@paykit-sdk/paypal 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { schema, validateRequiredKeys, AbstractPayKitProvider, ConstraintViolationError, ProviderNotSupportedError, NotImplementedError, ResourceNotFoundError, WebhookError, paykitEvent$InboundSchema, omitInternalMetadata } from '@paykit-sdk/core';
2
- import { Environment, Client, LogLevel, OrdersController, PaymentsController, OrderApplicationContextUserAction, CheckoutPaymentIntent, CustomError } from '@paypal/paypal-server-sdk';
3
- import { BaseController } from '@paypal/paypal-server-sdk/dist/types/controllers/baseController';
4
- import { object, string, lazy, number, stringEnum, boolean } from '@paypal/paypal-server-sdk/dist/types/schema';
1
+ import { schema, validateRequiredKeys, AbstractPayKitProvider, createCheckoutSchema, ValidationError, ConstraintViolationError, OperationFailedError, ResourceNotFoundError, ProviderNotSupportedError, NotImplementedError, WebhookError, paykitEvent$InboundSchema, omitInternalMetadata } from '@paykit-sdk/core';
2
+ import { Environment, Client, LogLevel, OrdersController, PaymentsController, OrderApplicationContextUserAction, CheckoutPaymentIntent, CustomError, OrderStatus } from '@paypal/paypal-server-sdk';
3
+ import { BaseController } from '@paypal/paypal-server-sdk/dist/cjs/controllers/baseController';
4
+ import { object, string, lazy, number, stringEnum, boolean } from '@paypal/paypal-server-sdk/dist/cjs/schema';
5
5
 
6
6
  var __defProp = Object.defineProperty;
