@paykit-sdk/paypal 1.3.0 → 1.3.1

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.js CHANGED
@@ -536,10 +536,26 @@ var PayPalProvider = class extends core.AbstractPayKitProvider {
536
536
  this.webhookController = new WebhookController(this.client);
537
537
  this.isSandbox = isSandbox;
538
538
  }
539
- /**
540
- * Checkout management
541
- * In PayPal, Order IS the checkout
542
- */
539
+ buildPayer(customer) {
540
+ return {
541
+ ...core.isIdCustomer(customer) && {
542
+ payerId: String(customer.id)
543
+ },
544
+ ...core.isEmailCustomer(customer) && {
545
+ emailAddress: customer.email
546
+ }
547
+ };
548
+ }
549
+ async submitOrder(body, method) {
550
+ try {
551
+ const order = await this.ordersController.createOrder({ body });
552
+ return order.result;
553
+ } catch (error) {
554
+ throw new core.OperationFailedError(method, this.providerName, {
555
+ cause: error instanceof Error ? error : new Error("Unknown error")
556
+ });
557
+ }
558
+ }
543
559
  createCheckout = async (params) => {
544
560
  const { error, data } = core.createCheckoutSchema.safeParse(params);
545
561
  if (error)
@@ -573,14 +589,7 @@ var PayPalProvider = class extends core.AbstractPayKitProvider {
573
589
  const unitAmount = (totalAmount / quantity).toFixed(2);
574
590
  const orderOptionsBody = {
575
591
  intent: paypalServerSdk.CheckoutPaymentIntent.Capture,
576
- payer: {
577
- ...typeof data.customer === "string" && {
578
- payerId: data.customer
579
- },
580
- ...typeof data.customer === "object" && "email" in data.customer && {
581
- emailAddress: data.customer.email
582
- }
583
- },
592
+ payer: this.buildPayer(data.customer),
584
593
  purchaseUnits: [
585
594
  {
586
595
  amount: {
@@ -630,20 +639,11 @@ var PayPalProvider = class extends core.AbstractPayKitProvider {
630
639
  }
631
640
  };
632
641
  }
633
- try {
634
- const order = await this.ordersController.createOrder({
635
- body: orderOptionsBody
636
- });
637
- return Checkout$inboundSchema(order.result);
638
- } catch (error2) {
639
- throw new core.OperationFailedError(
640
- "createCheckout",
641
- this.providerName,
642
- {
643
- cause: error2 instanceof Error ? error2 : new Error("Unknown error")
644
- }
645
- );
646
- }
642
+ const result = await this.submitOrder(
643
+ orderOptionsBody,
644
+ "createCheckout"
645
+ );
646
+ return Checkout$inboundSchema(result);
647
647
  };
648
648
  retrieveCheckout = async (id) => {
649
649
  try {
@@ -762,7 +762,7 @@ var PayPalProvider = class extends core.AbstractPayKitProvider {
762
762
  * In PayPal, Order IS the payment
763
763
  */
764
764
  createPayment = async (params) => {
765
- const stringifiedMetadata = JSON.stringify(params.metadata);
765
+ const stringifiedMetadata = JSON.stringify(params.metadata ?? {});
766
766
  if (stringifiedMetadata.length > PAYPAL_METADATA_MAX_LENGTH) {
767
767
  throw new core.ConstraintViolationError(
768
768
  "Metadata exceeds maximum length",
@@ -775,14 +775,7 @@ var PayPalProvider = class extends core.AbstractPayKitProvider {
775
775
  }
776
776
  const orderOptionsBody = {
777
777
  intent: paypalServerSdk.CheckoutPaymentIntent.Capture,
778
- payer: {
779
- ...core.isIdCustomer(params.customer) && {
780
- payerId: String(params.customer.id)
781
- },
782
- ...core.isEmailCustomer(params.customer) && {
783
- emailAddress: params.customer.email
784
- }
785
- },
778
+ payer: this.buildPayer(params.customer),
786
779
  purchaseUnits: [
787
780
  {
788
781
  amount: {
@@ -812,20 +805,11 @@ var PayPalProvider = class extends core.AbstractPayKitProvider {
812
805
  }
813
806
  };
814
807
  }
815
- try {
816
- const order = await this.ordersController.createOrder({
817
- body: orderOptionsBody
818
- });
819
- return Payment$inboundSchema(order.result);
820
- } catch (error) {
821
- throw new core.OperationFailedError(
822
- "createPayment",
823
- this.providerName,
824
- {
825
- cause: error instanceof Error ? error : new Error("Unknown error")
826
- }
827
- );
828
- }
808
+ const result = await this.submitOrder(
809
+ orderOptionsBody,
810
+ "createPayment"
811
+ );
812
+ return Payment$inboundSchema(result);
829
813
  };
830
814
  updatePayment = async (id, params) => {
831
815
  throw new core.ProviderNotSupportedError(
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { schema, Schema, validateRequiredKeys, AbstractPayKitProvider, createCheckoutSchema, ValidationError, ConstraintViolationError, OperationFailedError, ResourceNotFoundError, ProviderNotSupportedError, NotImplementedError, isEmailCustomer, isIdCustomer, WebhookError, paykitEvent$InboundSchema, omitInternalMetadata } from '@paykit-sdk/core';
1
+ import { schema, Schema, validateRequiredKeys, AbstractPayKitProvider, isEmailCustomer, isIdCustomer, OperationFailedError, createCheckoutSchema, ValidationError, ConstraintViolationError, ResourceNotFoundError, ProviderNotSupportedError, NotImplementedError, WebhookError, paykitEvent$InboundSchema, omitInternalMetadata } from '@paykit-sdk/core';
2
2
  import { Environment, Client, LogLevel, OrdersController, PaymentsController, OrderApplicationContextUserAction, CheckoutPaymentIntent, CustomError, OrderStatus } from '@paypal/paypal-server-sdk';
3
3
  import { BaseController } from '@paypal/paypal-server-sdk/dist/cjs/controllers/baseController';
4
4
  import { object, string, lazy, number, stringEnum, boolean } from '@paypal/paypal-server-sdk/dist/cjs/schema';
@@ -534,10 +534,26 @@ var PayPalProvider = class extends AbstractPayKitProvider {
534
534
  this.webhookController = new WebhookController(this.client);
535
535
  this.isSandbox = isSandbox;
536
536
  }
537
- /**
538
- * Checkout management
539
- * In PayPal, Order IS the checkout
540
- */
537
+ buildPayer(customer) {
538
+ return {
539
+ ...isIdCustomer(customer) && {
540
+ payerId: String(customer.id)
541
+ },
542
+ ...isEmailCustomer(customer) && {
543
+ emailAddress: customer.email
544
+ }
545
+ };
546
+ }
547
+ async submitOrder(body, method) {
548
+ try {
549
+ const order = await this.ordersController.createOrder({ body });
550
+ return order.result;
551
+ } catch (error) {
552
+ throw new OperationFailedError(method, this.providerName, {
553
+ cause: error instanceof Error ? error : new Error("Unknown error")
554
+ });
555
+ }
556
+ }
541
557
  createCheckout = async (params) => {
542
558
  const { error, data } = createCheckoutSchema.safeParse(params);
543
559
  if (error)
@@ -571,14 +587,7 @@ var PayPalProvider = class extends AbstractPayKitProvider {
571
587
  const unitAmount = (totalAmount / quantity).toFixed(2);
572
588
  const orderOptionsBody = {
573
589
  intent: CheckoutPaymentIntent.Capture,
574
- payer: {
575
- ...typeof data.customer === "string" && {
576
- payerId: data.customer
577
- },
578
- ...typeof data.customer === "object" && "email" in data.customer && {
579
- emailAddress: data.customer.email
580
- }
581
- },
590
+ payer: this.buildPayer(data.customer),
582
591
  purchaseUnits: [
583
592
  {
584
593
  amount: {
@@ -628,20 +637,11 @@ var PayPalProvider = class extends AbstractPayKitProvider {
628
637
  }
629
638
  };
630
639
  }
631
- try {
632
- const order = await this.ordersController.createOrder({
633
- body: orderOptionsBody
634
- });
635
- return Checkout$inboundSchema(order.result);
636
- } catch (error2) {
637
- throw new OperationFailedError(
638
- "createCheckout",
639
- this.providerName,
640
- {
641
- cause: error2 instanceof Error ? error2 : new Error("Unknown error")
642
- }
643
- );
644
- }
640
+ const result = await this.submitOrder(
641
+ orderOptionsBody,
642
+ "createCheckout"
643
+ );
644
+ return Checkout$inboundSchema(result);
645
645
  };
646
646
  retrieveCheckout = async (id) => {
647
647
  try {
@@ -760,7 +760,7 @@ var PayPalProvider = class extends AbstractPayKitProvider {
760
760
  * In PayPal, Order IS the payment
761
761
  */
762
762
  createPayment = async (params) => {
763
- const stringifiedMetadata = JSON.stringify(params.metadata);
763
+ const stringifiedMetadata = JSON.stringify(params.metadata ?? {});
764
764
  if (stringifiedMetadata.length > PAYPAL_METADATA_MAX_LENGTH) {
765
765
  throw new ConstraintViolationError(
766
766
  "Metadata exceeds maximum length",
@@ -773,14 +773,7 @@ var PayPalProvider = class extends AbstractPayKitProvider {
773
773
  }
774
774
  const orderOptionsBody = {
775
775
  intent: CheckoutPaymentIntent.Capture,
776
- payer: {
777
- ...isIdCustomer(params.customer) && {
778
- payerId: String(params.customer.id)
779
- },
780
- ...isEmailCustomer(params.customer) && {
781
- emailAddress: params.customer.email
782
- }
783
- },
776
+ payer: this.buildPayer(params.customer),
784
777
  purchaseUnits: [
785
778
  {
786
779
  amount: {
@@ -810,20 +803,11 @@ var PayPalProvider = class extends AbstractPayKitProvider {
810
803
  }
811
804
  };
812
805
  }
813
- try {
814
- const order = await this.ordersController.createOrder({
815
- body: orderOptionsBody
816
- });
817
- return Payment$inboundSchema(order.result);
818
- } catch (error) {
819
- throw new OperationFailedError(
820
- "createPayment",
821
- this.providerName,
822
- {
823
- cause: error instanceof Error ? error : new Error("Unknown error")
824
- }
825
- );
826
- }
806
+ const result = await this.submitOrder(
807
+ orderOptionsBody,
808
+ "createPayment"
809
+ );
810
+ return Payment$inboundSchema(result);
827
811
  };
828
812
  updatePayment = async (id, params) => {
829
813
  throw new ProviderNotSupportedError(
@@ -24,10 +24,8 @@ declare class PayPalProvider extends AbstractPayKitProvider implements PayKitPro
24
24
  private subscriptionsController;
25
25
  private webhookController;
26
26
  constructor(config: PayPalOptions);
27
- /**
28
- * Checkout management
29
- * In PayPal, Order IS the checkout
30
- */
27
+ private buildPayer;
28
+ private submitOrder;
31
29
  createCheckout: (params: CreateCheckoutSchema) => Promise<Checkout>;
32
30
  retrieveCheckout: (id: string) => Promise<Checkout>;
33
31
  updateCheckout: (id: string, params: UpdateCheckoutSchema) => Promise<Checkout>;
@@ -24,10 +24,8 @@ declare class PayPalProvider extends AbstractPayKitProvider implements PayKitPro
24
24
  private subscriptionsController;
25
25
  private webhookController;
26
26
  constructor(config: PayPalOptions);
27
- /**
28
- * Checkout management
29
- * In PayPal, Order IS the checkout
30
- */
27
+ private buildPayer;
28
+ private submitOrder;
31
29
  createCheckout: (params: CreateCheckoutSchema) => Promise<Checkout>;
32
30
  retrieveCheckout: (id: string) => Promise<Checkout>;
33
31
  updateCheckout: (id: string, params: UpdateCheckoutSchema) => Promise<Checkout>;
@@ -536,10 +536,26 @@ var PayPalProvider = class extends core.AbstractPayKitProvider {
536
536
  this.webhookController = new WebhookController(this.client);
537
537
  this.isSandbox = isSandbox;
538
538
  }
539
- /**
540
- * Checkout management
541
- * In PayPal, Order IS the checkout
542
- */
539
+ buildPayer(customer) {
540
+ return {
541
+ ...core.isIdCustomer(customer) && {
542
+ payerId: String(customer.id)
543
+ },
544
+ ...core.isEmailCustomer(customer) && {
545
+ emailAddress: customer.email
546
+ }
547
+ };
548
+ }
549
+ async submitOrder(body, method) {
550
+ try {
551
+ const order = await this.ordersController.createOrder({ body });
552
+ return order.result;
553
+ } catch (error) {
554
+ throw new core.OperationFailedError(method, this.providerName, {
555
+ cause: error instanceof Error ? error : new Error("Unknown error")
556
+ });
557
+ }
558
+ }
543
559
  createCheckout = async (params) => {
544
560
  const { error, data } = core.createCheckoutSchema.safeParse(params);
545
561
  if (error)
@@ -573,14 +589,7 @@ var PayPalProvider = class extends core.AbstractPayKitProvider {
573
589
  const unitAmount = (totalAmount / quantity).toFixed(2);
574
590
  const orderOptionsBody = {
575
591
  intent: paypalServerSdk.CheckoutPaymentIntent.Capture,
576
- payer: {
577
- ...typeof data.customer === "string" && {
578
- payerId: data.customer
579
- },
580
- ...typeof data.customer === "object" && "email" in data.customer && {
581
- emailAddress: data.customer.email
582
- }
583
- },
592
+ payer: this.buildPayer(data.customer),
584
593
  purchaseUnits: [
585
594
  {
586
595
  amount: {
@@ -630,20 +639,11 @@ var PayPalProvider = class extends core.AbstractPayKitProvider {
630
639
  }
631
640
  };
632
641
  }
633
- try {
634
- const order = await this.ordersController.createOrder({
635
- body: orderOptionsBody
636
- });
637
- return Checkout$inboundSchema(order.result);
638
- } catch (error2) {
639
- throw new core.OperationFailedError(
640
- "createCheckout",
641
- this.providerName,
642
- {
643
- cause: error2 instanceof Error ? error2 : new Error("Unknown error")
644
- }
645
- );
646
- }
642
+ const result = await this.submitOrder(
643
+ orderOptionsBody,
644
+ "createCheckout"
645
+ );
646
+ return Checkout$inboundSchema(result);
647
647
  };
648
648
  retrieveCheckout = async (id) => {
649
649
  try {
@@ -762,7 +762,7 @@ var PayPalProvider = class extends core.AbstractPayKitProvider {
762
762
  * In PayPal, Order IS the payment
763
763
  */
764
764
  createPayment = async (params) => {
765
- const stringifiedMetadata = JSON.stringify(params.metadata);
765
+ const stringifiedMetadata = JSON.stringify(params.metadata ?? {});
766
766
  if (stringifiedMetadata.length > PAYPAL_METADATA_MAX_LENGTH) {
767
767
  throw new core.ConstraintViolationError(
768
768
  "Metadata exceeds maximum length",
@@ -775,14 +775,7 @@ var PayPalProvider = class extends core.AbstractPayKitProvider {
775
775
  }
776
776
  const orderOptionsBody = {
777
777
  intent: paypalServerSdk.CheckoutPaymentIntent.Capture,
778
- payer: {
779
- ...core.isIdCustomer(params.customer) && {
780
- payerId: String(params.customer.id)
781
- },
782
- ...core.isEmailCustomer(params.customer) && {
783
- emailAddress: params.customer.email
784
- }
785
- },
778
+ payer: this.buildPayer(params.customer),
786
779
  purchaseUnits: [
787
780
  {
788
781
  amount: {
@@ -812,20 +805,11 @@ var PayPalProvider = class extends core.AbstractPayKitProvider {
812
805
  }
813
806
  };
814
807
  }
815
- try {
816
- const order = await this.ordersController.createOrder({
817
- body: orderOptionsBody
818
- });
819
- return Payment$inboundSchema(order.result);
820
- } catch (error) {
821
- throw new core.OperationFailedError(
822
- "createPayment",
823
- this.providerName,
824
- {
825
- cause: error instanceof Error ? error : new Error("Unknown error")
826
- }
827
- );
828
- }
808
+ const result = await this.submitOrder(
809
+ orderOptionsBody,
810
+ "createPayment"
811
+ );
812
+ return Payment$inboundSchema(result);
829
813
  };
830
814
  updatePayment = async (id, params) => {
831
815
  throw new core.ProviderNotSupportedError(
@@ -1,4 +1,4 @@
1
- import { schema, Schema, AbstractPayKitProvider, createCheckoutSchema, ValidationError, ConstraintViolationError, validateRequiredKeys, OperationFailedError, ResourceNotFoundError, ProviderNotSupportedError, NotImplementedError, isEmailCustomer, isIdCustomer, WebhookError, paykitEvent$InboundSchema, omitInternalMetadata } from '@paykit-sdk/core';
1
+ import { schema, Schema, AbstractPayKitProvider, isEmailCustomer, isIdCustomer, OperationFailedError, createCheckoutSchema, ValidationError, ConstraintViolationError, validateRequiredKeys, ResourceNotFoundError, ProviderNotSupportedError, NotImplementedError, WebhookError, paykitEvent$InboundSchema, omitInternalMetadata } from '@paykit-sdk/core';
2
2
  import { Environment, Client, LogLevel, OrdersController, PaymentsController, OrderApplicationContextUserAction, CheckoutPaymentIntent, CustomError, OrderStatus } from '@paypal/paypal-server-sdk';
3
3
  import { BaseController } from '@paypal/paypal-server-sdk/dist/cjs/controllers/baseController';
4
4
  import { object, string, lazy, number, stringEnum, boolean } from '@paypal/paypal-server-sdk/dist/cjs/schema';
@@ -534,10 +534,26 @@ var PayPalProvider = class extends AbstractPayKitProvider {
534
534
  this.webhookController = new WebhookController(this.client);
535
535
  this.isSandbox = isSandbox;
536
536
  }
537
- /**
538
- * Checkout management
539
- * In PayPal, Order IS the checkout
540
- */
537
+ buildPayer(customer) {
538
+ return {
539
+ ...isIdCustomer(customer) && {
540
+ payerId: String(customer.id)
541
+ },
542
+ ...isEmailCustomer(customer) && {
543
+ emailAddress: customer.email
544
+ }
545
+ };
546
+ }
547
+ async submitOrder(body, method) {
548
+ try {
549
+ const order = await this.ordersController.createOrder({ body });
550
+ return order.result;
551
+ } catch (error) {
552
+ throw new OperationFailedError(method, this.providerName, {
553
+ cause: error instanceof Error ? error : new Error("Unknown error")
554
+ });
555
+ }
556
+ }
541
557
  createCheckout = async (params) => {
542
558
  const { error, data } = createCheckoutSchema.safeParse(params);
543
559
  if (error)
@@ -571,14 +587,7 @@ var PayPalProvider = class extends AbstractPayKitProvider {
571
587
  const unitAmount = (totalAmount / quantity).toFixed(2);
572
588
  const orderOptionsBody = {
573
589
  intent: CheckoutPaymentIntent.Capture,
574
- payer: {
575
- ...typeof data.customer === "string" && {
576
- payerId: data.customer
577
- },
578
- ...typeof data.customer === "object" && "email" in data.customer && {
579
- emailAddress: data.customer.email
580
- }
581
- },
590
+ payer: this.buildPayer(data.customer),
582
591
  purchaseUnits: [
583
592
  {
584
593
  amount: {
@@ -628,20 +637,11 @@ var PayPalProvider = class extends AbstractPayKitProvider {
628
637
  }
629
638
  };
630
639
  }
631
- try {
632
- const order = await this.ordersController.createOrder({
633
- body: orderOptionsBody
634
- });
635
- return Checkout$inboundSchema(order.result);
636
- } catch (error2) {
637
- throw new OperationFailedError(
638
- "createCheckout",
639
- this.providerName,
640
- {
641
- cause: error2 instanceof Error ? error2 : new Error("Unknown error")
642
- }
643
- );
644
- }
640
+ const result = await this.submitOrder(
641
+ orderOptionsBody,
642
+ "createCheckout"
643
+ );
644
+ return Checkout$inboundSchema(result);
645
645
  };
646
646
  retrieveCheckout = async (id) => {
647
647
  try {
@@ -760,7 +760,7 @@ var PayPalProvider = class extends AbstractPayKitProvider {
760
760
  * In PayPal, Order IS the payment
761
761
  */
762
762
  createPayment = async (params) => {
763
- const stringifiedMetadata = JSON.stringify(params.metadata);
763
+ const stringifiedMetadata = JSON.stringify(params.metadata ?? {});
764
764
  if (stringifiedMetadata.length > PAYPAL_METADATA_MAX_LENGTH) {
765
765
  throw new ConstraintViolationError(
766
766
  "Metadata exceeds maximum length",
@@ -773,14 +773,7 @@ var PayPalProvider = class extends AbstractPayKitProvider {
773
773
  }
774
774
  const orderOptionsBody = {
775
775
  intent: CheckoutPaymentIntent.Capture,
776
- payer: {
777
- ...isIdCustomer(params.customer) && {
778
- payerId: String(params.customer.id)
779
- },
780
- ...isEmailCustomer(params.customer) && {
781
- emailAddress: params.customer.email
782
- }
783
- },
776
+ payer: this.buildPayer(params.customer),
784
777
  purchaseUnits: [
785
778
  {
786
779
  amount: {
@@ -810,20 +803,11 @@ var PayPalProvider = class extends AbstractPayKitProvider {
810
803
  }
811
804
  };
812
805
  }
813
- try {
814
- const order = await this.ordersController.createOrder({
815
- body: orderOptionsBody
816
- });
817
- return Payment$inboundSchema(order.result);
818
- } catch (error) {
819
- throw new OperationFailedError(
820
- "createPayment",
821
- this.providerName,
822
- {
823
- cause: error instanceof Error ? error : new Error("Unknown error")
824
- }
825
- );
826
- }
806
+ const result = await this.submitOrder(
807
+ orderOptionsBody,
808
+ "createPayment"
809
+ );
810
+ return Payment$inboundSchema(result);
827
811
  };
828
812
  updatePayment = async (id, params) => {
829
813
  throw new ProviderNotSupportedError(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paykit-sdk/paypal",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "PayPal provider for PayKit",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -23,7 +23,7 @@
23
23
  "tsup": "^8.5.0",
24
24
  "typescript": "^5.9.2",
25
25
  "esbuild": "^0.25.11",
26
- "@paykit-sdk/core": "1.3.0"
26
+ "@paykit-sdk/core": "1.3.1"
27
27
  },
28
28
  "dependencies": {
29
29
  "@paypal/paypal-server-sdk": "^1.1.0"