@internetarchive/donation-form 0.5.12-a1 → 0.5.12-a4

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.
Files changed (27) hide show
  1. package/dist/src/donation-form-controller.d.ts +1 -0
  2. package/dist/src/donation-form-controller.js +6 -0
  3. package/dist/src/donation-form-controller.js.map +1 -1
  4. package/dist/src/donation-form.d.ts +1 -0
  5. package/dist/src/donation-form.js +17 -4
  6. package/dist/src/donation-form.js.map +1 -1
  7. package/dist/src/modals/confirm-donation-modal-content.d.ts +2 -0
  8. package/dist/src/modals/confirm-donation-modal-content.js +12 -3
  9. package/dist/src/modals/confirm-donation-modal-content.js.map +1 -1
  10. package/dist/src/payment-flow-handlers/donation-flow-modal-manager.js +5 -6
  11. package/dist/src/payment-flow-handlers/donation-flow-modal-manager.js.map +1 -1
  12. package/dist/src/payment-flow-handlers/handlers/paypal-flow-handler.d.ts +5 -0
  13. package/dist/src/payment-flow-handlers/handlers/paypal-flow-handler.js +6 -9
  14. package/dist/src/payment-flow-handlers/handlers/paypal-flow-handler.js.map +1 -1
  15. package/dist/test/tests/flow-handlers/donation-flow-modal-manager.test.js +23 -0
  16. package/dist/test/tests/flow-handlers/donation-flow-modal-manager.test.js.map +1 -1
  17. package/dist/test/tests/payment-providers/paypal-button-datasource.test.js +3 -0
  18. package/dist/test/tests/payment-providers/paypal-button-datasource.test.js.map +1 -1
  19. package/package.json +1 -1
  20. package/src/donation-form-controller.ts +7 -0
  21. package/src/donation-form.ts +14 -0
  22. package/src/modals/confirm-donation-modal-content.ts +14 -4
  23. package/src/payment-flow-handlers/donation-flow-modal-manager.ts +6 -6
  24. package/src/payment-flow-handlers/handlers/paypal-flow-handler.ts +7 -12
  25. package/dist/src/modals/payment-confirmation-content.d.ts +0 -23
  26. package/dist/src/modals/payment-confirmation-content.js +0 -74
  27. package/dist/src/modals/payment-confirmation-content.js.map +0 -1
@@ -13,6 +13,7 @@ export interface PayPalFlowHandlerEvents {
13
13
  payPalPaymentStarted: (dataSource: PayPalButtonDataSourceInterface, options: object) => void;
14
14
  payPalPaymentCancelled: (dataSource: PayPalButtonDataSourceInterface, data: object) => void;
15
15
  payPalPaymentError: (dataSource: PayPalButtonDataSourceInterface, error: string) => void;
16
+ payPalPaymentConfirmed: (dataSource: PayPalButtonDataSourceInterface, data: object) => void;
16
17
  }
17
18
  /**
18
19
  * This class manages the user-flow for PayPal.
@@ -36,6 +37,10 @@ export declare class PayPalFlowHandler implements PayPalFlowHandlerInterface, Pa
36
37
  });
37
38
  on<E extends keyof PayPalFlowHandlerEvents>(event: E, callback: PayPalFlowHandlerEvents[E]): Unsubscribe;
38
39
  payPalPaymentStarted(dataSource: PayPalButtonDataSourceInterface, options: object): Promise<void>;
40
+ /**
41
+ * Once we have the dataSource & payload, we ask patron to confirm donation.
42
+ * Once confirmed, we move forward to: `payPalPaymentConfirmed`
43
+ */
39
44
  payPalPaymentAuthorized(dataSource: PayPalButtonDataSourceInterface, payload: paypal.TokenizePayload): Promise<void>;
40
45
  payPalPaymentConfirmed(dataSource: PayPalButtonDataSourceInterface, payload: paypal.TokenizePayload): Promise<void>;
41
46
  payPalPaymentCancelled(dataSource: PayPalButtonDataSourceInterface, data: object): Promise<void>;
@@ -48,20 +48,19 @@ export class PayPalFlowHandler {
48
48
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
49
49
  options) {
50
50
  return __awaiter(this, void 0, void 0, function* () {
51
- console.log('payPalPaymentStarted *******', { dataSource, options });
52
51
  this.emitter.emit('payPalPaymentStarted', dataSource, options);
53
52
  });
54
53
  }