7
7
  var __export = (target, all) => {
@@ -4038,14 +4038,14 @@ var ostring = () => stringType().optional();
4038
4038
  var onumber = () => numberType().optional();
4039
4039
  var oboolean = () => booleanType().optional();
4040
4040
  var coerce = {
4041
- string: (arg) => ZodString.create({ ...arg, coerce: true }),
4042
- number: (arg) => ZodNumber.create({ ...arg, coerce: true }),
4043
- boolean: (arg) => ZodBoolean.create({
4041
+ string: ((arg) => ZodString.create({ ...arg, coerce: true })),
4042
+ number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
4043
+ boolean: ((arg) => ZodBoolean.create({
4044
4044
  ...arg,
4045
4045
  coerce: true
4046
- }),
4047
- bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
4048
- date: (arg) => ZodDate.create({ ...arg, coerce: true })
4046
+ })),
4047
+ bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
4048
+ date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
4049
4049
  };
4050
4050
  var NEVER = INVALID;
4051
4051
  object({
@@ -4249,12 +4249,18 @@ var WebhookController = class extends BaseController {
4249
4249
  return req.callAsJson(verifyWebhookSchema);
4250
4250
  }
4251
4251
  };
4252
+ var paykitPayee$InboundSchema = (payee) => {
4253
+ let customer = { email: "" };
4254
+ if (typeof payee === "string") customer = payee;
4255
+ else if (payee?.emailAddress) customer = { email: payee?.emailAddress };
4256
+ return customer;
4257
+ };
4252
4258
  var paykitRefund$InboundSchema = (refund) => {
4253
4259
  return {
4254
4260
  id: refund.id,
4255
4261
  amount: refund.amount?.value ? parseFloat(refund.amount.value) : 0,
4256
4262
  currency: refund.amount?.currencyCode || "USD",
4257
- metadata: refund.customId ? omitInternalMetadata(JSON.parse(refund.customId)) : {},
4263
+ metadata: omitInternalMetadata(JSON.parse(refund.customId ?? "{}")),
4258
4264
  reason: refund.noteToPayer ?? null
4259
4265
  };
4260
4266
  };
@@ -4264,10 +4270,12 @@ var paykitCheckout$InboundSchema = (order) => {
4264
4270
  payment_url: order.links?.find((l) => l.rel === "approve")?.href || "",
4265
4271
  amount: parseFloat(order.purchaseUnits?.[0]?.amount?.value || "0"),
4266
4272
  currency: order.purchaseUnits?.[0]?.amount?.currencyCode || "USD",
4267
- customer: order.payer?.payerId ? order.payer?.payerId : { email: order.payer?.emailAddress ?? "" },
4273
+ customer: paykitPayee$InboundSchema(order.payer ?? {}),
4268
4274
  session_type: "one_time",
4269
4275
  products: [{ id: order.purchaseUnits?.[0]?.items?.[0]?.sku || "", quantity: 1 }],
4270
- metadata: order.purchaseUnits?.[0]?.customId ? omitInternalMetadata(JSON.parse(order.purchaseUnits?.[0]?.customId)) : {},
4276
+ metadata: omitInternalMetadata(
4277
+ JSON.parse(order.purchaseUnits?.[0]?.customId ?? "{}")
4278
+ ),
4271
4279
  subscription: null
4272
4280
  };
4273
4281
  };
@@ -4281,14 +4289,193 @@ var paykitPayment$InboundSchema = (order) => {
4281
4289
  PAYER_ACTION_REQUIRED: "requires_action"
4282
4290
  };
4283
4291
  const status = statusMap[order.status ?? statusMap.CREATED];
4292
+ const approveLink = order.links?.find((l) => l.rel === "approve")?.href ?? "";
4293
+ const requiresAction = [
4294
+ OrderStatus.PayerActionRequired,
4295
+ OrderStatus.Created,
4296
+ OrderStatus.Saved
4297
+ ].includes(order.status);
4284
4298
  return {
4285
4299
  id: order.id,
4286
4300
  status,
4301
+ customer: paykitPayee$InboundSchema(order.payer ?? {}),
4287
4302
  amount: parseFloat(order.purchaseUnits?.[0]?.amount?.value || "0"),
4288
4303
  currency: order.purchaseUnits?.[0]?.amount?.currencyCode || "USD",
4289
- metadata: order.purchaseUnits?.[0]?.customId ? omitInternalMetadata(JSON.parse(order.purchaseUnits?.[0]?.customId)) : {},
4290
- customer: order.payer?.payerId ? order.payer?.payerId : { email: order.payer?.emailAddress ?? "" },
4291
- item_id: order.purchaseUnits?.[0]?.items?.[0]?.sku || ""
4304
+ metadata: omitInternalMetadata(
4305
+ JSON.parse(order.purchaseUnits?.[0]?.customId ?? "{}")
4306
+ ),
4307
+ item_id: order.purchaseUnits?.[0]?.items?.[0]?.sku || "",
4308
+ requires_action: requiresAction,
4309
+ payment_url: approveLink
4310
+ };
4311
+ };
4312
+ var paykitPaymentWebhook$InboundSchema = (resource) => {
4313
+ const statusMap = {
4314
+ CREATED: "pending",
4315
+ SAVED: "pending",
4316
+ APPROVED: "requires_capture",
4317
+ VOIDED: "canceled",
4318
+ COMPLETED: "succeeded",
4319
+ PAYER_ACTION_REQUIRED: "requires_action"
4320
+ };
4321
+ const status = statusMap[resource.status ?? "CREATED"] ?? "pending";
4322
+ const payer = resource.payer;
4323
+ let customer = { email: "" };
4324
+ if (payer?.payer_id) {
4325
+ customer = payer.payer_id;
4326
+ } else if (payer?.email_address) {
4327
+ customer = { email: payer.email_address };
4328
+ }
4329
+ const purchaseUnits = resource.purchase_units ?? [];
4330
+ const firstUnit = purchaseUnits[0] ?? {};
4331
+ const amount = firstUnit.amount;
4332
+ const items = firstUnit.items ?? [];
4333
+ const metadata = (() => {
4334
+ try {
4335
+ const customId = firstUnit?.custom_id;
4336
+ return customId ? JSON.parse(customId) : {};
4337
+ } catch {
4338
+ return {};
4339
+ }
4340
+ })();
4341
+ const itemId = items[0]?.sku ?? firstUnit.reference_id ?? "";
4342
+ return {
4343
+ id: resource.id,
4344
+ status,
4345
+ customer,
4346
+ amount: parseFloat(amount?.value ?? "0"),
4347
+ currency: amount?.currency_code ?? "USD",
4348
+ metadata: omitInternalMetadata(metadata),
4349
+ item_id: itemId,
4350
+ requires_action: false,
4351
+ payment_url: null
4352
+ };
4353
+ };
4354
+ var paykitPaymentCaptureWebhook$InboundSchema = (capture) => {
4355
+ const statusMap = {
4356
+ COMPLETED: "succeeded",
4357
+ PENDING: "pending",
4358
+ REFUNDED: "succeeded",
4359
+ // Refunded but was successful
4360
+ PARTIALLY_REFUNDED: "succeeded"
4361
+ };
4362
+ const status = statusMap[capture.status ?? "PENDING"] ?? "pending";
4363
+ const supplementaryData = capture.supplementary_data;
4364
+ const relatedIds = supplementaryData?.related_ids;
4365
+ const orderId = relatedIds?.order_id ?? capture.id;
4366
+ const metadata = (() => {
4367
+ try {
4368
+ const customId = capture.custom_id;
4369
+ return customId ? JSON.parse(customId) : {};
4370
+ } catch {
4371
+ return {};
4372
+ }
4373
+ })();
4374
+ const amount = capture.amount;
4375
+ return {
4376
+ id: orderId,
4377
+ status,
4378
+ customer: { email: "" },
4379
+ // Not available in capture event
4380
+ amount: parseFloat(amount?.value ?? "0"),
4381
+ currency: amount?.currency_code ?? "USD",
4382
+ metadata: omitInternalMetadata(metadata),
4383
+ item_id: "",
4384
+ // Not available in capture event
4385
+ requires_action: false,
4386
+ payment_url: null
4387
+ };
4388
+ };
4389
+ var paykitRefundWebhook$InboundSchema = (refund) => {
4390
+ const amount = refund.amount;
4391
+ const refundAmount = amount?.total ? Math.abs(parseFloat(amount.total)) : 0;
4392
+ return {
4393
+ id: refund.id,
4394
+ amount: refundAmount,
4395
+ currency: amount?.currency ?? "USD",
4396
+ metadata: omitInternalMetadata({}),
4397
+ // No metadata in webhook refund
4398
+ reason: null
4399
+ // No reason in webhook refund
4400
+ };
4401
+ };
4402
+ var paykitSubscriptionWebhook$InboundSchema = (agreement) => {
4403
+ const state = agreement.state ?? "Pending";
4404
+ const statusMap = {
4405
+ Pending: "pending",
4406
+ Active: "active",
4407
+ Suspended: "past_due",
4408
+ Cancelled: "canceled",
4409
+ Expired: "canceled",
4410
+ Completed: "active"
4411
+ };
4412
+ const status = statusMap[state] ?? "pending";
4413
+ const plan = agreement.plan;
4414
+ const paymentDefinitions = plan?.payment_definitions ?? [];
4415
+ const regularDefinition = paymentDefinitions.find((def) => def.type === "REGULAR") ?? paymentDefinitions[0];
4416
+ const frequency = regularDefinition?.frequency ?? "Month";
4417
+ const billingIntervalMap = {
4418
+ Day: "day",
4419
+ Days: "day",
4420
+ Week: "week",
4421
+ Weeks: "week",
4422
+ Month: "month",
4423
+ Months: "month",
4424
+ Year: "year",
4425
+ Years: "year"
4426
+ };
4427
+ const billingInterval = billingIntervalMap[frequency] ?? "month";
4428
+ const startDate = agreement.start_date ?? (/* @__PURE__ */ new Date()).toISOString();
4429
+ const periodStart = new Date(startDate);
4430
+ const periodEnd = (() => {
4431
+ const end = new Date(periodStart);
4432
+ switch (billingInterval) {
4433
+ case "day":
4434
+ end.setDate(end.getDate() + 1);
4435
+ break;
4436
+ case "week":
4437
+ end.setDate(end.getDate() + 7);
4438
+ break;
4439
+ case "month":
4440
+ end.setMonth(end.getMonth() + 1);
4441
+ break;
4442
+ case "year":
4443
+ end.setFullYear(end.getFullYear() + 1);
4444
+ break;
4445
+ default:
4446
+ end.setMonth(end.getMonth() + 1);
4447
+ }
4448
+ return end;
4449
+ })();
4450
+ const payer = agreement.payer;
4451
+ const payerInfo = payer?.payer_info;
4452
+ const email = payerInfo?.email ?? "";
4453
+ const planId = plan?.id ?? agreement.id;
4454
+ const amount = regularDefinition?.amount;
4455
+ const subscriptionAmount = amount?.value ? parseFloat(amount.value) : 0;
4456
+ const currency = plan?.curr_code ?? "USD";
4457
+ const metadata = (() => {
4458
+ try {
4459
+ const description = agreement.description;
4460
+ return description ? JSON.parse(description) : {};
4461
+ } catch {
4462
+ return {};
4463
+ }
4464
+ })();
4465
+ return {
4466
+ id: agreement.id,
4467
+ customer: { email },
4468
+ status,
4469
+ item_id: planId,
4470
+ current_period_start: periodStart,
4471
+ current_period_end: periodEnd,
4472
+ metadata: omitInternalMetadata(metadata),
4473
+ billing_interval: billingInterval,
4474
+ amount: subscriptionAmount,
4475
+ currency,
4476
+ custom_fields: null,
4477
+ requires_action: false,
4478
+ payment_url: null
4292
4479
  };
4293
4480
  };
4294
4481
 
@@ -4337,7 +4524,10 @@ var PayPalProvider = class extends AbstractPayKitProvider {
4337
4524
  * In PayPal, Order IS the checkout
4338
4525
  */
4339
4526
  createCheckout = async (params) => {
4340
- const stringifiedMetadata = JSON.stringify(params.metadata);
4527
+ const { error, data } = createCheckoutSchema.safeParse(params);
4528
+ if (error)
4529
+ throw ValidationError.fromZodError(error, this.providerName, "createCheckout");
4530
+ const stringifiedMetadata = JSON.stringify(data.metadata);
4341
4531
  if (stringifiedMetadata.length > PAYPAL_METADATA_MAX_LENGTH) {
4342
4532
  throw new ConstraintViolationError("Metadata exceeds maximum length", {
4343
4533
  value: stringifiedMetadata.length,
@@ -4351,57 +4541,81 @@ var PayPalProvider = class extends AbstractPayKitProvider {
4351
4541
  itemName = "Untitled Item"
4352
4542
  } = validateRequiredKeys(
4353
4543
  ["currency", "amount", "itemName"],
4354
- params.provider_metadata,
4355
- "Missing required parameters: {keys}"
4544
+ data.provider_metadata,
4545
+ "Missing required parameters in provider_metadata: {keys}"
4356
4546
  );
4547
+ const totalAmount = parseFloat(amount);
4548
+ const quantity = data.quantity || 1;
4549
+ const unitAmount = (totalAmount / quantity).toFixed(2);
4357
4550
  const orderOptionsBody = {
4358
4551
  intent: CheckoutPaymentIntent.Capture,
4359
4552
  payer: {
4360
- ...typeof params.customer === "string" && { payerId: params.customer },
4361
- ...typeof params.customer === "object" && "email" in params.customer && { emailAddress: params.customer.email }
4553
+ ...typeof data.customer === "string" && { payerId: data.customer },
4554
+ ...typeof data.customer === "object" && "email" in data.customer && { emailAddress: data.customer.email }
4362
4555
  },
4363
4556
  purchaseUnits: [
4364
4557
  {
4365
- amount: { currencyCode: currency, value: amount },
4558
+ amount: {
4559
+ currencyCode: currency,
4560
+ value: amount,
4561
+ breakdown: { itemTotal: { currencyCode: currency, value: amount } }
4562
+ },
4366
4563
  customId: stringifiedMetadata,
4367
4564
  items: [
4368
4565
  {
4369
- sku: params.item_id,
4370
- quantity: params.quantity.toString(),
4566
+ sku: data.item_id,
4567
+ quantity: quantity.toString(),
4371
4568
  name: itemName,
4372
- unitAmount: { currencyCode: currency, value: amount }
4569
+ unitAmount: { currencyCode: currency, value: unitAmount }
4373
4570
  }
4374
4571
  ]
4375
4572
  }
4376
4573
  ],
4377
- applicationContext: { userAction: OrderApplicationContextUserAction.PayNow },
4378
- ...params.provider_metadata && { ...params.provider_metadata }
4574
+ applicationContext: {
4575
+ userAction: OrderApplicationContextUserAction.PayNow,
4576
+ returnUrl: data.success_url,
4577
+ cancelUrl: data.cancel_url
4578
+ },
4579
+ ...data.provider_metadata && { ...data.provider_metadata }
4379
4580
  };
4380
- if (params.billing) {
4581
+ if (data.billing) {
4381
4582
  orderOptionsBody.purchaseUnits[0].shipping = {
4382
- name: { fullName: params.billing.address.name },
4583
+ name: { fullName: data.billing.address.name },
4383
4584
  address: {
4384
- addressLine1: params.billing.address.line1,
4385
- addressLine2: params.billing.address.line2,
4386
- adminArea1: params.billing.address.city,
4387
- adminArea2: params.billing.address.state,
4388
- postalCode: params.billing.address.postal_code,
4389
- countryCode: params.billing.address.country
4585
+ addressLine1: data.billing.address.line1,
4586
+ addressLine2: data.billing.address.line2,
4587
+ adminArea1: data.billing.address.city,
4588
+ adminArea2: data.billing.address.state,
4589
+ postalCode: data.billing.address.postal_code,
4590
+ countryCode: data.billing.address.country
4390
4591
  },
4391
- ...params.billing.address.phone && {
4592
+ ...data.billing.address.phone && {
4392
4593
  phoneNumber: {
4393
- nationalNumber: params.billing.address.phone,
4394
- countryCode: params.billing.address.country
4594
+ nationalNumber: data.billing.address.phone,
4595
+ countryCode: data.billing.address.country
4395
4596
  }
4396
4597
  }
4397
4598
  };
4398
4599
  }
4399
- const order = await this.ordersController.createOrder({ body: orderOptionsBody });
4400
- return paykitCheckout$InboundSchema(order.result);
4600
+ try {
4601
+ const order = await this.ordersController.createOrder({ body: orderOptionsBody });
4602
+ return paykitCheckout$InboundSchema(order.result);
4603
+ } catch (error2) {
4604
+ throw new OperationFailedError("createCheckout", this.providerName, {
4605
+ cause: error2 instanceof Error ? error2 : new Error("Unknown error")
4606
+ });
4607
+ }
4401
4608
  };
4402
4609
  retrieveCheckout = async (id) => {
4403
- const order = await this.ordersController.getOrder({ id });
4404
- return paykitCheckout$InboundSchema(order.result);
4610
+ try {
4611
+ const order = await this.ordersController.getOrder({ id });
4612
+ if (!order.result) throw new ResourceNotFoundError("Order", id);
4613
+ return paykitCheckout$InboundSchema(order.result);
4614
+ } catch (error) {
4615
+ throw new OperationFailedError("retrieveCheckout", this.providerName, {
4616
+ cause: error instanceof Error ? error : new Error("Unknown error")
4617
+ });
4618
+ }
4405
4619
  };
4406
4620
  updateCheckout = async (id, params) => {
4407
4621
  throw new ProviderNotSupportedError("updateCheckout", this.providerName, {
@@ -4522,8 +4736,14 @@ var PayPalProvider = class extends AbstractPayKitProvider {
4522
4736
  }
4523
4737
  };
4524
4738
  }
4525
- const order = await this.ordersController.createOrder({ body: orderOptionsBody });
4526
- return paykitPayment$InboundSchema(order.result);
4739
+ try {
4740
+ const order = await this.ordersController.createOrder({ body: orderOptionsBody });
4741
+ return paykitPayment$InboundSchema(order.result);
4742
+ } catch (error) {
4743
+ throw new OperationFailedError("createPayment", this.providerName, {
4744
+ cause: error instanceof Error ? error : new Error("Unknown error")
4745
+ });
4746
+ }
4527
4747
  };
4528
4748
  updatePayment = async (id, params) => {
4529
4749
  throw new ProviderNotSupportedError("updatePayment", this.providerName, {
@@ -4531,8 +4751,15 @@ var PayPalProvider = class extends AbstractPayKitProvider {
4531
4751
  });
4532
4752
  };
4533
4753
  retrievePayment = async (id) => {
4534
- const order = await this.ordersController.getOrder({ id });
4535
- return paykitPayment$InboundSchema(order.result);
4754
+ try {
4755
+ const order = await this.ordersController.getOrder({ id });
4756
+ if (!order.result) throw new ResourceNotFoundError("Order", id);
4757
+ return paykitPayment$InboundSchema(order.result);
4758
+ } catch (error) {
4759
+ throw new OperationFailedError("retrievePayment", this.providerName, {
4760
+ cause: error instanceof Error ? error : new Error("Unknown error")
4761
+ });
4762
+ }
4536
4763
  };
4537
4764
  deletePayment = async (id) => {
4538
4765
  throw new ProviderNotSupportedError("deletePayment", this.providerName, {
@@ -4540,8 +4767,15 @@ var PayPalProvider = class extends AbstractPayKitProvider {
4540
4767
  });
4541
4768
  };
4542
4769
  capturePayment = async (id) => {
4543
- const captured = await this.ordersController.captureOrder({ id });
4544
- return paykitPayment$InboundSchema(captured.result);
4770
+ try {
4771
+ const captured = await this.ordersController.captureOrder({ id });
4772
+ if (!captured.result) throw new ResourceNotFoundError("Order", id);
4773
+ return paykitPayment$InboundSchema(captured.result);
4774
+ } catch (error) {
4775
+ throw new OperationFailedError("capturePayment", this.providerName, {
4776
+ cause: error instanceof Error ? error : new Error("Unknown error")
4777
+ });
4778
+ }
4545
4779
  };
4546
4780
  cancelPayment = async (id) => {
4547
4781
  throw new ProviderNotSupportedError("cancelPayment", this.providerName, {
@@ -4552,18 +4786,26 @@ var PayPalProvider = class extends AbstractPayKitProvider {
4552
4786
  * Refund management
4553
4787
  */
4554
4788
  createRefund = async (params) => {
4555
- const order = await this.ordersController.getOrder({ id: params.payment_id });
4556
- const captureIds = order.result.purchaseUnits?.[0]?.payments?.captures?.map((c) => c.id) || [];
4557
- if (captureIds.length === 0) {
4558
- throw new ResourceNotFoundError("Capture", params.payment_id, this.providerName);
4559
- }
4560
- const currencyCode = order.result.purchaseUnits?.[0]?.amount?.currencyCode || "USD";
4561
- const amount = params.amount ? params.amount.toString() : order.result.purchaseUnits?.[0]?.amount?.value || "0";
4562
- const refund = await this.paymentsController.refundCapturedPayment({
4563
- captureId: captureIds[0],
4564
- body: { amount: { currencyCode, value: amount } }
4565
- });
4566
- return paykitRefund$InboundSchema(refund.result);
4789
+ try {
4790
+ const order = await this.ordersController.getOrder({ id: params.payment_id });
4791
+ if (!order.result) throw new ResourceNotFoundError("Order", params.payment_id);
4792
+ const captureIds = order.result.purchaseUnits?.[0]?.payments?.captures?.map((c) => c.id) || [];
4793
+ if (captureIds.length === 0) {
4794
+ throw new ResourceNotFoundError("Capture", params.payment_id, this.providerName);
4795
+ }
4796
+ const currencyCode = order.result.purchaseUnits?.[0]?.amount?.currencyCode || "USD";
4797
+ const amount = params.amount ? params.amount.toString() : order.result.purchaseUnits?.[0]?.amount?.value || "0";
4798
+ const refund = await this.paymentsController.refundCapturedPayment({
4799
+ captureId: captureIds[0],
4800
+ body: { amount: { currencyCode, value: amount } }
4801
+ });
4802
+ if (!refund.result) throw new ResourceNotFoundError("Refund", params.payment_id);
4803
+ return paykitRefund$InboundSchema(refund.result);
4804
+ } catch (error) {
4805
+ throw new OperationFailedError("createRefund", this.providerName, {
4806
+ cause: error instanceof Error ? error : new Error("Unknown error")
4807
+ });
4808
+ }
4567
4809
  };
4568
4810
  /**
4569
4811
  * Webhook management
@@ -4588,8 +4830,9 @@ var PayPalProvider = class extends AbstractPayKitProvider {
4588
4830
  const eventType = event.event_type;
4589
4831
  const webhookHandlers = {
4590
4832
  "CHECKOUT.ORDER.APPROVED": async () => {
4591
- const orderData = event.resource;
4592
- const payment = paykitPayment$InboundSchema(orderData);
4833
+ const payment = paykitPaymentWebhook$InboundSchema(
4834
+ event.resource
4835
+ );
4593
4836
  return [
4594
4837
  paykitEvent$InboundSchema({
4595
4838
  type: "payment.created",
@@ -4600,8 +4843,9 @@ var PayPalProvider = class extends AbstractPayKitProvider {
4600
4843
  ];
4601
4844
  },
4602
4845
  "CHECKOUT.ORDER.COMPLETED": async () => {
4603
- const orderData = event.resource;
4604
- const payment = paykitPayment$InboundSchema(orderData);
4846
+ const payment = paykitPaymentWebhook$InboundSchema(
4847
+ event.resource
4848
+ );
4605
4849
  return [
4606
4850
  paykitEvent$InboundSchema({
4607
4851
  type: "payment.updated",
@@ -4612,8 +4856,9 @@ var PayPalProvider = class extends AbstractPayKitProvider {
4612
4856
  ];
4613
4857
  },
4614
4858
  "PAYMENT.CAPTURE.COMPLETED": async () => {
4615
- const orderData = event.resource;
4616
- const payment = paykitPayment$InboundSchema(orderData);
4859
+ const payment = paykitPaymentCaptureWebhook$InboundSchema(
4860
+ event.resource
4861
+ );
4617
4862
  return [
4618
4863
  paykitEvent$InboundSchema({
4619
4864
  type: "payment.updated",
@@ -4624,8 +4869,9 @@ var PayPalProvider = class extends AbstractPayKitProvider {
4624
4869
  ];
4625
4870
  },
4626
4871
  "PAYMENT.CAPTURE.REFUNDED": async () => {
4627
- const refundData = event.resource;
4628
- const refund = paykitRefund$InboundSchema(refundData);
4872
+ const refund = paykitRefundWebhook$InboundSchema(
4873
+ event.resource
4874
+ );
4629
4875
  return [
4630
4876
  paykitEvent$InboundSchema({
4631
4877
  type: "refund.created",
@@ -4634,6 +4880,71 @@ var PayPalProvider = class extends AbstractPayKitProvider {
4634
4880
  data: refund
4635
4881
  })
4636
4882
  ];
4883
+ },
4884
+ "BILLING.SUBSCRIPTION.CREATED": async () => {
4885
+ const subscription = paykitSubscriptionWebhook$InboundSchema(
4886
+ event.resource
4887
+ );
4888
+ return [
4889
+ paykitEvent$InboundSchema({
4890
+ type: "subscription.created",
4891
+ created: Date.now() / 1e3,
4892
+ id: event.id,
4893
+ data: subscription
4894
+ })
4895
+ ];
4896
+ },
4897
+ "BILLING.SUBSCRIPTION.UPDATED": async () => {
4898
+ const subscription = paykitSubscriptionWebhook$InboundSchema(
4899
+ event.resource
4900
+ );
4901
+ return [
4902
+ paykitEvent$InboundSchema({
4903
+ type: "subscription.updated",
4904
+ created: Date.now() / 1e3,
4905
+ id: event.id,
4906
+ data: subscription
4907
+ })
4908
+ ];
4909
+ },
4910
+ "BILLING.SUBSCRIPTION.SUSPENDED": async () => {
4911
+ const subscription = paykitSubscriptionWebhook$InboundSchema(
4912
+ event.resource
4913
+ );
4914
+ return [
4915
+ paykitEvent$InboundSchema({
4916
+ type: "subscription.updated",
4917
+ created: Date.now() / 1e3,
4918
+ id: event.id,
4919
+ data: subscription
4920
+ })
4921
+ ];
4922
+ },
4923
+ "BILLING.SUBSCRIPTION.CANCELLED": async () => {
4924
+ const subscription = paykitSubscriptionWebhook$InboundSchema(
4925
+ event.resource
4926
+ );
4927
+ return [
4928
+ paykitEvent$InboundSchema({
4929
+ type: "subscription.canceled",
4930
+ created: Date.now() / 1e3,
4931
+ id: event.id,
4932
+ data: subscription
4933
+ })
4934
+ ];
4935
+ },
4936
+ "BILLING.SUBSCRIPTION.EXPIRED": async () => {
4937
+ const subscription = paykitSubscriptionWebhook$InboundSchema(
4938
+ event.resource
4939
+ );
4940
+ return [
4941
+ paykitEvent$InboundSchema({
4942
+ type: "subscription.canceled",
4943
+ created: Date.now() / 1e3,
4944
+ id: event.id,
4945
+ data: subscription
4946
+ })
4947
+ ];
4637
4948
  }
4638
4949
  };
4639
4950
  const handler = webhookHandlers[eventType];