54
+ /**
55
+ * Once we have the dataSource & payload, we ask patron to confirm donation.
56
+ * Once confirmed, we move forward to: `payPalPaymentConfirmed`
57
+ */
55
58
  payPalPaymentAuthorized(dataSource, payload) {
56
59
  return __awaiter(this, void 0, void 0, function* () {
57
- // we got dataSource & payload
58
- // we need to send it to `payPalPaymentConfirmed`
59
- // after patron confirms the payment
60
- console.log('payPalPaymentAuthorized *******', { dataSource, payload });
61
- const { donationType, amount } = dataSource.donationInfo;
60
+ const { donationType, total } = dataSource.donationInfo;
62
61
  this.donationFlowModalManager.showConfirmationStepModal({
63
62
  donationType,
64
- amount,
63
+ amount: total,
65
64
  currencyType: 'USD',
66
65
  confirmDonationCB: () => {
67
66
  this.payPalPaymentConfirmed(dataSource, payload);
@@ -71,8 +70,6 @@ export class PayPalFlowHandler {
71
70
  this.payPalPaymentCancelled(dataSource, {});
72
71
  }
73
72
  });
74
- // cancel payment on modal X
75
- // cancel payment on cancel
76
73
  });
77
74
  }
78
75
  payPalPaymentConfirmed(dataSource, payload) {
@@ -1 +1 @@
1
- {"version":3,"file":"paypal-flow-handler.js","sourceRoot":"","sources":["../../../../src/payment-flow-handlers/handlers/paypal-flow-handler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,gBAAgB,EAAwB,MAAM,YAAY,CAAC;AAMpE,OAAO,EAEL,YAAY,EACZ,mBAAmB,EAEnB,YAAY,EACZ,WAAW,EACX,eAAe,GAEhB,MAAM,4CAA4C,CAAC;AAGpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAEL,wBAAwB,GACzB,MAAM,gCAAgC,CAAC;AAYxC;;;;GAIG;AACH,MAAM,yBAAyB;IAK7B,YAAY,OAIX;QACC,IAAI,CAAC,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC;QAC7D,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;QAC7C,IAAI,CAAC,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAC/D,CAAC;CACF;AAQD;;;;;;;GAOG;AACH,MAAM,OAAO,iBAAiB;IAwB5B,YAAY,OAGX;QAjBO,YAAO,GAAqC,gBAAgB,EAA2B,CAAC;QAkB9F,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QACjD,IAAI,CAAC,wBAAwB,GAAG,OAAO,CAAC,wBAAwB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AK,EAAE,MAAkC;oBACzC,IAAI,EAAE,YAAuC;oBAC7C,OAAO,EAAE,KAAK;iBACf;gBACD,YAAY,EAAE,OAAO,CAAC,YAAY;aACnC,EAAC,CAAC;YAEH,IAAI,sBAAsB,EAAE;gBAC1B,sBAAsB,CAAC,QAAQ,GAAG,IAAI,CAAC;gBACvC,IAAI,CAAC,+BAA+B,GAAG,IAAI,yBAAyB,CAAC;oBACnE,sBAAsB,EAAE,sBAAsB;oBAC9C,cAAc,EAAE,OAAO,CAAC,cAAc;oBACtC,sBAAsB,EAAE,OAAO,CAAC,sBAAsB;iBACvD,CAAC,CAAC;aACJ;iBAAM;gBACL,OAAO,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;aACvD;;KACF;CACF","sourcesContent":["import { createNanoEvents, Emitter, Unsubscribe } from 'nanoevents';\n\nimport {\n PayPalButtonDataSourceInterface,\n PayPalButtonDataSourceDelegate,\n} from '../../braintree-manager/payment-providers/paypal/paypal-button-datasource';\nimport {\n DonationResponse,\n DonationType,\n DonationPaymentInfo,\n SuccessResponse,\n CustomerInfo,\n BillingInfo,\n PaymentProvider,\n ErrorResponse,\n} from '@internetarchive/donation-form-data-models';\nimport { BraintreeManagerInterface } from '../../braintree-manager/braintree-interfaces';\n\nimport { UpsellModalCTAMode } from '../../modals/upsell-modal-content';\nimport {\n DonationFlowModalManagerInterface,\n DonationFlowModalManager,\n} from '../donation-flow-modal-manager';\n\nexport interface PayPalFlowHandlerInterface {\n updateDonationInfo(donationInfo: DonationPaymentInfo): void;\n updateUpsellDonationInfo(donationInfo: DonationPaymentInfo): void;\n renderPayPalButton(donationInfo: DonationPaymentInfo): Promise<void>;\n on<E extends keyof PayPalFlowHandlerEvents>(\n event: E,\n callback: PayPalFlowHandlerEvents[E],\n ): Unsubscribe;\n}\n\n/**\n * This is a class to combine the data from the one-time purchase to the upsell\n *\n * @class UpsellDataSourceContainer\n */\nclass UpsellDataSourceContainer {\n upsellButtonDataSource: PayPalButtonDataSourceInterface;\n oneTimePayload: paypal.TokenizePayload;\n oneTimeSuccessResponse: SuccessResponse;\n\n constructor(options: {\n upsellButtonDataSource: PayPalButtonDataSourceInterface;\n oneTimePayload: paypal.TokenizePayload;\n oneTimeSuccessResponse: SuccessResponse;\n }) {\n this.upsellButtonDataSource = options.upsellButtonDataSource;\n this.oneTimePayload = options.oneTimePayload;\n this.oneTimeSuccessResponse = options.oneTimeSuccessResponse;\n }\n}\n\nexport interface PayPalFlowHandlerEvents {\n payPalPaymentStarted: (dataSource: PayPalButtonDataSourceInterface, options: object) => void;\n payPalPaymentCancelled: (dataSource: PayPalButtonDataSourceInterface, data: object) => void;\n payPalPaymentError: (dataSource: PayPalButtonDataSourceInterface, error: string) => void;\n}\n\n/**\n * This class manages the user-flow for PayPal.\n *\n * @export\n * @class PayPalFlowHandler\n * @implements {PayPalFlowHandlerInterface}\n * @implements {PayPalButtonDataSourceDelegate}\n */\nexport class PayPalFlowHandler\n implements PayPalFlowHandlerInterface, PayPalButtonDataSourceDelegate {\n private upsellButtonDataSourceContainer?: UpsellDataSourceContainer;\n\n private buttonDataSource?: PayPalButtonDataSourceInterface;\n\n private donationFlowModalManager: DonationFlowModalManagerInterface;\n\n private braintreeManager: BraintreeManagerInterface;\n\n private emitter: Emitter<PayPalFlowHandlerEvents> = createNanoEvents<PayPalFlowHandlerEvents>();\n\n updateDonationInfo(donationInfo: DonationPaymentInfo): void {\n if (this.buttonDataSource) {\n this.buttonDataSource.donationInfo = donationInfo;\n }\n }\n\n updateUpsellDonationInfo(donationInfo: DonationPaymentInfo): void {\n if (this.upsellButtonDataSourceContainer) {\n this.upsellButtonDataSourceContainer.upsellButtonDataSource.donationInfo = donationInfo;\n }\n }\n\n constructor(options: {\n braintreeManager: BraintreeManagerInterface;\n donationFlowModalManager: DonationFlowModalManagerInterface;\n }) {\n this.braintreeManager = options.braintreeManager;\n this.donationFlowModalManager = options.donationFlowModalManager;\n }\n\n on<E extends keyof PayPalFlowHandlerEvents>(\n event: E,\n callback: PayPalFlowHandlerEvents[E],\n ): Unsubscribe {\n return this.emitter.on(event, callback);\n }\n\n async payPalPaymentStarted(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n dataSource: PayPalButtonDataSourceInterface,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n options: object,\n ): Promise<void> {\n console.log('payPalPaymentStarted *******', { dataSource, options });\n this.emitter.emit('payPalPaymentStarted', dataSource, options);\n }\n\n async payPalPaymentAuthorized(dataSource: PayPalButtonDataSourceInterface,\n payload: paypal.TokenizePayload\n ): Promise<void> {\n\n // we got dataSource & payload\n // we need to send it to `payPalPaymentConfirmed`\n // after patron confirms the payment\n console.log('payPalPaymentAuthorized *******', { dataSource, payload });\n\n const { donationType, amount } = dataSource.donationInfo;\n this.donationFlowModalManager.showConfirmationStepModal({\n donationType,\n amount,\n currencyType: 'USD', // defaults to USD for now\n confirmDonationCB: () => {\n this.payPalPaymentConfirmed(dataSource, payload);\n },\n cancelDonationCB: () => {\n this.donationFlowModalManager.closeModal();\n this.payPalPaymentCancelled(dataSource, {});\n }\n });\n\n // cancel payment on modal X\n // cancel payment on cancel\n \n }\n\n async payPalPaymentConfirmed(\n dataSource: PayPalButtonDataSourceInterface,\n payload: paypal.TokenizePayload,\n ): Promise<void> {\n this.donationFlowModalManager.showProcessingModal();\n\n const donationType = dataSource.donationInfo.donationType;\n\n const details = payload?.details;\n\n const customerInfo = new CustomerInfo({\n email: details?.email,\n firstName: details?.firstName,\n lastName: details?.lastName,\n });\n\n const shippingAddress = details.shippingAddress;\n\n const billingInfo = new BillingInfo({\n streetAddress: shippingAddress?.line1,\n extendedAddress: shippingAddress?.line2,\n locality: shippingAddress?.city,\n region: shippingAddress?.state,\n postalCode: shippingAddress?.postalCode,\n countryCodeAlpha2: shippingAddress?.countryCode,\n });\n\n const oneTimeTransaction = this.upsellButtonDataSourceContainer\n ? this.upsellButtonDataSourceContainer.oneTimeSuccessResponse.transaction_id\n : undefined;\n\n const response: DonationResponse = await this.braintreeManager.submitDonation({\n nonce: payload.nonce,\n paymentProvider: PaymentProvider.PayPal,\n donationInfo: dataSource.donationInfo,\n customerInfo: customerInfo,\n billingInfo: billingInfo,\n upsellOnetimeTransactionId: oneTimeTransaction,\n });\n\n if (!response.success) {\n const error = response.value as ErrorResponse;\n this.donationFlowModalManager.showErrorModal({\n message: error.message,\n });\n return;\n }\n\n const successResponse = response.value as SuccessResponse;\n\n switch (donationType) {\n case DonationType.OneTime:\n this.showUpsellModal(payload, successResponse);\n break;\n case DonationType.Monthly:\n // show thank you, redirect\n this.donationFlowModalManager.showThankYouModal({ successResponse });\n break;\n case DonationType.Upsell:\n if (this.upsellButtonDataSourceContainer) {\n this.donationFlowModalManager.showThankYouModal({\n successResponse: this.upsellButtonDataSourceContainer.oneTimeSuccessResponse,\n upsellSuccessResponse: successResponse,\n });\n } else {\n // we're in the upsell flow, but no upsell data source container.. this should not happen\n this.donationFlowModalManager.showErrorModal({\n message: 'Error setting up monthly donation',\n });\n }\n break;\n }\n }\n\n async payPalPaymentCancelled(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n dataSource: PayPalButtonDataSourceInterface,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n data: object,\n ): Promise<void> {\n this.emitter.emit('payPalPaymentCancelled', dataSource, data);\n }\n\n async payPalPaymentError(\n dataSource: PayPalButtonDataSourceInterface,\n error: string,\n ): Promise<void> {\n this.emitter.emit('payPalPaymentError', dataSource, error);\n console.error(\n 'PaymentSector:payPalPaymentError error:',\n dataSource,\n dataSource.donationInfo,\n error,\n );\n }\n\n async renderPayPalButton(donationInfo: DonationPaymentInfo): Promise<void> {\n const handler = await this.braintreeManager?.paymentProviders.paypalHandler.get();\n\n this.buttonDataSource = await handler?.renderPayPalButton({\n selector: '#paypal-button',\n style: {\n color: 'blue' as paypal.ButtonColorOption, // I'm not sure why I can't access the enum directly here.. I get a UMD error\n label: 'paypal' as paypal.ButtonLabelOption,\n shape: 'rect' as paypal.ButtonShapeOption,\n size: 'medium' as paypal.ButtonSizeOption,\n tagline: false,\n },\n donationInfo: donationInfo,\n });\n\n if (this.buttonDataSource) {\n this.buttonDataSource.delegate = this;\n }\n }\n\n private async showUpsellModal(\n oneTimePayload: paypal.TokenizePayload,\n oneTimeSuccessResponse: SuccessResponse,\n ): Promise<void> {\n this.donationFlowModalManager.showUpsellModal({\n oneTimeAmount: oneTimeSuccessResponse.amount,\n amountChanged: this.upsellAmountChanged.bind(this),\n noSelected: () => {\n this.donationFlowModalManager.showThankYouModal({\n successResponse: oneTimeSuccessResponse,\n });\n },\n ctaMode: UpsellModalCTAMode.PayPalUpsellSlot,\n userClosedModalCallback: () => {\n this.donationFlowModalManager.showThankYouModal({\n successResponse: oneTimeSuccessResponse,\n });\n },\n });\n\n const amount = DonationFlowModalManager.getDefaultUpsellAmount(oneTimeSuccessResponse.amount);\n\n const upsellDonationInfo = new DonationPaymentInfo({\n amount: amount,\n donationType: DonationType.Upsell,\n coverFees: false,\n });\n\n if (!this.upsellButtonDataSourceContainer) {\n this.renderUpsellPayPalButton({\n donationInfo: upsellDonationInfo,\n oneTimePayload,\n oneTimeSuccessResponse,\n });\n }\n }\n\n private upsellAmountChanged(amount: number): void {\n if (this.upsellButtonDataSourceContainer) {\n this.upsellButtonDataSourceContainer.upsellButtonDataSource.donationInfo.amount = amount;\n }\n }\n\n private async renderUpsellPayPalButton(options: {\n donationInfo: DonationPaymentInfo;\n oneTimePayload: paypal.TokenizePayload;\n oneTimeSuccessResponse: SuccessResponse;\n }): Promise<void> {\n const handler = await this.braintreeManager?.paymentProviders.paypalHandler.get();\n\n const upsellButtonDataSource = await handler?.renderPayPalButton({\n selector: '#paypal-upsell-button',\n style: {\n color: 'blue' as paypal.ButtonColorOption,\n label: 'paypal' as paypal.ButtonLabelOption,\n shape: 'rect' as paypal.ButtonShapeOption,\n size: 'responsive' as paypal.ButtonSizeOption,\n tagline: false,\n },\n donationInfo: options.donationInfo,\n });\n\n if (upsellButtonDataSource) {\n upsellButtonDataSource.delegate = this;\n this.upsellButtonDataSourceContainer = new UpsellDataSourceContainer({\n upsellButtonDataSource: upsellButtonDataSource,\n oneTimePayload: options.oneTimePayload,\n oneTimeSuccessResponse: options.oneTimeSuccessResponse,\n });\n } else {\n console.error('error rendering paypal upsell button');\n }\n }\n}\n"]}
1
+ {"version":3,"file":"paypal-flow-handler.js","sourceRoot":"","sources":["../../../../src/payment-flow-handlers/handlers/paypal-flow-handler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,gBAAgB,EAAwB,MAAM,YAAY,CAAC;AAMpE,OAAO,EAEL,YAAY,EACZ,mBAAmB,EAEnB,YAAY,EACZ,WAAW,EACX,eAAe,GAEhB,MAAM,4CAA4C,CAAC;AAGpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAEL,wBAAwB,GACzB,MAAM,gCAAgC,CAAC;AAYxC;;;;GAIG;AACH,MAAM,yBAAyB;IAK7B,YAAY,OAIX;QACC,IAAI,CAAC,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC;QAC7D,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;QAC7C,IAAI,CAAC,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAC/D,CAAC;CACF;AASD;;;;;;;GAOG;AACH,MAAM,OAAO,iBAAiB;IAwB5B,YAAY,OAGX;QAjBO,YAAO,GAAqC,gBAAgB,EAA2B,CAAC;QAkB9F,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QACjD,IAAI,CAAC,wBAAwB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IACnE,CAAC;IAlBD,kBAAkB,CAAC,YAAiC;QAClD,IAAI,IAAI,CAAC,gBAAgB,EAAE;YACzB,IAAI,CAAC,gBAAgB,CAAC,YAAY,GAAG,YAAY,CAAC;SACnD;IACH,CAAC;IAED,wBAAwB,CAAC,YAAiC;QACxD,IAAI,IAAI,C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sCAAsC,CAAC,CAAC;aACvD;;KACF;CACF","sourcesContent":["import { createNanoEvents, Emitter, Unsubscribe } from 'nanoevents';\n\nimport {\n PayPalButtonDataSourceInterface,\n PayPalButtonDataSourceDelegate,\n} from '../../braintree-manager/payment-providers/paypal/paypal-button-datasource';\nimport {\n DonationResponse,\n DonationType,\n DonationPaymentInfo,\n SuccessResponse,\n CustomerInfo,\n BillingInfo,\n PaymentProvider,\n ErrorResponse,\n} from '@internetarchive/donation-form-data-models';\nimport { BraintreeManagerInterface } from '../../braintree-manager/braintree-interfaces';\n\nimport { UpsellModalCTAMode } from '../../modals/upsell-modal-content';\nimport {\n DonationFlowModalManagerInterface,\n DonationFlowModalManager,\n} from '../donation-flow-modal-manager';\n\nexport interface PayPalFlowHandlerInterface {\n updateDonationInfo(donationInfo: DonationPaymentInfo): void;\n updateUpsellDonationInfo(donationInfo: DonationPaymentInfo): void;\n renderPayPalButton(donationInfo: DonationPaymentInfo): Promise<void>;\n on<E extends keyof PayPalFlowHandlerEvents>(\n event: E,\n callback: PayPalFlowHandlerEvents[E],\n ): Unsubscribe;\n}\n\n/**\n * This is a class to combine the data from the one-time purchase to the upsell\n *\n * @class UpsellDataSourceContainer\n */\nclass UpsellDataSourceContainer {\n upsellButtonDataSource: PayPalButtonDataSourceInterface;\n oneTimePayload: paypal.TokenizePayload;\n oneTimeSuccessResponse: SuccessResponse;\n\n constructor(options: {\n upsellButtonDataSource: PayPalButtonDataSourceInterface;\n oneTimePayload: paypal.TokenizePayload;\n oneTimeSuccessResponse: SuccessResponse;\n }) {\n this.upsellButtonDataSource = options.upsellButtonDataSource;\n this.oneTimePayload = options.oneTimePayload;\n this.oneTimeSuccessResponse = options.oneTimeSuccessResponse;\n }\n}\n\nexport interface PayPalFlowHandlerEvents {\n payPalPaymentStarted: (dataSource: PayPalButtonDataSourceInterface, options: object) => void;\n payPalPaymentCancelled: (dataSource: PayPalButtonDataSourceInterface, data: object) => void;\n payPalPaymentError: (dataSource: PayPalButtonDataSourceInterface, error: string) => void;\n payPalPaymentConfirmed: (dataSource: PayPalButtonDataSourceInterface, data: object) => void;\n}\n\n/**\n * This class manages the user-flow for PayPal.\n *\n * @export\n * @class PayPalFlowHandler\n * @implements {PayPalFlowHandlerInterface}\n * @implements {PayPalButtonDataSourceDelegate}\n */\nexport class PayPalFlowHandler\n implements PayPalFlowHandlerInterface, PayPalButtonDataSourceDelegate {\n private upsellButtonDataSourceContainer?: UpsellDataSourceContainer;\n\n private buttonDataSource?: PayPalButtonDataSourceInterface;\n\n private donationFlowModalManager: DonationFlowModalManagerInterface;\n\n private braintreeManager: BraintreeManagerInterface;\n\n private emitter: Emitter<PayPalFlowHandlerEvents> = createNanoEvents<PayPalFlowHandlerEvents>();\n\n updateDonationInfo(donationInfo: DonationPaymentInfo): void {\n if (this.buttonDataSource) {\n this.buttonDataSource.donationInfo = donationInfo;\n }\n }\n\n updateUpsellDonationInfo(donationInfo: DonationPaymentInfo): void {\n if (this.upsellButtonDataSourceContainer) {\n this.upsellButtonDataSourceContainer.upsellButtonDataSource.donationInfo = donationInfo;\n }\n }\n\n constructor(options: {\n braintreeManager: BraintreeManagerInterface;\n donationFlowModalManager: DonationFlowModalManagerInterface;\n }) {\n this.braintreeManager = options.braintreeManager;\n this.donationFlowModalManager = options.donationFlowModalManager;\n }\n\n on<E extends keyof PayPalFlowHandlerEvents>(\n event: E,\n callback: PayPalFlowHandlerEvents[E],\n ): Unsubscribe {\n return this.emitter.on(event, callback);\n }\n\n async payPalPaymentStarted(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n dataSource: PayPalButtonDataSourceInterface,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n options: object,\n ): Promise<void> {\n this.emitter.emit('payPalPaymentStarted', dataSource, options);\n }\n\n /**\n * Once we have the dataSource & payload, we ask patron to confirm donation.\n * Once confirmed, we move forward to: `payPalPaymentConfirmed`\n */\n async payPalPaymentAuthorized(dataSource: PayPalButtonDataSourceInterface,\n payload: paypal.TokenizePayload\n ): Promise<void> {\n\n const { donationType, total } = dataSource.donationInfo;\n this.donationFlowModalManager.showConfirmationStepModal({\n donationType,\n amount: total,\n currencyType: 'USD', // defaults to USD for now\n confirmDonationCB: () => {\n this.payPalPaymentConfirmed(dataSource, payload);\n },\n cancelDonationCB: () => {\n this.donationFlowModalManager.closeModal();\n this.payPalPaymentCancelled(dataSource, {});\n }\n });\n }\n\n async payPalPaymentConfirmed(\n dataSource: PayPalButtonDataSourceInterface,\n payload: paypal.TokenizePayload,\n ): Promise<void> {\n this.donationFlowModalManager.showProcessingModal();\n\n const donationType = dataSource.donationInfo.donationType;\n\n const details = payload?.details;\n\n const customerInfo = new CustomerInfo({\n email: details?.email,\n firstName: details?.firstName,\n lastName: details?.lastName,\n });\n\n const shippingAddress = details.shippingAddress;\n\n const billingInfo = new BillingInfo({\n streetAddress: shippingAddress?.line1,\n extendedAddress: shippingAddress?.line2,\n locality: shippingAddress?.city,\n region: shippingAddress?.state,\n postalCode: shippingAddress?.postalCode,\n countryCodeAlpha2: shippingAddress?.countryCode,\n });\n\n const oneTimeTransaction = this.upsellButtonDataSourceContainer\n ? this.upsellButtonDataSourceContainer.oneTimeSuccessResponse.transaction_id\n : undefined;\n\n const response: DonationResponse = await this.braintreeManager.submitDonation({\n nonce: payload.nonce,\n paymentProvider: PaymentProvider.PayPal,\n donationInfo: dataSource.donationInfo,\n customerInfo: customerInfo,\n billingInfo: billingInfo,\n upsellOnetimeTransactionId: oneTimeTransaction,\n });\n\n if (!response.success) {\n const error = response.value as ErrorResponse;\n this.donationFlowModalManager.showErrorModal({\n message: error.message,\n });\n return;\n }\n\n const successResponse = response.value as SuccessResponse;\n\n switch (donationType) {\n case DonationType.OneTime:\n this.showUpsellModal(payload, successResponse);\n break;\n case DonationType.Monthly:\n // show thank you, redirect\n this.donationFlowModalManager.showThankYouModal({ successResponse });\n break;\n case DonationType.Upsell:\n if (this.upsellButtonDataSourceContainer) {\n this.donationFlowModalManager.showThankYouModal({\n successResponse: this.upsellButtonDataSourceContainer.oneTimeSuccessResponse,\n upsellSuccessResponse: successResponse,\n });\n } else {\n // we're in the upsell flow, but no upsell data source container.. this should not happen\n this.donationFlowModalManager.showErrorModal({\n message: 'Error setting up monthly donation',\n });\n }\n break;\n }\n }\n\n async payPalPaymentCancelled(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n dataSource: PayPalButtonDataSourceInterface,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n data: object,\n ): Promise<void> {\n this.emitter.emit('payPalPaymentCancelled', dataSource, data);\n }\n\n async payPalPaymentError(\n dataSource: PayPalButtonDataSourceInterface,\n error: string,\n ): Promise<void> {\n this.emitter.emit('payPalPaymentError', dataSource, error);\n console.error(\n 'PaymentSector:payPalPaymentError error:',\n dataSource,\n dataSource.donationInfo,\n error,\n );\n }\n\n async renderPayPalButton(donationInfo: DonationPaymentInfo): Promise<void> {\n const handler = await this.braintreeManager?.paymentProviders.paypalHandler.get();\n\n this.buttonDataSource = await handler?.renderPayPalButton({\n selector: '#paypal-button',\n style: {\n color: 'blue' as paypal.ButtonColorOption, // I'm not sure why I can't access the enum directly here.. I get a UMD error\n label: 'paypal' as paypal.ButtonLabelOption,\n shape: 'rect' as paypal.ButtonShapeOption,\n size: 'medium' as paypal.ButtonSizeOption,\n tagline: false,\n },\n donationInfo: donationInfo,\n });\n\n if (this.buttonDataSource) {\n this.buttonDataSource.delegate = this;\n }\n }\n\n private async showUpsellModal(\n oneTimePayload: paypal.TokenizePayload,\n oneTimeSuccessResponse: SuccessResponse,\n ): Promise<void> {\n this.donationFlowModalManager.showUpsellModal({\n oneTimeAmount: oneTimeSuccessResponse.amount,\n amountChanged: this.upsellAmountChanged.bind(this),\n noSelected: () => {\n this.donationFlowModalManager.showThankYouModal({\n successResponse: oneTimeSuccessResponse,\n });\n },\n ctaMode: UpsellModalCTAMode.PayPalUpsellSlot,\n userClosedModalCallback: () => {\n this.donationFlowModalManager.showThankYouModal({\n successResponse: oneTimeSuccessResponse,\n });\n },\n });\n\n const amount = DonationFlowModalManager.getDefaultUpsellAmount(oneTimeSuccessResponse.amount);\n\n const upsellDonationInfo = new DonationPaymentInfo({\n amount: amount,\n donationType: DonationType.Upsell,\n coverFees: false,\n });\n\n if (!this.upsellButtonDataSourceContainer) {\n this.renderUpsellPayPalButton({\n donationInfo: upsellDonationInfo,\n oneTimePayload,\n oneTimeSuccessResponse,\n });\n }\n }\n\n private upsellAmountChanged(amount: number): void {\n if (this.upsellButtonDataSourceContainer) {\n this.upsellButtonDataSourceContainer.upsellButtonDataSource.donationInfo.amount = amount;\n }\n }\n\n private async renderUpsellPayPalButton(options: {\n donationInfo: DonationPaymentInfo;\n oneTimePayload: paypal.TokenizePayload;\n oneTimeSuccessResponse: SuccessResponse;\n }): Promise<void> {\n const handler = await this.braintreeManager?.paymentProviders.paypalHandler.get();\n\n const upsellButtonDataSource = await handler?.renderPayPalButton({\n selector: '#paypal-upsell-button',\n style: {\n color: 'blue' as paypal.ButtonColorOption,\n label: 'paypal' as paypal.ButtonLabelOption,\n shape: 'rect' as paypal.ButtonShapeOption,\n size: 'responsive' as paypal.ButtonSizeOption,\n tagline: false,\n },\n donationInfo: options.donationInfo,\n });\n\n if (upsellButtonDataSource) {\n upsellButtonDataSource.delegate = this;\n this.upsellButtonDataSourceContainer = new UpsellDataSourceContainer({\n upsellButtonDataSource: upsellButtonDataSource,\n oneTimePayload: options.oneTimePayload,\n oneTimeSuccessResponse: options.oneTimeSuccessResponse,\n });\n } else {\n console.error('error rendering paypal upsell button');\n }\n }\n}\n"]}
@@ -98,6 +98,29 @@ describe('Donation Flow Modal Manager', () => {
98
98
  const response = (_e = mockBraintreeManager.donationSuccessfulOptions) === null || _e === void 0 ? void 0 : _e.successResponse;
99
99
  expect(response).to.deep.equal(mockSuccessResponse);
100
100
  }));
101
+ it('can show the confirmation modal', () => __awaiter(void 0, void 0, void 0, function* () {
102
+ var _f, _g;
103
+ const mockModalManager = (yield fixture(html `
104
+ <mock-modal-manager></mock-modal-manager>
105
+ `));
106
+ const mockBraintreeManager = new MockBraintreeManager();
107
+ const manager = new DonationFlowModalManager({
108
+ braintreeManager: mockBraintreeManager,
109
+ modalManager: mockModalManager,
110
+ });
111
+ manager.showConfirmationStepModal({
112
+ donationType: DonationType.Upsell,
113
+ amount: 8,
114
+ currencyType: 'USD',
115
+ cancelDonationCB: () => console.log('donation cancelled'),
116
+ confirmDonationCB: () => console.log('donation confirmed'),
117
+ });
118
+ const modalOptions = mockModalManager.showModalOptions;
119
+ expect(modalOptions === null || modalOptions === void 0 ? void 0 : modalOptions.config.headerColor).to.equal('#55A183');
120
+ expect(modalOptions === null || modalOptions === void 0 ? void 0 : modalOptions.config.closeOnBackdropClick).to.be.false;
121
+ expect(modalOptions === null || modalOptions === void 0 ? void 0 : modalOptions.config.showCloseButton).to.be.true;
122
+ expect((_g = (_f = modalOptions === null || modalOptions === void 0 ? void 0 : modalOptions.config) === null || _f === void 0 ? void 0 : _f.title) === null || _g === void 0 ? void 0 : _g.values).to.contain('Confirm monthly donation');
123
+ }));
101
124
  it('can start the donation submission flow', () => __awaiter(void 0, void 0, void 0, function* () {
102
125
  const mockModalManager = (yield fixture(html `
103
126
  <mock-modal-manager></mock-modal-manager>
@@ -1 +1 @@
1
- {"version":3,"file":"donation-flow-modal-manager.test.js","sourceRoot":"","sources":["../../../../test/tests/flow-handlers/donation-flow-modal-manager.test.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,gEAAgE,CAAC;AAE1G,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAC/E,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,YAAY,GACb,MAAM,4CAA4C,C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MAAM,EAAE,CAAC;gBACT,SAAS,EAAE,KAAK;aACjB,CAAC;YACF,WAAW,EAAE,eAAe;YAC5B,YAAY,EAAE,gBAAgB;SAC/B,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC;YAC3B,OAAO,EAAE,IAAI;YACb,KAAK,EAAE;gBACL,MAAM,EAAE,CAAC;gBACT,OAAO,EAAE;oBACP,iBAAiB,EAAE,IAAI;oBACvB,eAAe,EAAE,SAAS;oBAC1B,QAAQ,EAAE,eAAe;oBACzB,UAAU,EAAE,OAAO;oBACnB,MAAM,EAAE,IAAI;oBACZ,aAAa,EAAE,aAAa;iBAC7B;gBACD,QAAQ,EAAE;oBACR,KAAK,EAAE,aAAa;oBACpB,SAAS,EAAE,OAAO;oBAClB,QAAQ,EAAE,YAAY;iBACvB;gBACD,WAAW,EAAE,KAAK;gBAClB,YAAY,EAAE,UAAU;gBACxB,kBAAkB,EAAE,KAAK;gBACzB,eAAe,EAAE,aAAa;gBAC9B,cAAc,EAAE,KAAK;aACtB;SACF,CAAC,CAAC;IACL,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/camelcase */\nimport { html, fixture, expect } from '@open-wc/testing';\nimport { DonationFlowModalManager } from '../../../src/payment-flow-handlers/donation-flow-modal-manager';\nimport { MockModalManager } from '../../mocks/mock-modal-manager';\nimport '../../mocks/mock-modal-manager';\nimport { MockBraintreeManager } from '../../mocks/mock-braintree-manager';\nimport { mockSuccessResponse } from '../../mocks/models/mock-success-response';\nimport {\n PaymentProvider,\n DonationPaymentInfo,\n DonationType,\n} from '@internetarchive/donation-form-data-models';\nimport { mockBillingInfo } from '../../mocks/models/mock-billing-info';\nimport { mockCustomerInfo } from '../../mocks/models/mock-customer-info';\n\ndescribe('Donation Flow Modal Manager', () => {\n it('can close the modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n });\n manager.closeModal();\n expect(mockModalManager.closeCalled).to.be.true;\n });\n\n it('can calculate the proper default upsell amount', async () => {\n let amount = DonationFlowModalManager.getDefaultUpsellAmount(1);\n expect(amount).to.equal(5);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(10);\n expect(amount).to.equal(5);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(10.01);\n expect(amount).to.equal(10);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(25);\n expect(amount).to.equal(10);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(25.01);\n expect(amount).to.equal(25);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(100);\n expect(amount).to.equal(25);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(100.01);\n expect(amount).to.equal(50);\n });\n\n it('can show the processing modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n });\n manager.showProcessingModal();\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#497fbf');\n expect(modalOptions?.config.showProcessingIndicator).to.be.true;\n expect(modalOptions?.config.processingImageMode).to.equal('processing');\n expect(modalOptions?.config.closeOnBackdropClick).to.be.false;\n expect(modalOptions?.config.showCloseButton).to.be.false;\n expect(modalOptions?.config.title?.strings[0]).to.contain('Processing...');\n });\n\n it('can show the error modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n });\n manager.showErrorModal({ message: 'foo-error' });\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#691916');\n expect(modalOptions?.config.showProcessingIndicator).to.be.false;\n expect(modalOptions?.config.closeOnBackdropClick).to.be.true;\n expect(modalOptions?.config.showCloseButton).to.be.true;\n expect(modalOptions?.config.headline?.strings[0]).to.contain(\n \"There's been a problem completing your donation.\",\n );\n expect(modalOptions?.config.message?.values[0]).to.equal('foo-error');\n });\n\n it('shows the thank you modal and calls `donationSuccessful` to take user to thank you page', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n });\n manager.showThankYouModal({\n successResponse: mockSuccessResponse,\n });\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#55A183');\n expect(modalOptions?.config.processingImageMode).to.equal('complete');\n expect(modalOptions?.config.showProcessingIndicator).to.be.true;\n expect(modalOptions?.config.closeOnBackdropClick).to.be.true;\n expect(modalOptions?.config.showCloseButton).to.be.true;\n expect(modalOptions?.config.title?.strings[0]).to.contain('Thank You!');\n const response = mockBraintreeManager.donationSuccessfulOptions?.successResponse;\n expect(response).to.deep.equal(mockSuccessResponse);\n });\n\n it('can start the donation submission flow', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n });\n const result = await manager.startDonationSubmissionFlow({\n nonce: 'foo',\n paymentProvider: PaymentProvider.CreditCard,\n donationInfo: new DonationPaymentInfo({\n donationType: DonationType.OneTime,\n amount: 5,\n coverFees: false,\n }),\n billingInfo: mockBillingInfo,\n customerInfo: mockCustomerInfo,\n });\n\n expect(result).to.deep.equal({\n success: true,\n value: {\n amount: 5,\n billing: {\n countryCodeAlpha2: 'US',\n extendedAddress: 'Apt 123',\n locality: 'San Francisco',\n postalCode: '12345',\n region: 'CA',\n streetAddress: '123 Fake St',\n },\n customer: {\n email: 'foo@bar.com',\n firstName: 'Fooey',\n lastName: 'McBarrison',\n },\n customer_id: 'bar',\n donationType: 'one-time',\n paymentMethodNonce: 'foo',\n paymentProvider: 'Credit Card',\n transaction_id: 'foo',\n },\n });\n });\n});\n"]}
1
+ {"version":3,"file":"donation-flow-modal-manager.test.js","sourceRoot":"","sources":["../../../../test/tests/flow-handlers/donation-flow-modal-manager.test.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,gEAAgE,CAAC;AAE1G,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAC/E,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,YAAY,GACb,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAGzE,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,EAAE,CAAC,qBAAqB,EAAE,GAAS,EAAE;QACnC,MAAM,gBAAgB,GAAG,CAAC,MAAM,OAAO,CAAC,IAAI,CAAA;;KAE3C,CAAC,CAAqB,CAAC;QACxB,MAAM,oBAAoB,GAAG,IAAI,oBAAoB,EAAE,CAAC;QACxD,MAAM,OAAO,GAAG,IAAI,wBAAwB,CAAC;YAC3C,gBAAgB,EAAE,oBAAoB;YACtC,YAAY,EAAE,gBAAgB;SAC/B,CAAC,CAAC;QACH,OAAO,CAAC,UAAU,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AO;oBAClB,QAAQ,EAAE,YAAY;iBACvB;gBACD,WAAW,EAAE,KAAK;gBAClB,YAAY,EAAE,UAAU;gBACxB,kBAAkB,EAAE,KAAK;gBACzB,eAAe,EAAE,aAAa;gBAC9B,cAAc,EAAE,KAAK;aACtB;SACF,CAAC,CAAC;IACL,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/camelcase */\nimport { html, fixture, expect } from '@open-wc/testing';\nimport { DonationFlowModalManager } from '../../../src/payment-flow-handlers/donation-flow-modal-manager';\nimport { MockModalManager } from '../../mocks/mock-modal-manager';\nimport '../../mocks/mock-modal-manager';\nimport { MockBraintreeManager } from '../../mocks/mock-braintree-manager';\nimport { mockSuccessResponse } from '../../mocks/models/mock-success-response';\nimport {\n PaymentProvider,\n DonationPaymentInfo,\n DonationType,\n} from '@internetarchive/donation-form-data-models';\nimport { mockBillingInfo } from '../../mocks/models/mock-billing-info';\nimport { mockCustomerInfo } from '../../mocks/models/mock-customer-info';\nimport { ModalConfig } from '@internetarchive/modal-manager';\n\ndescribe('Donation Flow Modal Manager', () => {\n it('can close the modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n });\n manager.closeModal();\n expect(mockModalManager.closeCalled).to.be.true;\n });\n\n it('can calculate the proper default upsell amount', async () => {\n let amount = DonationFlowModalManager.getDefaultUpsellAmount(1);\n expect(amount).to.equal(5);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(10);\n expect(amount).to.equal(5);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(10.01);\n expect(amount).to.equal(10);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(25);\n expect(amount).to.equal(10);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(25.01);\n expect(amount).to.equal(25);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(100);\n expect(amount).to.equal(25);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(100.01);\n expect(amount).to.equal(50);\n });\n\n it('can show the processing modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n });\n manager.showProcessingModal();\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#497fbf');\n expect(modalOptions?.config.showProcessingIndicator).to.be.true;\n expect(modalOptions?.config.processingImageMode).to.equal('processing');\n expect(modalOptions?.config.closeOnBackdropClick).to.be.false;\n expect(modalOptions?.config.showCloseButton).to.be.false;\n expect(modalOptions?.config.title?.strings[0]).to.contain('Processing...');\n });\n\n it('can show the error modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n });\n manager.showErrorModal({ message: 'foo-error' });\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#691916');\n expect(modalOptions?.config.showProcessingIndicator).to.be.false;\n expect(modalOptions?.config.closeOnBackdropClick).to.be.true;\n expect(modalOptions?.config.showCloseButton).to.be.true;\n expect(modalOptions?.config.headline?.strings[0]).to.contain(\n \"There's been a problem completing your donation.\",\n );\n expect(modalOptions?.config.message?.values[0]).to.equal('foo-error');\n });\n\n it('shows the thank you modal and calls `donationSuccessful` to take user to thank you page', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n });\n manager.showThankYouModal({\n successResponse: mockSuccessResponse,\n });\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#55A183');\n expect(modalOptions?.config.processingImageMode).to.equal('complete');\n expect(modalOptions?.config.showProcessingIndicator).to.be.true;\n expect(modalOptions?.config.closeOnBackdropClick).to.be.true;\n expect(modalOptions?.config.showCloseButton).to.be.true;\n expect(modalOptions?.config.title?.strings[0]).to.contain('Thank You!');\n const response = mockBraintreeManager.donationSuccessfulOptions?.successResponse;\n expect(response).to.deep.equal(mockSuccessResponse);\n });\n\n it('can show the confirmation modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n });\n manager.showConfirmationStepModal({\n donationType: DonationType.Upsell,\n amount: 8,\n currencyType: 'USD',\n cancelDonationCB: () => console.log('donation cancelled'),\n confirmDonationCB: () => console.log('donation confirmed'),\n });\n\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#55A183');\n expect(modalOptions?.config.closeOnBackdropClick).to.be.false;\n expect(modalOptions?.config.showCloseButton).to.be.true;\n expect(modalOptions?.config?.title?.values).to.contain('Confirm monthly donation');\n });\n\n it('can start the donation submission flow', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n });\n const result = await manager.startDonationSubmissionFlow({\n nonce: 'foo',\n paymentProvider: PaymentProvider.CreditCard,\n donationInfo: new DonationPaymentInfo({\n donationType: DonationType.OneTime,\n amount: 5,\n coverFees: false,\n }),\n billingInfo: mockBillingInfo,\n customerInfo: mockCustomerInfo,\n });\n\n expect(result).to.deep.equal({\n success: true,\n value: {\n amount: 5,\n billing: {\n countryCodeAlpha2: 'US',\n extendedAddress: 'Apt 123',\n locality: 'San Francisco',\n postalCode: '12345',\n region: 'CA',\n streetAddress: '123 Fake St',\n },\n customer: {\n email: 'foo@bar.com',\n firstName: 'Fooey',\n lastName: 'McBarrison',\n },\n customer_id: 'bar',\n donationType: 'one-time',\n paymentMethodNonce: 'foo',\n paymentProvider: 'Credit Card',\n transaction_id: 'foo',\n },\n });\n });\n});\n"]}
@@ -42,6 +42,7 @@ describe('PayPalButtonDataSource', () => {
42
42
  enableShippingAddress: true,
43
43
  amount: 3.5,
44
44
  currency: 'USD',
45
+ intent: 'capture',
45
46
  });
46
47
  }));
47
48
  it('sends the proper one-time donation request with fees covered', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -65,6 +66,7 @@ describe('PayPalButtonDataSource', () => {
65
66
  enableShippingAddress: true,
66
67
  amount: expectedTotal,
67
68
  currency: 'USD',
69
+ intent: 'capture',
68
70
  });
69
71
  }));
70
72
  it('sends the proper monthly donation request', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -85,6 +87,7 @@ describe('PayPalButtonDataSource', () => {
85
87
  flow: 'vault',
86
88
  enableShippingAddress: true,
87
89
  billingAgreementDescription: 'Subscribe to donate $1.50 monthly',
90
+ intent: 'capture',
88
91
  });
89
92
  }));
90
93
  });
@@ -1 +1 @@
1
- {"version":3,"file":"paypal-button-datasource.test.js","sourceRoot":"","sources":["../../../../test/tests/payment-providers/paypal-button-datasource.test.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gDAAgD,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAC/F,OAAO,EAAE,sBAAsB,EAAE,MAAM,kFAAkF,CAAC;AAC1H,OAAO,EAAE,kCAAkC,EAAE,MAAM,2FAA2F,CAAC;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mocks/payment-clients/mock-paypal-client';\nimport { DonationPaymentInfo, DonationType } from '@internetarchive/donation-form-data-models';\nimport { PayPalButtonDataSource } from '../../../src/braintree-manager/payment-providers/paypal/paypal-button-datasource';\nimport { MockPayPalButtonDataSourceDelegate } from '../../mocks/payment-providers/individual-providers/mock-paypal-button-datasource-delegate';\n\ndescribe('PayPalButtonDataSource', () => {\n describe('Payment start', () => {\n it('notifies the delegate and creates the payment when the `payment()` callback is triggered from a button press', async () => {\n const delegate = new MockPayPalButtonDataSourceDelegate();\n const paypalInstance = new MockPayPalClient();\n const donation = new DonationPaymentInfo({\n donationType: DonationType.Monthly,\n amount: 3.5,\n coverFees: false,\n });\n const datasource = new PayPalButtonDataSource({\n donationInfo: donation,\n paypalInstance: paypalInstance,\n });\n\n datasource.delegate = delegate;\n\n const result = await datasource.payment();\n\n expect(delegate.paymentStartedResults.called).to.be.true;\n expect(result).to.equal('createPaymentCalled');\n });\n\n it('sends the proper one-time donation request', async () => {\n const delegate = new MockPayPalButtonDataSourceDelegate();\n const paypalInstance = new MockPayPalClient();\n const donation = new DonationPaymentInfo({\n donationType: DonationType.OneTime,\n amount: 3.5,\n coverFees: false,\n });\n const datasource = new PayPalButtonDataSource({\n donationInfo: donation,\n paypalInstance: paypalInstance,\n });\n datasource.delegate = delegate;\n await datasource.payment();\n expect(delegate.paymentStartedResults.options).to.deep.equal({\n flow: 'checkout',\n enableShippingAddress: true,\n amount: 3.5,\n currency: 'USD',\n });\n });\n\n it('sends the proper one-time donation request with fees covered', async () => {\n const baseAmount = 3.5;\n const expectedTotal = DonationPaymentInfo.calculateTotal(baseAmount, true);\n const delegate = new MockPayPalButtonDataSourceDelegate();\n const paypalInstance = new MockPayPalClient();\n const donation = new DonationPaymentInfo({\n donationType: DonationType.OneTime,\n amount: baseAmount,\n coverFees: true,\n });\n const datasource = new PayPalButtonDataSource({\n donationInfo: donation,\n paypalInstance: paypalInstance,\n });\n datasource.delegate = delegate;\n await datasource.payment();\n expect(delegate.paymentStartedResults.options).to.deep.equal({\n flow: 'checkout',\n enableShippingAddress: true,\n amount: expectedTotal,\n currency: 'USD',\n });\n });\n\n it('sends the proper monthly donation request', async () => {\n const delegate = new MockPayPalButtonDataSourceDelegate();\n const paypalInstance = new MockPayPalClient();\n const donation = new DonationPaymentInfo({\n donationType: DonationType.Monthly,\n amount: 1.5,\n coverFees: false,\n });\n const datasource = new PayPalButtonDataSource({\n donationInfo: donation,\n paypalInstance: paypalInstance,\n });\n datasource.delegate = delegate;\n await datasource.payment();\n expect(delegate.paymentStartedResults.options).to.deep.equal({\n flow: 'vault',\n enableShippingAddress: true,\n billingAgreementDescription: 'Subscribe to donate $1.50 monthly',\n });\n });\n });\n\n describe('Payment authorized', () => {\n it('it tokenizes the payment and notifies the delegate when the payment is authorized', async () => {\n const delegate = new MockPayPalButtonDataSourceDelegate();\n const paypalInstance = new MockPayPalClient();\n const donation = new DonationPaymentInfo({\n donationType: DonationType.OneTime,\n amount: 3.5,\n coverFees: false,\n });\n const datasource = new PayPalButtonDataSource({\n donationInfo: donation,\n paypalInstance: paypalInstance,\n });\n\n const authData: paypal.AuthorizationData = {\n payerId: 'foo',\n paymentId: '1234',\n };\n\n datasource.delegate = delegate;\n\n const result = await datasource.onAuthorize(authData);\n\n expect(delegate.paymentAuthorizedResults.called).to.be.true;\n expect(delegate.paymentAuthorizedResults.payload?.nonce).to.equal('foo-nonce');\n\n expect(result.nonce).to.equal('foo-nonce');\n expect(result.type).to.equal('foo-type');\n });\n });\n\n describe('Payment cancelled', () => {\n it('it notifies the delegate when the payment is cancelled', async () => {\n const delegate = new MockPayPalButtonDataSourceDelegate();\n const paypalInstance = new MockPayPalClient();\n const donation = new DonationPaymentInfo({\n donationType: DonationType.OneTime,\n amount: 3.5,\n coverFees: false,\n });\n const datasource = new PayPalButtonDataSource({\n donationInfo: donation,\n paypalInstance: paypalInstance,\n });\n\n const cancelData = {\n foo: 'bar',\n };\n\n datasource.delegate = delegate;\n\n datasource.onCancel(cancelData);\n\n expect(delegate.paymentCancelledResults.called).to.be.true;\n expect(delegate.paymentCancelledResults.data).to.deep.equal(cancelData);\n });\n });\n\n describe('Payment error', () => {\n it('it notifies the delegate when there has been a payment error', async () => {\n const delegate = new MockPayPalButtonDataSourceDelegate();\n const paypalInstance = new MockPayPalClient();\n const donation = new DonationPaymentInfo({\n donationType: DonationType.OneTime,\n amount: 3.5,\n coverFees: false,\n });\n const datasource = new PayPalButtonDataSource({\n donationInfo: donation,\n paypalInstance: paypalInstance,\n });\n\n const error = 'foo-error';\n\n datasource.delegate = delegate;\n\n datasource.onError(error);\n\n expect(delegate.paymentErrorResults.called).to.be.true;\n expect(delegate.paymentErrorResults.error).to.equal(error);\n });\n });\n});\n"]}
1
+ {"version":3,"file":"paypal-button-datasource.test.js","sourceRoot":"","sources":["../../../../test/tests/payment-providers/paypal-button-datasource.test.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gDAAgD,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAC/F,OAAO,EAAE,sBAAsB,EAAE,MAAM,kFAAkF,CAAC;AAC1H,OAAO,EAAE,kCAAkC,EAAE,MAAM,2FAA2F,CAAC;AAE/I,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;QAC7B,EAAE,CAAC,8GAA8G,EAAE,GAAS,EAAE;YAC5H,MAAM,QAAQ,GAAG,IAAI,kCAAkC,EAAE,CAAC;YAC1D,MAAM,cAAc,GAAG,IAAI,gBAAgB,EAAE,CAAC;YAC9C,MAAM,QAAQ,GAAG,IAAI,mBAAmB,CAAC;gBACvC,YAAY,EAAE,YAAY,CAAC,OAAO;gBAClC,MAAM,EAAE,GAAG;gBACX,SAAS,EAAE,KAAK;aACjB,CAAC,CAAC;YACH,MAAM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e,EAAE,GAAG,EAAE;QAC7B,EAAE,CAAC,8DAA8D,EAAE,GAAS,EAAE;YAC5E,MAAM,QAAQ,GAAG,IAAI,kCAAkC,EAAE,CAAC;YAC1D,MAAM,cAAc,GAAG,IAAI,gBAAgB,EAAE,CAAC;YAC9C,MAAM,QAAQ,GAAG,IAAI,mBAAmB,CAAC;gBACvC,YAAY,EAAE,YAAY,CAAC,OAAO;gBAClC,MAAM,EAAE,GAAG;gBACX,SAAS,EAAE,KAAK;aACjB,CAAC,CAAC;YACH,MAAM,UAAU,GAAG,IAAI,sBAAsB,CAAC;gBAC5C,YAAY,EAAE,QAAQ;gBACtB,cAAc,EAAE,cAAc;aAC/B,CAAC,CAAC;YAEH,MAAM,KAAK,GAAG,WAAW,CAAC;YAE1B,UAAU,CAAC,QAAQ,GAAG,QAAQ,CAAC;YAE/B,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAE1B,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;YACvD,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC7D,CAAC,CAAA,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { expect } from '@open-wc/testing';\nimport { MockPayPalClient } from '../../mocks/payment-clients/mock-paypal-client';\nimport { DonationPaymentInfo, DonationType } from '@internetarchive/donation-form-data-models';\nimport { PayPalButtonDataSource } from '../../../src/braintree-manager/payment-providers/paypal/paypal-button-datasource';\nimport { MockPayPalButtonDataSourceDelegate } from '../../mocks/payment-providers/individual-providers/mock-paypal-button-datasource-delegate';\n\ndescribe('PayPalButtonDataSource', () => {\n describe('Payment start', () => {\n it('notifies the delegate and creates the payment when the `payment()` callback is triggered from a button press', async () => {\n const delegate = new MockPayPalButtonDataSourceDelegate();\n const paypalInstance = new MockPayPalClient();\n const donation = new DonationPaymentInfo({\n donationType: DonationType.Monthly,\n amount: 3.5,\n coverFees: false,\n });\n const datasource = new PayPalButtonDataSource({\n donationInfo: donation,\n paypalInstance: paypalInstance,\n });\n\n datasource.delegate = delegate;\n\n const result = await datasource.payment();\n\n expect(delegate.paymentStartedResults.called).to.be.true;\n expect(result).to.equal('createPaymentCalled');\n });\n\n it('sends the proper one-time donation request', async () => {\n const delegate = new MockPayPalButtonDataSourceDelegate();\n const paypalInstance = new MockPayPalClient();\n const donation = new DonationPaymentInfo({\n donationType: DonationType.OneTime,\n amount: 3.5,\n coverFees: false,\n });\n const datasource = new PayPalButtonDataSource({\n donationInfo: donation,\n paypalInstance: paypalInstance,\n });\n datasource.delegate = delegate;\n await datasource.payment();\n expect(delegate.paymentStartedResults.options).to.deep.equal({\n flow: 'checkout',\n enableShippingAddress: true,\n amount: 3.5,\n currency: 'USD',\n intent: 'capture',\n });\n });\n\n it('sends the proper one-time donation request with fees covered', async () => {\n const baseAmount = 3.5;\n const expectedTotal = DonationPaymentInfo.calculateTotal(baseAmount, true);\n const delegate = new MockPayPalButtonDataSourceDelegate();\n const paypalInstance = new MockPayPalClient();\n const donation = new DonationPaymentInfo({\n donationType: DonationType.OneTime,\n amount: baseAmount,\n coverFees: true,\n });\n const datasource = new PayPalButtonDataSource({\n donationInfo: donation,\n paypalInstance: paypalInstance,\n });\n datasource.delegate = delegate;\n await datasource.payment();\n expect(delegate.paymentStartedResults.options).to.deep.equal({\n flow: 'checkout',\n enableShippingAddress: true,\n amount: expectedTotal,\n currency: 'USD',\n intent: 'capture',\n });\n });\n\n it('sends the proper monthly donation request', async () => {\n const delegate = new MockPayPalButtonDataSourceDelegate();\n const paypalInstance = new MockPayPalClient();\n const donation = new DonationPaymentInfo({\n donationType: DonationType.Monthly,\n amount: 1.5,\n coverFees: false,\n });\n const datasource = new PayPalButtonDataSource({\n donationInfo: donation,\n paypalInstance: paypalInstance,\n });\n datasource.delegate = delegate;\n await datasource.payment();\n expect(delegate.paymentStartedResults.options).to.deep.equal({\n flow: 'vault',\n enableShippingAddress: true,\n billingAgreementDescription: 'Subscribe to donate $1.50 monthly',\n intent: 'capture',\n });\n });\n });\n\n describe('Payment authorized', () => {\n it('it tokenizes the payment and notifies the delegate when the payment is authorized', async () => {\n const delegate = new MockPayPalButtonDataSourceDelegate();\n const paypalInstance = new MockPayPalClient();\n const donation = new DonationPaymentInfo({\n donationType: DonationType.OneTime,\n amount: 3.5,\n coverFees: false,\n });\n const datasource = new PayPalButtonDataSource({\n donationInfo: donation,\n paypalInstance: paypalInstance,\n });\n\n const authData: paypal.AuthorizationData = {\n payerId: 'foo',\n paymentId: '1234',\n };\n\n datasource.delegate = delegate;\n\n const result = await datasource.onAuthorize(authData);\n\n expect(delegate.paymentAuthorizedResults.called).to.be.true;\n expect(delegate.paymentAuthorizedResults.payload?.nonce).to.equal('foo-nonce');\n\n expect(result.nonce).to.equal('foo-nonce');\n expect(result.type).to.equal('foo-type');\n });\n });\n\n describe('Payment cancelled', () => {\n it('it notifies the delegate when the payment is cancelled', async () => {\n const delegate = new MockPayPalButtonDataSourceDelegate();\n const paypalInstance = new MockPayPalClient();\n const donation = new DonationPaymentInfo({\n donationType: DonationType.OneTime,\n amount: 3.5,\n coverFees: false,\n });\n const datasource = new PayPalButtonDataSource({\n donationInfo: donation,\n paypalInstance: paypalInstance,\n });\n\n const cancelData = {\n foo: 'bar',\n };\n\n datasource.delegate = delegate;\n\n datasource.onCancel(cancelData);\n\n expect(delegate.paymentCancelledResults.called).to.be.true;\n expect(delegate.paymentCancelledResults.data).to.deep.equal(cancelData);\n });\n });\n\n describe('Payment error', () => {\n it('it notifies the delegate when there has been a payment error', async () => {\n const delegate = new MockPayPalButtonDataSourceDelegate();\n const paypalInstance = new MockPayPalClient();\n const donation = new DonationPaymentInfo({\n donationType: DonationType.OneTime,\n amount: 3.5,\n coverFees: false,\n });\n const datasource = new PayPalButtonDataSource({\n donationInfo: donation,\n paypalInstance: paypalInstance,\n });\n\n const error = 'foo-error';\n\n datasource.delegate = delegate;\n\n datasource.onError(error);\n\n expect(delegate.paymentErrorResults.called).to.be.true;\n expect(delegate.paymentErrorResults.error).to.equal(error);\n });\n });\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/donation-form",
3
- "version": "0.5.12-a1",
3
+ "version": "0.5.12-a4",
4
4
  "description": "The Internet Archive Donation Form",
5
5
  "license": "AGPL-3.0-only",
6
6
  "main": "dist/index.js",
@@ -396,6 +396,7 @@ export class DonationFormController extends LitElement {
396
396
  @donationInfoChanged=${this.donationInfoChanged}
397
397
  @paymentProviderSelected=${this.paymentProviderSelected}
398
398
  @paymentFlowStarted=${this.paymentFlowStarted}
399
+ @paymentFlowConfirmed=${this.paymentFlowConfirmed}
399
400
  @paymentFlowCancelled=${this.paymentFlowCancelled}
400
401
  @paymentFlowError=${this.paymentFlowError}
401
402
  >
@@ -479,6 +480,12 @@ export class DonationFormController extends LitElement {
479
480
  this.logEvent(eventName, previousProviderInfo);
480
481
  }
481
482
 
483
+ private paymentFlowConfirmed(e: CustomEvent): void {
484
+ const selectedProvider = e.detail.paymentProvider as PaymentProvider;
485
+ const providerNoSpaces = this.removeSpaces(selectedProvider);
486
+ this.logEvent('PaymentFlowConfirmed', providerNoSpaces);
487
+ }
488
+
482
489
  private paymentFlowStarted(e: CustomEvent): void {
483
490
  const selectedProvider = e.detail.paymentProvider as PaymentProvider;
484
491
  const providerNoSpaces = this.removeSpaces(selectedProvider);
@@ -372,6 +372,16 @@ export class DonationForm extends LitElement {
372
372
  this.dispatchEvent(event);
373
373
  }
374
374
 
375
+ private emitPaymentFlowConfirmedEvent(): void {
376
+ if (!this.selectedPaymentProvider) {
377
+ return;
378
+ }
379
+ const event = new CustomEvent('paymentFlowConfirmed', {
380
+ detail: { paymentProvider: this.selectedPaymentProvider },
381
+ });
382
+ this.dispatchEvent(event);
383
+ }
384
+
375
385
  private emitPaymentFlowCancelledEvent(): void {
376
386
  if (!this.selectedPaymentProvider) {
377
387
  return;
@@ -462,6 +472,10 @@ export class DonationForm extends LitElement {
462
472
  this.selectedPaymentProvider = PaymentProvider.PayPal;
463
473
  this.emitPaymentFlowStartedEvent();
464
474
  });
475
+ this.paymentFlowHandlers?.paypalHandler?.on('payPalPaymentConfirmed', () => {
476
+ this.selectedPaymentProvider = PaymentProvider.PayPal;
477
+ this.emitPaymentFlowConfirmedEvent();
478
+ });
465
479
  this.paymentFlowHandlers?.paypalHandler?.on('payPalPaymentCancelled', () => {
466
480
  this.selectedPaymentProvider = PaymentProvider.PayPal;
467
481
  this.emitPaymentFlowCancelledEvent();
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-empty-function */
2
- import { LitElement, html, TemplateResult, css, CSSResultGroup } from 'lit';
2
+ import { LitElement, html, TemplateResult, css, CSSResultGroup, nothing } from 'lit';
3
3
  import { customElement, property } from 'lit/decorators.js';
4
4
  import { DonationType } from '@internetarchive/donation-form-data-models';
5
5
  import currency from 'currency.js';
@@ -28,8 +28,14 @@ export class ConfirmDonationContent extends LitElement {
28
28
 
29
29
  get confirmationText(): TemplateResult {
30
30
  const amount = currency(this.amount, { symbol: this.currencySymbol }).format();
31
+ return html`
32
+ <p>You are about to make a <b>${this.donationType}</b> donation of <b>${amount} ${this.currencyType}</b> to the Internet Archive.</p>
33
+ `;
34
+ }
31
35
 
32
- return html`<p>You are about to make a <b>${this.donationType}</b> donation of <b>${amount} ${this.currencyType}</b> to the Internet Archive.</p>`;
36
+ get confirmUpsellText(): TemplateResult {
37
+ const amount = currency(this.amount, { symbol: this.currencySymbol }).format();
38
+ return html`<p>You are about to begin making <b>monthly</b> donations of <b>${amount} ${this.currencyType}</b> to the Internet Archive. (Your first recurring contribution will be next month.)</p>`;
33
39
  }
34
40
 
35
41
  confirm(): void {
@@ -40,13 +46,17 @@ export class ConfirmDonationContent extends LitElement {
40
46
  this?.cancelDonation();
41
47
  }
42
48
 
49
+ get confirmCTA(): string {
50
+ return this.donationType === DonationType.Upsell ? 'Start monthly donation' : 'Complete donation';
51
+ }
52
+
43
53
  /** @inheritdoc */
44
54
  render(): TemplateResult {
45
55
  return html`
46
- <p>${this.confirmationText}</p>
56
+ ${this.donationType === DonationType.Upsell ? this.confirmUpsellText : this.confirmationText}
47
57
 
48
58
  <div class="cta-group">
49
- <button id="confirm" @click=${(): void => this.confirm()}>Complete donation</button>
59
+ <button id="confirm" @click=${(): void => this.confirm()}>${this.confirmCTA}</button>
50
60
  <button id="cancel" @click=${(): void => this.cancel()}>Cancel</button>
51
61
  </div>
52
62
  `;
@@ -228,20 +228,19 @@ export class DonationFlowModalManager implements DonationFlowModalManagerInterfa
228
228
  cancelDonationCB: Function;
229
229
  }): Promise<void> {
230
230
  const confirmDonation = (): void => {
231
- console.log('confirmDonation ~~~~~~~');
232
231
  options?.confirmDonationCB();
233
232
  };
234
233
  const cancelDonation = (): void => {
235
- console.log('cancelDonation ~~~~~~~');
236
234
  options?.cancelDonationCB();
237
235
  };
236
+ const modalTitle = options.donationType === DonationType.Upsell
237
+ ? 'Confirm monthly donation'
238
+ : 'Complete donation';
239
+
238
240
  const modalConfig = new ModalConfig({
239
241
  closeOnBackdropClick: false,
240
- // call close callback
241
242
  headerColor: ModalHeaderColor.Green,
242
- title: html`
243
- Confirm donation
244
- `,
243
+ title: html`${modalTitle}`,
245
244
  message: html`
246
245
  <confirm-donation-modal
247
246
  .amount="${options.amount}"
@@ -254,6 +253,7 @@ export class DonationFlowModalManager implements DonationFlowModalManagerInterfa
254
253
  });
255
254
  return this.modalManager.showModal({
256
255
  config: modalConfig,
256
+ userClosedModalCallback: cancelDonation
257
257
  });
258
258
  }
259
259
 
@@ -57,6 +57,7 @@ export interface PayPalFlowHandlerEvents {
57
57
  payPalPaymentStarted: (dataSource: PayPalButtonDataSourceInterface, options: object) => void;
58
58
  payPalPaymentCancelled: (dataSource: PayPalButtonDataSourceInterface, data: object) => void;
59
59
  payPalPaymentError: (dataSource: PayPalButtonDataSourceInterface, error: string) => void;
60
+ payPalPaymentConfirmed: (dataSource: PayPalButtonDataSourceInterface, data: object) => void;
60
61
  }
61
62
 
62
63
  /**
@@ -112,23 +113,21 @@ export class PayPalFlowHandler
112
113
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
113
114
  options: object,
114
115
  ): Promise<void> {
115
- console.log('payPalPaymentStarted *******', { dataSource, options });
116
116
  this.emitter.emit('payPalPaymentStarted', dataSource, options);
117
117
  }
118
118
 
119
+ /**
120
+ * Once we have the dataSource & payload, we ask patron to confirm donation.
121
+ * Once confirmed, we move forward to: `payPalPaymentConfirmed`
122
+ */
119
123
  async payPalPaymentAuthorized(dataSource: PayPalButtonDataSourceInterface,
120
124
  payload: paypal.TokenizePayload
121
125
  ): Promise<void> {
122
126
 
123
- // we got dataSource & payload
124
- // we need to send it to `payPalPaymentConfirmed`
125
- // after patron confirms the payment
126
- console.log('payPalPaymentAuthorized *******', { dataSource, payload });
127
-
128
- const { donationType, amount } = dataSource.donationInfo;
127
+ const { donationType, total } = dataSource.donationInfo;
129
128
  this.donationFlowModalManager.showConfirmationStepModal({
130
129
  donationType,
131
- amount,
130
+ amount: total,
132
131
  currencyType: 'USD', // defaults to USD for now
133
132
  confirmDonationCB: () => {
134
133
  this.payPalPaymentConfirmed(dataSource, payload);
@@ -138,10 +137,6 @@ export class PayPalFlowHandler
138
137
  this.payPalPaymentCancelled(dataSource, {});
139
138
  }
140
139
  });
141
-
142
- // cancel payment on modal X
143
- // cancel payment on cancel
144
-
145
140
  }
146
141
 
147
142
  async payPalPaymentConfirmed(
@@ -1,23 +0,0 @@
1
- import { LitElement, TemplateResult } from 'lit';
2
- import { DonationType } from '@internetarchive/donation-form-data-models';
3
- /**
4
- * This is the content that we show in the upsell modal.
5
- *
6
- * It has an amount input, "Yes" and "No Thanks" options and a switch to optionally
7
- * show the PayPal upsell button.
8
- *
9
- * @export
10
- * @class PaymentConfirmationContent
11
- * @extends {LitElement}
12
- */
13
- export declare class PaymentConfirmationContent extends LitElement {
14
- amount: number;
15
- currencyType: string;
16
- donationType: DonationType;
17
- get confirmationText(): string;
18
- get currencySymbol(): string;
19
- donationConfirmed(e: Event): void;
20
- donationCancelled(e: Event): void;
21
- /** @inheritdoc */
22
- render(): TemplateResult;
23
- }
@@ -1,74 +0,0 @@
1
- import { __decorate } from "tslib";
2
- import { LitElement, html } from 'lit';
3
- import { customElement, property } from 'lit/decorators.js';
4
- import { DonationType } from '@internetarchive/donation-form-data-models';
5
- /**
6
- * This is the content that we show in the upsell modal.
7
- *
8
- * It has an amount input, "Yes" and "No Thanks" options and a switch to optionally
9
- * show the PayPal upsell button.
10
- *
11
- * @export
12
- * @class PaymentConfirmationContent
13
- * @extends {LitElement}
14
- */
15
- let PaymentConfirmationContent = class PaymentConfirmationContent extends LitElement {
16
- constructor() {
17
- super(...arguments);
18
- this.amount = 5;
19
- this.currencyType = '$';
20
- this.donationType = DonationType.OneTime;
21
- }
22
- get confirmationText() {
23
- return `You are about to make a ${this.donationType} donation of ${this.currencySymbol}${this.amount}${this.currencyType} to the Internet Archive`;
24
- }
25
- get currencySymbol() {
26
- switch (this.currencyType) {
27
- case 'USD':
28
- return '$';
29
- case 'EUR':
30
- return '€';
31
- case 'GBP':
32
- return '£';
33
- case 'JPY':
34
- return '¥';
35
- case 'CAD':
36
- return '$';
37
- case 'AUD':
38
- return '$';
39
- case 'NZD':
40
- return '$';
41
- default:
42
- return '$';
43
- }
44
- }
45
- donationConfirmed(e) {
46
- console.log('donationConfirmed --- ', e);
47
- }
48
- donationCancelled(e) {
49
- console.log('donationCancelled --- ', e);
50
- }
51
- /** @inheritdoc */
52
- render() {
53
- return html `
54
- <h3>Confirm:</h3>
55
- <p>${this.confirmationText}</p>
56
- <button @click=${(e) => this.donationConfirmed(e)}>COMPLETE DONATION</button>
57
- <button @click=${(e) => this.donationCancelled(e)}>Cancel</button>
58
- `;
59
- }
60
- };
61
- __decorate([
62
- property({ type: Number })
63
- ], PaymentConfirmationContent.prototype, "amount", void 0);
64
- __decorate([
65
- property({ type: String })
66
- ], PaymentConfirmationContent.prototype, "currencyType", void 0);
67
- __decorate([
68
- property({ type: String })
69
- ], PaymentConfirmationContent.prototype, "donationType", void 0);
70
- PaymentConfirmationContent = __decorate([
71
- customElement('payment-confirmation-modal')
72
- ], PaymentConfirmationContent);
73
- export { PaymentConfirmationContent };
74
- //# sourceMappingURL=payment-confirmation-content.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"payment-confirmation-content.js","sourceRoot":"","sources":["../../../src/modals/payment-confirmation-content.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAkB,MAAM,KAAK,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAE1E;;;;;;;;;GASG;AAEH,IAAa,0BAA0B,GAAvC,MAAa,0BAA2B,SAAQ,UAAU;IAA1D;;QAC8B,WAAM,GAAG,CAAC,CAAC;QAEX,iBAAY,GAAG,GAAG,CAAC;QAEnB,iBAAY,GAAiB,YAAY,CAAC,OAAO,CAAC;IA4ChF,CAAC;IA1CC,IAAI,gBAAgB;QAClB,OAAO,2BAA2B,IAAI,CAAC,YAAY,gBAAgB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,0BAA0B,CAAC;IACrJ,CAAC;IAED,IAAI,cAAc;QAChB,QAAO,IAAI,CAAC,YAAY,EAAE;YACxB,KAAK,KAAK;gBACR,OAAO,GAAG,CAAC;YACb,KAAK,KAAK;gBACR,OAAO,GAAG,CAAC;YACb,KAAK,KAAK;gBACR,OAAO,GAAG,CAAC;YACb,KAAK,KAAK;gBACR,OAAO,GAAG,CAAC;YACb,KAAK,KAAK;gBACR,OAAO,GAAG,CAAC;YACb,KAAK,KAAK;gBACR,OAAO,GAAG,CAAC;YACb,KAAK,KAAK;gBACR,OAAO,GAAG,CAAC;YACb;gBACE,OAAO,GAAG,CAAC;SACd;IACH,CAAC;IAED,iBAAiB,CAAC,CAAQ;QACxB,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED,iBAAiB,CAAC,CAAQ;QACxB,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED,kBAAkB;IAClB,MAAM;QACJ,OAAO,IAAI,CAAA;;WAEJ,IAAI,CAAC,gBAAgB;uBACT,CAAC,CAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC;uBACvC,CAAC,CAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC;KACzD,CAAC;IACJ,CAAC;CACF,CAAA;AAhD6B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;0DAAY;AAEX;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gEAAoB;AAEnB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gEAAmD;AALnE,0BAA0B;IADtC,aAAa,CAAC,4BAA4B,CAAC;GAC/B,0BAA0B,CAiDtC;SAjDY,0BAA0B","sourcesContent":["import { LitElement, html, TemplateResult } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { DonationType } from '@internetarchive/donation-form-data-models';\n\n/**\n * This is the content that we show in the upsell modal.\n *\n * It has an amount input, \"Yes\" and \"No Thanks\" options and a switch to optionally\n * show the PayPal upsell button.\n *\n * @export\n * @class PaymentConfirmationContent\n * @extends {LitElement}\n */\n@customElement('payment-confirmation-modal')\nexport class PaymentConfirmationContent extends LitElement {\n @property({ type: Number }) amount = 5;\n\n @property({ type: String }) currencyType = '$';\n\n @property({ type: String }) donationType: DonationType = DonationType.OneTime;\n\n get confirmationText(): string {\n return `You are about to make a ${this.donationType} donation of ${this.currencySymbol}${this.amount}${this.currencyType} to the Internet Archive`;\n }\n\n get currencySymbol(): string {\n switch(this.currencyType) {\n case 'USD':\n return '$';\n case 'EUR':\n return '€';\n case 'GBP':\n return '£';\n case 'JPY':\n return '¥';\n case 'CAD':\n return '$';\n case 'AUD':\n return '$';\n case 'NZD':\n return '$';\n default:\n return '$';\n }\n }\n\n donationConfirmed(e: Event): void {\n console.log('donationConfirmed --- ', e);\n }\n\n donationCancelled(e: Event): void {\n console.log('donationCancelled --- ', e);\n }\n\n /** @inheritdoc */\n render(): TemplateResult {\n return html`\n <h3>Confirm:</h3>\n <p>${this.confirmationText}</p>\n <button @click=${(e: Event) => this.donationConfirmed(e)}>COMPLETE DONATION</button>\n <button @click=${(e: Event) => this.donationCancelled(e)}>Cancel</button>\n `;\n }\n}"]}