@internetarchive/donation-form 0.6.2 → 0.6.3

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 (109) hide show
  1. package/dist/demo/braintree-endpoint-manager.js.map +1 -1
  2. package/dist/demo/submit-form-with.js.map +1 -1
  3. package/dist/src/braintree-manager/braintree-manager.js.map +1 -1
  4. package/dist/src/braintree-manager/payment-clients.d.ts +0 -2
  5. package/dist/src/braintree-manager/payment-clients.js +0 -1
  6. package/dist/src/braintree-manager/payment-clients.js.map +1 -1
  7. package/dist/src/braintree-manager/payment-providers/apple-pay/apple-pay-session-datasource-interface.d.ts +0 -1
  8. package/dist/src/braintree-manager/payment-providers/apple-pay/apple-pay-session-datasource.d.ts +0 -1
  9. package/dist/src/braintree-manager/payment-providers/apple-pay/apple-pay-session-datasource.js +2 -2
  10. package/dist/src/braintree-manager/payment-providers/apple-pay/apple-pay-session-datasource.js.map +1 -1
  11. package/dist/src/braintree-manager/payment-providers/apple-pay/apple-pay-session-manager.d.ts +0 -1
  12. package/dist/src/braintree-manager/payment-providers/apple-pay/apple-pay.js +0 -1
  13. package/dist/src/braintree-manager/payment-providers/apple-pay/apple-pay.js.map +1 -1
  14. package/dist/src/braintree-manager/payment-providers/credit-card/credit-card.js +2 -2
  15. package/dist/src/braintree-manager/payment-providers/credit-card/credit-card.js.map +1 -1
  16. package/dist/src/braintree-manager/payment-providers/credit-card/hosted-field-container.js.map +1 -1
  17. package/dist/src/braintree-manager/payment-providers/google-pay-interface.d.ts +0 -1
  18. package/dist/src/braintree-manager/payment-providers/google-pay.d.ts +0 -1
  19. package/dist/src/braintree-manager/payment-providers/paypal/paypal-button-datasource.js +3 -3
  20. package/dist/src/braintree-manager/payment-providers/paypal/paypal-button-datasource.js.map +1 -1
  21. package/dist/src/braintree-manager/payment-providers/paypal/paypal.js.map +1 -1
  22. package/dist/src/braintree-manager/payment-providers/venmo.js +1 -1
  23. package/dist/src/braintree-manager/payment-providers/venmo.js.map +1 -1
  24. package/dist/src/braintree-manager/payment-providers.js.map +1 -1
  25. package/dist/src/donation-form-controller.js +0 -1
  26. package/dist/src/donation-form-controller.js.map +1 -1
  27. package/dist/src/donation-form.js +18 -15
  28. package/dist/src/donation-form.js.map +1 -1
  29. package/dist/src/form-elements/badged-input.js.map +1 -1
  30. package/dist/src/form-elements/contact-form/contact-form.js.map +1 -1
  31. package/dist/src/form-elements/header/donation-form-header.js.map +1 -1
  32. package/dist/src/form-elements/header/donation-summary.js.map +1 -1
  33. package/dist/src/form-elements/payment-selector.js +1 -1
  34. package/dist/src/form-elements/payment-selector.js.map +1 -1
  35. package/dist/src/form-elements/total-amount.js.map +1 -1
  36. package/dist/src/modals/confirm-donation-modal-content.js +0 -2
  37. package/dist/src/modals/confirm-donation-modal-content.js.map +1 -1
  38. package/dist/src/modals/error-modal-content.js.map +1 -1
  39. package/dist/src/modals/upsell-modal-content.js.map +1 -1
  40. package/dist/src/payment-flow-handlers/donation-flow-modal-manager.js +0 -1
  41. package/dist/src/payment-flow-handlers/donation-flow-modal-manager.js.map +1 -1
  42. package/dist/src/payment-flow-handlers/handlers/applepay-flow-handler.js +1 -1
  43. package/dist/src/payment-flow-handlers/handlers/applepay-flow-handler.js.map +1 -1
  44. package/dist/src/payment-flow-handlers/handlers/creditcard-flow-handler.js +1 -1
  45. package/dist/src/payment-flow-handlers/handlers/creditcard-flow-handler.js.map +1 -1
  46. package/dist/src/payment-flow-handlers/handlers/googlepay-flow-handler.js +1 -1
  47. package/dist/src/payment-flow-handlers/handlers/googlepay-flow-handler.js.map +1 -1
  48. package/dist/src/payment-flow-handlers/handlers/paypal-flow-handler.js +6 -14
  49. package/dist/src/payment-flow-handlers/handlers/paypal-flow-handler.js.map +1 -1
  50. package/dist/src/payment-flow-handlers/handlers/venmo-flow-handler.js.map +1 -1
  51. package/dist/src/payment-flow-handlers/handlers/venmo-restoration-state-handler.js +1 -1
  52. package/dist/src/payment-flow-handlers/handlers/venmo-restoration-state-handler.js.map +1 -1
  53. package/dist/src/payment-flow-handlers/payment-flow-handlers.js +1 -1
  54. package/dist/src/payment-flow-handlers/payment-flow-handlers.js.map +1 -1
  55. package/dist/src/recaptcha-manager/recaptcha-manager.d.ts +0 -1
  56. package/dist/src/recaptcha-manager/recaptcha-manager.js.map +1 -1
  57. package/dist/test/mocks/flow-handlers/individual-handlers/mock-creditcard-flow-handler.js +0 -1
  58. package/dist/test/mocks/flow-handlers/individual-handlers/mock-creditcard-flow-handler.js.map +1 -1
  59. package/dist/test/mocks/flow-handlers/mock-payment-flow-handlers.js +1 -1
  60. package/dist/test/mocks/flow-handlers/mock-payment-flow-handlers.js.map +1 -1
  61. package/dist/test/mocks/mock-braintree-manager.js.map +1 -1
  62. package/dist/test/mocks/mock-lazy-loader.js.map +1 -1
  63. package/dist/test/mocks/mock-modal-manager.js +0 -1
  64. package/dist/test/mocks/mock-modal-manager.js.map +1 -1
  65. package/dist/test/mocks/mock-payment-clients.d.ts +0 -2
  66. package/dist/test/mocks/mock-payment-clients.js +0 -1
  67. package/dist/test/mocks/mock-payment-clients.js.map +1 -1
  68. package/dist/test/mocks/mock-recaptcha-manager.d.ts +0 -1
  69. package/dist/test/mocks/payment-clients/mock-applepay-client.js.map +1 -1
  70. package/dist/test/mocks/payment-clients/mock-applepay-payment.d.ts +0 -1
  71. package/dist/test/mocks/payment-clients/mock-applepay-paymentauthorizedevent.d.ts +0 -1
  72. package/dist/test/mocks/payment-clients/mock-applepay-session.d.ts +0 -1
  73. package/dist/test/mocks/payment-clients/mock-applepay-session.js +0 -2
  74. package/dist/test/mocks/payment-clients/mock-applepay-session.js.map +1 -1
  75. package/dist/test/mocks/payment-clients/mock-applepay-sessionmanager.d.ts +0 -1
  76. package/dist/test/mocks/payment-clients/mock-applepay-validatemerchantevent.d.ts +0 -1
  77. package/dist/test/mocks/payment-clients/mock-data-collector.js.map +1 -1
  78. package/dist/test/mocks/payment-clients/mock-googlepay-client.d.ts +0 -1
  79. package/dist/test/mocks/payment-clients/mock-googlepay-library.d.ts +0 -1
  80. package/dist/test/mocks/payment-clients/mock-grecaptcha.d.ts +0 -1
  81. package/dist/test/mocks/payment-clients/mock-grecaptcha.js +0 -1
  82. package/dist/test/mocks/payment-clients/mock-grecaptcha.js.map +1 -1
  83. package/dist/test/mocks/payment-clients/mock-hostedfields-client.js.map +1 -1
  84. package/dist/test/mocks/payment-clients/mock-hostedfieldtokenizepayload.d.ts +1 -1
  85. package/dist/test/mocks/payment-providers/individual-providers/mock-googlepay-handler.d.ts +0 -1
  86. package/dist/test/mocks/payment-providers/individual-providers/mock-paypal-button-datasource.js +2 -2
  87. package/dist/test/mocks/payment-providers/individual-providers/mock-paypal-button-datasource.js.map +1 -1
  88. package/dist/test/tests/braintree-manager.test.js +12 -13
  89. package/dist/test/tests/braintree-manager.test.js.map +1 -1
  90. package/dist/test/tests/donation-form-controller.test.js +21 -21
  91. package/dist/test/tests/donation-form.test.js +7 -7
  92. package/dist/test/tests/flow-handlers/donation-flow-modal-manager.test.js +8 -8
  93. package/dist/test/tests/form-elements/donation-summary.test.js +2 -2
  94. package/dist/test/tests/form-elements/payment-selector.test.js +8 -8
  95. package/dist/test/tests/modals/upsell-modal-content.test.js +21 -21
  96. package/dist/test/tests/models/donation-payment-info.test.js +7 -7
  97. package/dist/test/tests/models/donation-payment-info.test.js.map +1 -1
  98. package/dist/test/tests/payment-providers/applepay-sessiondatasource.test.js.map +1 -1
  99. package/dist/test/tests/payment-providers/creditcard.test.js.map +1 -1
  100. package/dist/test/tests/recaptcha-manager.test.js.map +1 -1
  101. package/package.json +40 -40
  102. package/src/braintree-manager/payment-clients.ts +0 -1
  103. package/src/braintree-manager/payment-providers/apple-pay/apple-pay.ts +0 -1
  104. package/src/donation-form-controller.ts +0 -1
  105. package/src/donation-form.ts +9 -6
  106. package/src/modals/confirm-donation-modal-content.ts +0 -2
  107. package/src/payment-flow-handlers/donation-flow-modal-manager.ts +0 -1
  108. package/src/payment-flow-handlers/handlers/paypal-flow-handler.ts +2 -4
  109. package/src/payment-flow-handlers/payment-flow-handlers.ts +0 -1
@@ -42,11 +42,7 @@ export class PayPalFlowHandler {
42
42
  on(event, callback) {
43
43
  return this.emitter.on(event, callback);
44
44
  }
45
- payPalPaymentStarted(
46
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
47
- dataSource,
48
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
49
- options) {
45
+ payPalPaymentStarted(dataSource, options) {
50
46
  return __awaiter(this, void 0, void 0, function* () {
51
47
  this.emitter.emit('payPalPaymentStarted', dataSource, options);
52
48
  });
@@ -61,7 +57,7 @@ export class PayPalFlowHandler {
61
57
  this.donationFlowModalManager.showConfirmationStepModal({
62
58
  donationType,
63
59
  amount: total,
64
- currencyType: 'USD',
60
+ currencyType: 'USD', // defaults to USD for now
65
61
  confirmDonationCB: () => {
66
62
  this.payPalPaymentConfirmed(dataSource, payload);
67
63
  },
@@ -136,11 +132,7 @@ export class PayPalFlowHandler {
136
132
  }
137
133
  });
138
134
  }
139
- payPalPaymentCancelled(
140
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
141
- dataSource,
142
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
143
- data) {
135
+ payPalPaymentCancelled(dataSource, data) {
144
136
  return __awaiter(this, void 0, void 0, function* () {
145
137
  this.emitter.emit('payPalPaymentCancelled', dataSource, data);
146
138
  });
@@ -152,13 +144,13 @@ export class PayPalFlowHandler {
152
144
  });
153
145
  }
154
146
  renderPayPalButton(donationInfo) {
155
- var _a;
156
147
  return __awaiter(this, void 0, void 0, function* () {
148
+ var _a;
157
149
  const handler = yield ((_a = this.braintreeManager) === null || _a === void 0 ? void 0 : _a.paymentProviders.paypalHandler.get());
158
150
  this.buttonDataSource = yield (handler === null || handler === void 0 ? void 0 : handler.renderPayPalButton({
159
151
  selector: '#paypal-button',
160
152
  style: {
161
- color: 'blue',
153
+ color: 'blue', // I'm not sure why I can't access the enum directly here.. I get a UMD error
162
154
  label: 'paypal',
163
155
  shape: 'rect',
164
156
  size: 'medium',
@@ -209,8 +201,8 @@ export class PayPalFlowHandler {
209
201
  }
210
202
  }
211
203
  renderUpsellPayPalButton(options) {
212
- var _a;
213
204
  return __awaiter(this, void 0, void 0, function* () {
205
+ var _a;
214
206
  const handler = yield ((_a = this.braintreeManager) === null || _a === void 0 ? void 0 : _a.paymentProviders.paypalHandler.get());
215
207
  const upsellButtonDataSource = yield (handler === null || handler === void 0 ? void 0 : handler.renderPayPalButton({
216
208
  selector: '#paypal-upsell-button',
@@ -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;AASD;;;;;;;GAOG;AACH,MAAM,OAAO,iBAAiB;IAa5B,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,CAAC,+BAA+B,EAAE;YACxC,IAAI,CAAC,+BAA+B,CA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I,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 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{\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(\n dataSource: PayPalButtonDataSourceInterface,\n payload: paypal.TokenizePayload,\n ): Promise<void> {\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.emitter.emit('payPalPaymentConfirmed', dataSource, {});\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;IAa5B,kBAAkB,CAAC,YAAiC;QAClD,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC1B,IAAI,CAAC,gBAAgB,CAAC,YAAY,GAAG,YAAY,CAAC;QACpD,CAAC;IACH,CAAC;IAED,wBAAwB,CAAC,YAAiC;QACxD,IAAI,IAAI,CAAC,+BAA+B,EAAE,CAAC;YACzC,IAAI,CAAC,+BAA+B,CAAC,sBAAsB,CAAC,YAAY,GAAG,YAAY,CAAC;QAC1F,CAAC;IACH,CAAC;IAED,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,CAA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,cAAc;oBACtC,sBAAsB,EAAE,OAAO,CAAC,sBAAsB;iBACvD,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;YACxD,CAAC;QACH,CAAC;KAAA;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{\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 dataSource: PayPalButtonDataSourceInterface,\n\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(\n dataSource: PayPalButtonDataSourceInterface,\n payload: paypal.TokenizePayload,\n ): Promise<void> {\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.emitter.emit('payPalPaymentConfirmed', dataSource, {});\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 dataSource: PayPalButtonDataSourceInterface,\n\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 +1 @@
1
- {"version":3,"file":"venmo-flow-handler.js","sourceRoot":"","sources":["../../../../src/payment-flow-handlers/handlers/venmo-flow-handler.ts"],"names":[],"mappings":";AACA,OAAO,EAGL,eAAe,GAChB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAEL,4BAA4B,GAC7B,MAAM,mCAAmC,CAAC;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aAAa,CAAC,CAAC;SAC1C;IACH,CAAC;CACF","sourcesContent":["import { BraintreeManagerInterface } from '../../braintree-manager/braintree-interfaces';\nimport {\n DonorContactInfo,\n DonationPaymentInfo,\n PaymentProvider,\n} from '@internetarchive/donation-form-data-models';\nimport {\n VenmoRestorationStateHandlerInterface,\n VenmoRestorationStateHandler,\n} from './venmo-restoration-state-handler';\nimport { DonationFlowModalManagerInterface } from '../donation-flow-modal-manager';\nimport { BraintreeError } from '../../@types/braintree-web';\n\nexport interface VenmoFlowHandlerInterface {\n startup(): Promise<void>;\n paymentInitiated(contactInfo: DonorContactInfo, donationInfo: DonationPaymentInfo): Promise<void>;\n}\n\nexport class VenmoFlowHandler implements VenmoFlowHandlerInterface {\n private donationFlowModalManager: DonationFlowModalManagerInterface;\n\n private braintreeManager: BraintreeManagerInterface;\n\n private restorationStateHandler: VenmoRestorationStateHandlerInterface;\n\n constructor(options: {\n braintreeManager: BraintreeManagerInterface;\n donationFlowModalManager: DonationFlowModalManagerInterface;\n restorationStateHandler?: VenmoRestorationStateHandlerInterface;\n }) {\n this.braintreeManager = options.braintreeManager;\n this.donationFlowModalManager = options.donationFlowModalManager;\n this.restorationStateHandler =\n options.restorationStateHandler ?? new VenmoRestorationStateHandler();\n }\n\n /**\n * Check if we have any results from Venmo on startup.\n *\n * This happens if the app redirects to us in a new tab so we can resume the session.\n *\n * @returns {Promise<void>}\n * @memberof VenmoFlowHandler\n */\n async startup(): Promise<void> {\n const handler = await this.braintreeManager.paymentProviders.venmoHandler.get();\n const instance = await handler?.instance.get();\n if (instance?.hasTokenizationResult()) {\n // if we get redirected back from venmo in a different tab, we need to restore the data\n // that was persisted when the payment was initiated\n const restoredInfo = await this.restorationStateHandler.getRestorationState();\n if (restoredInfo) {\n this.paymentInitiated(restoredInfo.contactInfo, restoredInfo.donationInfo);\n } else {\n console.error('no restoration info');\n this.donationFlowModalManager.showErrorModal({\n message: 'Error restoring donation session',\n });\n }\n }\n }\n\n // VenmoFlowHandlerInterface conformance\n async paymentInitiated(\n contactInfo: DonorContactInfo,\n donationInfo: DonationPaymentInfo,\n ): Promise<void> {\n // if we get redirected back from venmo in a different tab, we need to restore the data\n // that was persisted when the payment was initiated so persist it here\n this.restorationStateHandler.persistState(contactInfo, donationInfo);\n\n try {\n const handler = await this.braintreeManager.paymentProviders.venmoHandler.get();\n const result = await handler?.startPayment();\n if (!result) {\n this.restorationStateHandler.clearState();\n this.donationFlowModalManager.showErrorModal({\n message: 'Error setting up the donation',\n });\n return;\n }\n this.handleTokenizationResult(result, contactInfo, donationInfo);\n } catch (tokenizeError) {\n this.restorationStateHandler.clearState();\n this.handleTokenizationError(tokenizeError as BraintreeError);\n this.donationFlowModalManager.showErrorModal({\n message: `There was a problem loading your donation information. Please try again.`,\n });\n }\n }\n\n private async handleTokenizationResult(\n payload: braintree.VenmoTokenizePayload,\n contactInfo: DonorContactInfo,\n donationInfo: DonationPaymentInfo,\n ): Promise<void> {\n this.restorationStateHandler.clearState();\n\n this.donationFlowModalManager.startDonationSubmissionFlow({\n nonce: payload.nonce,\n paymentProvider: PaymentProvider.Venmo,\n donationInfo: donationInfo,\n customerInfo: contactInfo.customer,\n billingInfo: contactInfo.billing,\n });\n }\n\n private handleTokenizationError(tokenizeError: braintree.BraintreeError): void {\n // Handle flow errors or premature flow closure\n switch (tokenizeError.code) {\n case 'VENMO_APP_CANCELED':\n break;\n case 'VENMO_CANCELED':\n break;\n default:\n console.error('Error!', tokenizeError);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"venmo-flow-handler.js","sourceRoot":"","sources":["../../../../src/payment-flow-handlers/handlers/venmo-flow-handler.ts"],"names":[],"mappings":";AACA,OAAO,EAGL,eAAe,GAChB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAEL,4BAA4B,GAC7B,MAAM,mCAAmC,CAAC;AAS3C,MAAM,OAAO,gBAAgB;IAO3B,YAAY,OAIX;;QACC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CA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CAAC;IACH,CAAC;CACF","sourcesContent":["import { BraintreeManagerInterface } from '../../braintree-manager/braintree-interfaces';\nimport {\n DonorContactInfo,\n DonationPaymentInfo,\n PaymentProvider,\n} from '@internetarchive/donation-form-data-models';\nimport {\n VenmoRestorationStateHandlerInterface,\n VenmoRestorationStateHandler,\n} from './venmo-restoration-state-handler';\nimport { DonationFlowModalManagerInterface } from '../donation-flow-modal-manager';\nimport { BraintreeError } from '../../@types/braintree-web';\n\nexport interface VenmoFlowHandlerInterface {\n startup(): Promise<void>;\n paymentInitiated(contactInfo: DonorContactInfo, donationInfo: DonationPaymentInfo): Promise<void>;\n}\n\nexport class VenmoFlowHandler implements VenmoFlowHandlerInterface {\n private donationFlowModalManager: DonationFlowModalManagerInterface;\n\n private braintreeManager: BraintreeManagerInterface;\n\n private restorationStateHandler: VenmoRestorationStateHandlerInterface;\n\n constructor(options: {\n braintreeManager: BraintreeManagerInterface;\n donationFlowModalManager: DonationFlowModalManagerInterface;\n restorationStateHandler?: VenmoRestorationStateHandlerInterface;\n }) {\n this.braintreeManager = options.braintreeManager;\n this.donationFlowModalManager = options.donationFlowModalManager;\n this.restorationStateHandler =\n options.restorationStateHandler ?? new VenmoRestorationStateHandler();\n }\n\n /**\n * Check if we have any results from Venmo on startup.\n *\n * This happens if the app redirects to us in a new tab so we can resume the session.\n *\n * @returns {Promise<void>}\n * @memberof VenmoFlowHandler\n */\n async startup(): Promise<void> {\n const handler = await this.braintreeManager.paymentProviders.venmoHandler.get();\n const instance = await handler?.instance.get();\n if (instance?.hasTokenizationResult()) {\n // if we get redirected back from venmo in a different tab, we need to restore the data\n // that was persisted when the payment was initiated\n const restoredInfo = await this.restorationStateHandler.getRestorationState();\n if (restoredInfo) {\n this.paymentInitiated(restoredInfo.contactInfo, restoredInfo.donationInfo);\n } else {\n console.error('no restoration info');\n this.donationFlowModalManager.showErrorModal({\n message: 'Error restoring donation session',\n });\n }\n }\n }\n\n // VenmoFlowHandlerInterface conformance\n async paymentInitiated(\n contactInfo: DonorContactInfo,\n donationInfo: DonationPaymentInfo,\n ): Promise<void> {\n // if we get redirected back from venmo in a different tab, we need to restore the data\n // that was persisted when the payment was initiated so persist it here\n this.restorationStateHandler.persistState(contactInfo, donationInfo);\n\n try {\n const handler = await this.braintreeManager.paymentProviders.venmoHandler.get();\n const result = await handler?.startPayment();\n if (!result) {\n this.restorationStateHandler.clearState();\n this.donationFlowModalManager.showErrorModal({\n message: 'Error setting up the donation',\n });\n return;\n }\n this.handleTokenizationResult(result, contactInfo, donationInfo);\n } catch (tokenizeError) {\n this.restorationStateHandler.clearState();\n this.handleTokenizationError(tokenizeError as BraintreeError);\n this.donationFlowModalManager.showErrorModal({\n message: `There was a problem loading your donation information. Please try again.`,\n });\n }\n }\n\n private async handleTokenizationResult(\n payload: braintree.VenmoTokenizePayload,\n contactInfo: DonorContactInfo,\n donationInfo: DonationPaymentInfo,\n ): Promise<void> {\n this.restorationStateHandler.clearState();\n\n this.donationFlowModalManager.startDonationSubmissionFlow({\n nonce: payload.nonce,\n paymentProvider: PaymentProvider.Venmo,\n donationInfo: donationInfo,\n customerInfo: contactInfo.customer,\n billingInfo: contactInfo.billing,\n });\n }\n\n private handleTokenizationError(tokenizeError: braintree.BraintreeError): void {\n // Handle flow errors or premature flow closure\n switch (tokenizeError.code) {\n case 'VENMO_APP_CANCELED':\n break;\n case 'VENMO_CANCELED':\n break;\n default:\n console.error('Error!', tokenizeError);\n }\n }\n}\n"]}
@@ -57,8 +57,8 @@ export class VenmoRestorationStateHandler {
57
57
  }
58
58
  /** @inheritdoc */
59
59
  getRestorationState() {
60
- var _a;
61
60
  return __awaiter(this, void 0, void 0, function* () {
61
+ var _a;
62
62
  const stored = (_a = this.storageSystem) === null || _a === void 0 ? void 0 : _a.getItem(this.persistanceKey);
63
63
  if (!stored) {
64
64
  console.error('restoreState: No stored data');
@@ -1 +1 @@
1
- {"version":3,"file":"venmo-restoration-state-handler.js","sourceRoot":"","sources":["../../../../src/payment-flow-handlers/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C,cAAc,CAAC,CAAC;YAChE,IAAI,CAAC,MAAM,EAAE;gBACX,OAAO,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;gBAC9C,OAAO,SAAS,CAAC;aAClB;YAED,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YACxC,IAAI,CAAC,YAAY,EAAE;gBACjB,OAAO,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;gBAC9D,OAAO,SAAS,CAAC;aAClB;YAED,MAAM,YAAY,GAAG,IAAI,qBAAqB,CAAC,YAAY,CAAC,CAAC;YAE7D,OAAO,YAAY,CAAC;;KACrB;IAED;;;;;;;OAOG;IACK,sBAAsB,CAAC,MAAe;QAC5C,IAAI;YACF,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAC7B,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YACzB,OAAO,IAAI,CAAC;SACb;QAAC,OAAO,SAAS,EAAE;YAClB,OAAO,KAAK,CAAC;SACd;IACH,CAAC;CACF","sourcesContent":["import { DonorContactInfo, DonationPaymentInfo } from '@internetarchive/donation-form-data-models';\n\nexport interface VenmoRestorationStateHandlerInterface {\n /**\n * Persist the session state\n *\n * @param {DonorContactInfo} contactInfo\n * @param {DonationPaymentInfo} donationInfo\n * @memberof VenmoRestorationStateHandlerInterface\n */\n persistState(contactInfo: DonorContactInfo, donationInfo: DonationPaymentInfo): void;\n\n /**\n * Get the session restoration state\n *\n * @returns {(Promise<VenmoRestorationState | undefined>)}\n * @memberof VenmoRestorationStateHandlerInterface\n */\n getRestorationState(): Promise<VenmoRestorationState | undefined>;\n\n /**\n * Clear the restoration state\n *\n * @memberof VenmoRestorationStateHandlerInterface\n */\n clearState(): void;\n}\n\n/**\n * Structure to store the session restoration state\n *\n * @export\n * @class VenmoRestorationState\n */\nexport class VenmoRestorationState {\n contactInfo: DonorContactInfo;\n donationInfo: DonationPaymentInfo;\n\n // TODO: Add restoration state expiration\n constructor(params: { contactInfo: DonorContactInfo; donationInfo: DonationPaymentInfo }) {\n this.contactInfo = params.contactInfo;\n this.donationInfo = params.donationInfo;\n }\n}\n\n/**\n * The VenmoRestorationStateHandler is used to persist and restore a Venmo checkout session.\n *\n * Venmo takes the user out of the web browser and into their app to authorize the purchase.\n * It then redirects the user back to the website to finish the transaction. The problem is\n * it may open a new browser tab so it's like starting a new session. We need to persist\n * the session information from the start of the Venmo session and restore it when it resumes.\n *\n * This class stores the session information in localStorage when the Venmo session is started\n * and retrieves it when the session is restored.\n *\n * @export\n * @class VenmoRestorationStateHandler\n * @implements {VenmoRestorationStateHandlerInterface}\n */\nexport class VenmoRestorationStateHandler implements VenmoRestorationStateHandlerInterface {\n private persistanceKey = 'venmoRestorationStateInfo';\n\n private storageSystem?: Storage;\n\n constructor(options?: { storageSystem?: Storage }) {\n if (options?.storageSystem) {\n this.storageSystem = options.storageSystem;\n } else if (this.storageSystemAvailable(localStorage)) {\n this.storageSystem = localStorage;\n } else if (this.storageSystemAvailable(sessionStorage)) {\n this.storageSystem = sessionStorage;\n }\n }\n\n /** @inheritdoc */\n clearState(): void {\n this.storageSystem?.removeItem(this.persistanceKey);\n }\n\n /** @inheritdoc */\n persistState(contactInfo: DonorContactInfo, donationInfo: DonationPaymentInfo): void {\n const venmoRestoration = new VenmoRestorationState({\n contactInfo,\n donationInfo,\n });\n const serialized = JSON.stringify(venmoRestoration);\n this.storageSystem?.setItem(this.persistanceKey, serialized);\n }\n\n /** @inheritdoc */\n async getRestorationState(): Promise<VenmoRestorationState | undefined> {\n const stored = this.storageSystem?.getItem(this.persistanceKey);\n if (!stored) {\n console.error('restoreState: No stored data');\n return undefined;\n }\n\n const deserialized = JSON.parse(stored);\n if (!deserialized) {\n console.error('restoreState: Data could not be deserialized');\n return undefined;\n }\n\n const donationInfo = new VenmoRestorationState(deserialized);\n\n return donationInfo;\n }\n\n /**\n * Check if a particular storage system (localStorage/sessionStorage) is availble\n *\n * @private\n * @param {Storage} system\n * @returns {boolean}\n * @memberof VenmoRestorationStateHandler\n */\n private storageSystemAvailable(system: Storage): boolean {\n try {\n system.setItem('foo', 'bar');\n system.removeItem('foo');\n return true;\n } catch (exception) {\n return false;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"venmo-restoration-state-handler.js","sourceRoot":"","sources":["../../../../src/payment-flow-handlers/handlers/venmo-restoration-state-handler.ts"],"names":[],"mappings":";AA4BA;;;;;GAKG;AACH,MAAM,OAAO,qBAAqB;IAIhC,yCAAyC;IACzC,YAAY,MAA4E;QACtF,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACtC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;IAC1C,CAAC;CACF;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,4BAA4B;IAKvC,YAAY,OAAqC;QAJzC,mBAAc,GAAG,2BAA2B,CAAC;QAKnD,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,EAAE,CAAC;YAC3B,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC7C,CAAC;aAAM,IAAI,IAAI,CAAC,sBAAsB,CAAC,YAAY,CAAC,EAAE,CAAC;YACrD,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QACpC,CAAC;aAAM,IAAI,IAAI,CAAC,sBAAsB,CAAC,cAAc,CAAC,EAAE,CAAC;YACvD,IAAI,CAAC,aAAa,GAAG,cAAc,CAAC;QACtC,CAAC;IACH,CAAC;IAED,kBAAkB;IAClB,UAAU;;QACR,MAAA,IAAI,CAAC,aAAa,0CAAE,UAAU,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACtD,CAAC;IAED,kBAAkB;IAClB,YAAY,CAAC,WAA6B,EAAE,YAAiC;;QAC3E,MAAM,gBAAgB,GAAG,IAAI,qBAAqB,CAAC;YACjD,WAAW;YACX,YAAY;SACb,CAAC,CAAC;QACH,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;QACpD,MAAA,IAAI,CAAC,aAAa,0CAAE,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;IAC/D,CAAC;IAED,kBAAkB;IACZ,mBAAmB;;;YACvB,MAAM,MAAM,GAAG,MAAA,IAAI,CAAC,aAAa,0CAAE,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAChE,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,OAAO,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;gBAC9C,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YACxC,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,OAAO,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;gBAC9D,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,MAAM,YAAY,GAAG,IAAI,qBAAqB,CAAC,YAAY,CAAC,CAAC;YAE7D,OAAO,YAAY,CAAC;QACtB,CAAC;KAAA;IAED;;;;;;;OAOG;IACK,sBAAsB,CAAC,MAAe;QAC5C,IAAI,CAAC;YACH,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAC7B,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YACzB,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,SAAS,EAAE,CAAC;YACnB,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF","sourcesContent":["import { DonorContactInfo, DonationPaymentInfo } from '@internetarchive/donation-form-data-models';\n\nexport interface VenmoRestorationStateHandlerInterface {\n /**\n * Persist the session state\n *\n * @param {DonorContactInfo} contactInfo\n * @param {DonationPaymentInfo} donationInfo\n * @memberof VenmoRestorationStateHandlerInterface\n */\n persistState(contactInfo: DonorContactInfo, donationInfo: DonationPaymentInfo): void;\n\n /**\n * Get the session restoration state\n *\n * @returns {(Promise<VenmoRestorationState | undefined>)}\n * @memberof VenmoRestorationStateHandlerInterface\n */\n getRestorationState(): Promise<VenmoRestorationState | undefined>;\n\n /**\n * Clear the restoration state\n *\n * @memberof VenmoRestorationStateHandlerInterface\n */\n clearState(): void;\n}\n\n/**\n * Structure to store the session restoration state\n *\n * @export\n * @class VenmoRestorationState\n */\nexport class VenmoRestorationState {\n contactInfo: DonorContactInfo;\n donationInfo: DonationPaymentInfo;\n\n // TODO: Add restoration state expiration\n constructor(params: { contactInfo: DonorContactInfo; donationInfo: DonationPaymentInfo }) {\n this.contactInfo = params.contactInfo;\n this.donationInfo = params.donationInfo;\n }\n}\n\n/**\n * The VenmoRestorationStateHandler is used to persist and restore a Venmo checkout session.\n *\n * Venmo takes the user out of the web browser and into their app to authorize the purchase.\n * It then redirects the user back to the website to finish the transaction. The problem is\n * it may open a new browser tab so it's like starting a new session. We need to persist\n * the session information from the start of the Venmo session and restore it when it resumes.\n *\n * This class stores the session information in localStorage when the Venmo session is started\n * and retrieves it when the session is restored.\n *\n * @export\n * @class VenmoRestorationStateHandler\n * @implements {VenmoRestorationStateHandlerInterface}\n */\nexport class VenmoRestorationStateHandler implements VenmoRestorationStateHandlerInterface {\n private persistanceKey = 'venmoRestorationStateInfo';\n\n private storageSystem?: Storage;\n\n constructor(options?: { storageSystem?: Storage }) {\n if (options?.storageSystem) {\n this.storageSystem = options.storageSystem;\n } else if (this.storageSystemAvailable(localStorage)) {\n this.storageSystem = localStorage;\n } else if (this.storageSystemAvailable(sessionStorage)) {\n this.storageSystem = sessionStorage;\n }\n }\n\n /** @inheritdoc */\n clearState(): void {\n this.storageSystem?.removeItem(this.persistanceKey);\n }\n\n /** @inheritdoc */\n persistState(contactInfo: DonorContactInfo, donationInfo: DonationPaymentInfo): void {\n const venmoRestoration = new VenmoRestorationState({\n contactInfo,\n donationInfo,\n });\n const serialized = JSON.stringify(venmoRestoration);\n this.storageSystem?.setItem(this.persistanceKey, serialized);\n }\n\n /** @inheritdoc */\n async getRestorationState(): Promise<VenmoRestorationState | undefined> {\n const stored = this.storageSystem?.getItem(this.persistanceKey);\n if (!stored) {\n console.error('restoreState: No stored data');\n return undefined;\n }\n\n const deserialized = JSON.parse(stored);\n if (!deserialized) {\n console.error('restoreState: Data could not be deserialized');\n return undefined;\n }\n\n const donationInfo = new VenmoRestorationState(deserialized);\n\n return donationInfo;\n }\n\n /**\n * Check if a particular storage system (localStorage/sessionStorage) is availble\n *\n * @private\n * @param {Storage} system\n * @returns {boolean}\n * @memberof VenmoRestorationStateHandler\n */\n private storageSystemAvailable(system: Storage): boolean {\n try {\n system.setItem('foo', 'bar');\n system.removeItem('foo');\n return true;\n } catch (exception) {\n return false;\n }\n }\n}\n"]}
@@ -26,8 +26,8 @@ import { GooglePayFlowHandler, } from './handlers/googlepay-flow-handler';
26
26
  */
27
27
  export class PaymentFlowHandlers {
28
28
  startup() {
29
- var _a, _b;
30
29
  return __awaiter(this, void 0, void 0, function* () {
30
+ var _a, _b;
31
31
  (_a = this.venmoHandler) === null || _a === void 0 ? void 0 : _a.startup();
32
32
  (_b = this.creditCardHandler) === null || _b === void 0 ? void 0 : _b.startup();
33
33
  });
@@ -1 +1 @@
1
- {"version":3,"file":"payment-flow-handlers.js","sourceRoot":"","sources":["../../../src/payment-flow-handlers/payment-flow-handlers.ts"],"names":[],"mappings":";AAGA,OAAO,EAEL,qBAAqB,GACtB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAA8B,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAG/F,OAAO,EAEL,mBAAmB,GACpB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAA6B,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAC5F,OAAO,EAEL,wBAAwB,GACzB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAEL,oBAAoB,GACrB,MAAM,mCAAmC,CAAC;AA2C3C;;;;;;;;;;;;;;;;;;GAkBG;AACH,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nimport { ModalManagerInterface } from '@internetarchive/modal-manager';\n\nimport {\n CreditCardFlowHandlerInterface,\n CreditCardFlowHandler,\n} from './handlers/creditcard-flow-handler';\nimport { PayPalFlowHandlerInterface, PayPalFlowHandler } from './handlers/paypal-flow-handler';\nimport { BraintreeManagerInterface } from '../braintree-manager/braintree-interfaces';\nimport { RecaptchaManagerInterface } from '../recaptcha-manager/recaptcha-manager';\nimport {\n ApplePayFlowHandlerInterface,\n ApplePayFlowHandler,\n} from './handlers/applepay-flow-handler';\nimport { VenmoFlowHandlerInterface, VenmoFlowHandler } from './handlers/venmo-flow-handler';\nimport {\n DonationFlowModalManagerInterface,\n DonationFlowModalManager,\n} from './donation-flow-modal-manager';\nimport {\n GooglePayFlowHandlerInterface,\n GooglePayFlowHandler,\n} from './handlers/googlepay-flow-handler';\nimport { UpsellModalCTAMode } from '../modals/upsell-modal-content';\nimport { DonationType } from '@internetarchive/donation-form-data-models';\n\nexport interface PaymentFlowHandlersInterface {\n startup(): Promise<void>;\n /**\n * Show the upsell modal\n *\n * @param {{\n * ctaMode?: UpsellModalCTAMode;\n * yesSelected?: (amount: number) => void;\n * noSelected?: () => void;\n * amountChanged?: (amount: number) => void;\n * userClosedModalCallback?: () => void;\n * }} [options]\n * @returns {Promise<void>}\n * @memberof DonationFlowModalManagerInterface\n */\n showUpsellModal(options: {\n oneTimeAmount: number;\n ctaMode?: UpsellModalCTAMode;\n yesSelected?: (amount: number) => void;\n noSelected?: () => void;\n amountChanged?: (amount: number) => void;\n userClosedModalCallback?: () => void;\n }): Promise<void>;\n\n showConfirmationStepModal(options: {\n amount: number;\n donationType: DonationType;\n currencyType: string;\n confirmDonationCB: Function;\n cancelDonationCB: Function;\n }): Promise<void>;\n\n creditCardHandler: CreditCardFlowHandlerInterface | undefined;\n paypalHandler: PayPalFlowHandlerInterface | undefined;\n applePayHandler: ApplePayFlowHandlerInterface | undefined;\n venmoHandler: VenmoFlowHandlerInterface | undefined;\n googlePayHandler: GooglePayFlowHandlerInterface | undefined;\n}\n\n/**\n * This class is a container for all of the individual flow handlers.\n *\n * Flow Handlers are responsible for handling the provider-specific interactions between\n * the UI and the Data.\n *\n * For instance, when the user clicks on the \"Donate\" button for credit cards, we\n * pull in contact info from the form, trigger the recaptcha, tokenize the form,\n * submit, show the upsell, complete. The Credit Card Flow Handler is responsible for\n * managing that series of steps.\n *\n * For PayPal, the user initiates the payment from the PayPal button and once they're\n * done, we show the modal. The PayPal Flow Handler is responsible for handling that\n * series of events.\n *\n * @export\n * @class PaymentFlowHandlers\n * @implements {PaymentFlowHandlersInterface}\n */\nexport class PaymentFlowHandlers implements PaymentFlowHandlersInterface {\n async startup(): Promise<void> {\n this.venmoHandler?.startup();\n this.creditCardHandler?.startup();\n }\n\n /** @inheritdoc */\n async showUpsellModal(options: {\n oneTimeAmount: number;\n ctaMode?: UpsellModalCTAMode;\n yesSelected?: (amount: number) => void;\n noSelected?: () => void;\n amountChanged?: (amount: number) => void;\n userClosedModalCallback?: () => void;\n }): Promise<void> {\n return this.donationFlowModalManager.showUpsellModal(options);\n }\n\n /** @inheritdoc */\n showConfirmationStepModal(options: {\n amount: number;\n donationType: DonationType;\n currencyType: string;\n confirmDonationCB: Function;\n cancelDonationCB: Function;\n }): Promise<void> {\n return this.donationFlowModalManager.showConfirmationStepModal(options);\n }\n\n get creditCardHandler(): CreditCardFlowHandlerInterface | undefined {\n if (this.creditCardHandlerCache) {\n return this.creditCardHandlerCache;\n }\n\n this.creditCardHandlerCache = new CreditCardFlowHandler({\n braintreeManager: this.braintreeManager,\n donationFlowModalManager: this.donationFlowModalManager,\n recaptchaManager: this.recaptchaManager,\n });\n\n return this.creditCardHandlerCache;\n }\n\n get paypalHandler(): PayPalFlowHandlerInterface | undefined {\n if (this.paypalHandlerCache) {\n return this.paypalHandlerCache;\n }\n\n this.paypalHandlerCache = new PayPalFlowHandler({\n braintreeManager: this.braintreeManager,\n donationFlowModalManager: this.donationFlowModalManager,\n });\n\n return this.paypalHandlerCache;\n }\n\n get applePayHandler(): ApplePayFlowHandlerInterface | undefined {\n if (this.applePayHandlerCache) {\n return this.applePayHandlerCache;\n }\n\n this.applePayHandlerCache = new ApplePayFlowHandler({\n braintreeManager: this.braintreeManager,\n donationFlowModalManager: this.donationFlowModalManager,\n });\n\n return this.applePayHandlerCache;\n }\n\n get venmoHandler(): VenmoFlowHandlerInterface | undefined {\n if (this.venmoHandlerCache) {\n return this.venmoHandlerCache;\n }\n\n this.venmoHandlerCache = new VenmoFlowHandler({\n braintreeManager: this.braintreeManager,\n donationFlowModalManager: this.donationFlowModalManager,\n });\n\n return this.venmoHandlerCache;\n }\n\n get googlePayHandler(): GooglePayFlowHandlerInterface | undefined {\n if (this.googlePayHandlerCache) {\n return this.googlePayHandlerCache;\n }\n\n this.googlePayHandlerCache = new GooglePayFlowHandler({\n braintreeManager: this.braintreeManager,\n donationFlowModalManager: this.donationFlowModalManager,\n });\n\n return this.googlePayHandlerCache;\n }\n\n private creditCardHandlerCache?: CreditCardFlowHandlerInterface;\n private paypalHandlerCache?: PayPalFlowHandlerInterface;\n private applePayHandlerCache?: ApplePayFlowHandlerInterface;\n private venmoHandlerCache?: VenmoFlowHandlerInterface;\n private googlePayHandlerCache?: GooglePayFlowHandlerInterface;\n\n constructor(options: {\n braintreeManager: BraintreeManagerInterface;\n modalManager: ModalManagerInterface;\n recaptchaManager: RecaptchaManagerInterface;\n resources: {\n analytics: {\n logEvent: (action: string, label: string) => void;\n logDonationFlowEvent: (action: string, label: string) => void;\n };\n };\n }) {\n this.braintreeManager = options.braintreeManager;\n this.modalManager = options.modalManager;\n this.recaptchaManager = options.recaptchaManager;\n this.resources = options.resources;\n\n this.donationFlowModalManager = new DonationFlowModalManager({\n braintreeManager: this.braintreeManager,\n modalManager: this.modalManager,\n analytics: this.resources.analytics,\n });\n }\n\n private braintreeManager: BraintreeManagerInterface;\n private modalManager: ModalManagerInterface;\n private recaptchaManager: RecaptchaManagerInterface;\n private donationFlowModalManager: DonationFlowModalManagerInterface;\n private resources: {\n analytics: {\n logEvent: (action: string, label: string) => void;\n logDonationFlowEvent: (action: string, label: string) => void;\n };\n };\n}\n"]}
1
+ {"version":3,"file":"payment-flow-handlers.js","sourceRoot":"","sources":["../../../src/payment-flow-handlers/payment-flow-handlers.ts"],"names":[],"mappings":";AAEA,OAAO,EAEL,qBAAqB,GACtB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAA8B,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAG/F,OAAO,EAEL,mBAAmB,GACpB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAA6B,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAC5F,OAAO,EAEL,wBAAwB,GACzB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAEL,oBAAoB,GACrB,MAAM,mCAAmC,CAAC;AA2C3C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,mBAAmB;IACxB,OAAO;;;YACX,MAAA,IAAI,CAAC,YAAY,0CAAE,OAAO,EAAE,CAAC;YAC7B,MAAA,IAAI,CAAC,iBAAiB,0CAAE,OAAO,EAAE,CAAC;QACpC,CAAC;KAAA;IAED,kBAAkB;IACZ,eAAe,CAAC,OAOrB;;YACC,OAAO,IAAI,CAAC,wBAAwB,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAChE,CAAC;KAAA;IAED,kBAAkB;IAClB,yBAAyB,CAAC,OAMzB;QACC,OAAO,IAAI,CAAC,wBAAwB,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC;IAC1E,CAAC;IAED,IAAI,iBAAiB;QACnB,IAAI,IAAI,CAAC,sBAAsB,EAAE,CAAC;YAChC,OAAO,IAAI,CAAC,sBAAsB,CAAC;QACrC,CAAC;QAED,IAAI,CAAC,sBAAsB,GAAG,IAAI,qBAAqB,CAAC;YACtD,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;YACvC,wBAAwB,EAAE,IAAI,CAAC,wBAAwB;YACvD,gBAAgB,EAA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AAC,gBAAgB;YACvC,wBAAwB,EAAE,IAAI,CAAC,wBAAwB;SACxD,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,qBAAqB,CAAC;IACpC,CAAC;IAQD,YAAY,OAUX;QACC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QACjD,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QACjD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QAEnC,IAAI,CAAC,wBAAwB,GAAG,IAAI,wBAAwB,CAAC;YAC3D,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;YACvC,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS;SACpC,CAAC,CAAC;IACL,CAAC;CAYF","sourcesContent":["import { ModalManagerInterface } from '@internetarchive/modal-manager';\n\nimport {\n CreditCardFlowHandlerInterface,\n CreditCardFlowHandler,\n} from './handlers/creditcard-flow-handler';\nimport { PayPalFlowHandlerInterface, PayPalFlowHandler } from './handlers/paypal-flow-handler';\nimport { BraintreeManagerInterface } from '../braintree-manager/braintree-interfaces';\nimport { RecaptchaManagerInterface } from '../recaptcha-manager/recaptcha-manager';\nimport {\n ApplePayFlowHandlerInterface,\n ApplePayFlowHandler,\n} from './handlers/applepay-flow-handler';\nimport { VenmoFlowHandlerInterface, VenmoFlowHandler } from './handlers/venmo-flow-handler';\nimport {\n DonationFlowModalManagerInterface,\n DonationFlowModalManager,\n} from './donation-flow-modal-manager';\nimport {\n GooglePayFlowHandlerInterface,\n GooglePayFlowHandler,\n} from './handlers/googlepay-flow-handler';\nimport { UpsellModalCTAMode } from '../modals/upsell-modal-content';\nimport { DonationType } from '@internetarchive/donation-form-data-models';\n\nexport interface PaymentFlowHandlersInterface {\n startup(): Promise<void>;\n /**\n * Show the upsell modal\n *\n * @param {{\n * ctaMode?: UpsellModalCTAMode;\n * yesSelected?: (amount: number) => void;\n * noSelected?: () => void;\n * amountChanged?: (amount: number) => void;\n * userClosedModalCallback?: () => void;\n * }} [options]\n * @returns {Promise<void>}\n * @memberof DonationFlowModalManagerInterface\n */\n showUpsellModal(options: {\n oneTimeAmount: number;\n ctaMode?: UpsellModalCTAMode;\n yesSelected?: (amount: number) => void;\n noSelected?: () => void;\n amountChanged?: (amount: number) => void;\n userClosedModalCallback?: () => void;\n }): Promise<void>;\n\n showConfirmationStepModal(options: {\n amount: number;\n donationType: DonationType;\n currencyType: string;\n confirmDonationCB: Function;\n cancelDonationCB: Function;\n }): Promise<void>;\n\n creditCardHandler: CreditCardFlowHandlerInterface | undefined;\n paypalHandler: PayPalFlowHandlerInterface | undefined;\n applePayHandler: ApplePayFlowHandlerInterface | undefined;\n venmoHandler: VenmoFlowHandlerInterface | undefined;\n googlePayHandler: GooglePayFlowHandlerInterface | undefined;\n}\n\n/**\n * This class is a container for all of the individual flow handlers.\n *\n * Flow Handlers are responsible for handling the provider-specific interactions between\n * the UI and the Data.\n *\n * For instance, when the user clicks on the \"Donate\" button for credit cards, we\n * pull in contact info from the form, trigger the recaptcha, tokenize the form,\n * submit, show the upsell, complete. The Credit Card Flow Handler is responsible for\n * managing that series of steps.\n *\n * For PayPal, the user initiates the payment from the PayPal button and once they're\n * done, we show the modal. The PayPal Flow Handler is responsible for handling that\n * series of events.\n *\n * @export\n * @class PaymentFlowHandlers\n * @implements {PaymentFlowHandlersInterface}\n */\nexport class PaymentFlowHandlers implements PaymentFlowHandlersInterface {\n async startup(): Promise<void> {\n this.venmoHandler?.startup();\n this.creditCardHandler?.startup();\n }\n\n /** @inheritdoc */\n async showUpsellModal(options: {\n oneTimeAmount: number;\n ctaMode?: UpsellModalCTAMode;\n yesSelected?: (amount: number) => void;\n noSelected?: () => void;\n amountChanged?: (amount: number) => void;\n userClosedModalCallback?: () => void;\n }): Promise<void> {\n return this.donationFlowModalManager.showUpsellModal(options);\n }\n\n /** @inheritdoc */\n showConfirmationStepModal(options: {\n amount: number;\n donationType: DonationType;\n currencyType: string;\n confirmDonationCB: Function;\n cancelDonationCB: Function;\n }): Promise<void> {\n return this.donationFlowModalManager.showConfirmationStepModal(options);\n }\n\n get creditCardHandler(): CreditCardFlowHandlerInterface | undefined {\n if (this.creditCardHandlerCache) {\n return this.creditCardHandlerCache;\n }\n\n this.creditCardHandlerCache = new CreditCardFlowHandler({\n braintreeManager: this.braintreeManager,\n donationFlowModalManager: this.donationFlowModalManager,\n recaptchaManager: this.recaptchaManager,\n });\n\n return this.creditCardHandlerCache;\n }\n\n get paypalHandler(): PayPalFlowHandlerInterface | undefined {\n if (this.paypalHandlerCache) {\n return this.paypalHandlerCache;\n }\n\n this.paypalHandlerCache = new PayPalFlowHandler({\n braintreeManager: this.braintreeManager,\n donationFlowModalManager: this.donationFlowModalManager,\n });\n\n return this.paypalHandlerCache;\n }\n\n get applePayHandler(): ApplePayFlowHandlerInterface | undefined {\n if (this.applePayHandlerCache) {\n return this.applePayHandlerCache;\n }\n\n this.applePayHandlerCache = new ApplePayFlowHandler({\n braintreeManager: this.braintreeManager,\n donationFlowModalManager: this.donationFlowModalManager,\n });\n\n return this.applePayHandlerCache;\n }\n\n get venmoHandler(): VenmoFlowHandlerInterface | undefined {\n if (this.venmoHandlerCache) {\n return this.venmoHandlerCache;\n }\n\n this.venmoHandlerCache = new VenmoFlowHandler({\n braintreeManager: this.braintreeManager,\n donationFlowModalManager: this.donationFlowModalManager,\n });\n\n return this.venmoHandlerCache;\n }\n\n get googlePayHandler(): GooglePayFlowHandlerInterface | undefined {\n if (this.googlePayHandlerCache) {\n return this.googlePayHandlerCache;\n }\n\n this.googlePayHandlerCache = new GooglePayFlowHandler({\n braintreeManager: this.braintreeManager,\n donationFlowModalManager: this.donationFlowModalManager,\n });\n\n return this.googlePayHandlerCache;\n }\n\n private creditCardHandlerCache?: CreditCardFlowHandlerInterface;\n private paypalHandlerCache?: PayPalFlowHandlerInterface;\n private applePayHandlerCache?: ApplePayFlowHandlerInterface;\n private venmoHandlerCache?: VenmoFlowHandlerInterface;\n private googlePayHandlerCache?: GooglePayFlowHandlerInterface;\n\n constructor(options: {\n braintreeManager: BraintreeManagerInterface;\n modalManager: ModalManagerInterface;\n recaptchaManager: RecaptchaManagerInterface;\n resources: {\n analytics: {\n logEvent: (action: string, label: string) => void;\n logDonationFlowEvent: (action: string, label: string) => void;\n };\n };\n }) {\n this.braintreeManager = options.braintreeManager;\n this.modalManager = options.modalManager;\n this.recaptchaManager = options.recaptchaManager;\n this.resources = options.resources;\n\n this.donationFlowModalManager = new DonationFlowModalManager({\n braintreeManager: this.braintreeManager,\n modalManager: this.modalManager,\n analytics: this.resources.analytics,\n });\n }\n\n private braintreeManager: BraintreeManagerInterface;\n private modalManager: ModalManagerInterface;\n private recaptchaManager: RecaptchaManagerInterface;\n private donationFlowModalManager: DonationFlowModalManagerInterface;\n private resources: {\n analytics: {\n logEvent: (action: string, label: string) => void;\n logDonationFlowEvent: (action: string, label: string) => void;\n };\n };\n}\n"]}
@@ -1,4 +1,3 @@
1
- /// <reference types="grecaptcha" />
2
1
  export interface RecaptchaManagerInterface {
3
2
  execute(): Promise<string>;
4
3
  setup(container: HTMLElement, tabIndex: number, theme: ReCaptchaV2.Theme, type: ReCaptchaV2.Type): void;
@@ -1 +1 @@
1
- {"version":3,"file":"recaptcha-manager.js","sourceRoot":"","sources":["../../../src/recaptcha-manager/recaptcha-manager.ts"],"names":[],"mappings":"AAUA,MAAM,OAAO,gBAAgB;IAK3B,YAAY,OAAsE;QAW1E,gBAAW,GAAG,KAAK,CAAC;QAV1B,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;QACnD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACjC,CAAC;IAUD;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,OAAO;QACL,IAAI,IAAI,CAAC,WAAW,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AE,WAAW;SAClB,CAAC,CAAC;IACL,CAAC;IAED,8DAA8D;IACtD,eAAe,CAAC,QAAa;QACnC,IAAI,IAAI,CAAC,qBAAqB,EAAE;YAC9B,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;YACrC,IAAI,CAAC,qBAAqB,GAAG,SAAS,CAAC;SACxC;IACH,CAAC;IAEO,cAAc;QACpB,IAAI,IAAI,CAAC,qBAAqB,EAAE;YAC9B,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC7B,IAAI,CAAC,qBAAqB,GAAG,SAAS,CAAC;SACxC;IACH,CAAC;IAEO,YAAY;QAClB,IAAI,IAAI,CAAC,mBAAmB,EAAE;YAC5B,IAAI,CAAC,mBAAmB,EAAE,CAAC;YAC3B,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC;SACtC;IACH,CAAC;CACF","sourcesContent":["export interface RecaptchaManagerInterface {\n execute(): Promise<string>;\n setup(\n container: HTMLElement,\n tabIndex: number,\n theme: ReCaptchaV2.Theme,\n type: ReCaptchaV2.Type,\n ): void;\n}\n\nexport class RecaptchaManager implements RecaptchaManagerInterface {\n private grecaptchaLibrary: ReCaptchaV2.ReCaptcha;\n\n private siteKey: string;\n\n constructor(options: { grecaptchaLibrary: ReCaptchaV2.ReCaptcha; siteKey: string }) {\n this.grecaptchaLibrary = options.grecaptchaLibrary;\n this.siteKey = options.siteKey;\n }\n\n private executionSuccessBlock?: (token: string) => void;\n\n private executionExpiredBlock?: () => void;\n\n private executionErrorBlock?: () => void;\n\n private isExecuting = false;\n\n /**\n * Execute Recaptcha and return a Promise containing the response token.\n *\n * This is an interesting flow.. we call `execute()` here, but have to wait for the\n * response and expiration handlers that we bind during the inital `setup` call.\n * For consumers, we want to be able to just call `execute()` and wait for a response.\n * To allow this, we assign two callbacks:\n * - `executionSuccessBlock`\n * - `executionExpiredBlock`\n *\n * We then call those callbacks from inside `responseHandler` and `expiredHandler` to\n * either resolve or reject the Promise.\n *\n * ie:\n *\n * try {\n * const recaptchaResult = await recaptchaManager.execute();\n * console.log('recaptcha token:', recaptchaResult);\n * } catch {\n * console.error('something happened')\n * }\n *\n * @returns {Promise<string>}\n * @memberof RecaptchaManager\n */\n execute(): Promise<string> {\n if (this.isExecuting) {\n this.finishExecution();\n }\n this.isExecuting = true;\n return new Promise((resolve, reject) => {\n this.executionSuccessBlock = (token: string): void => {\n this.finishExecution();\n resolve(token);\n };\n\n this.executionExpiredBlock = (): void => {\n this.finishExecution();\n reject('expired');\n };\n\n this.executionErrorBlock = (): void => {\n this.finishExecution();\n reject('error');\n };\n\n this.grecaptchaLibrary.execute();\n });\n }\n\n private finishExecution(): void {\n this.isExecuting = false;\n this.grecaptchaLibrary.reset();\n }\n\n setup(\n container: HTMLElement,\n tabIndex: number,\n theme: ReCaptchaV2.Theme,\n type: ReCaptchaV2.Type,\n ): void {\n this.grecaptchaLibrary.render(container, {\n callback: this.responseHandler.bind(this),\n 'expired-callback': this.expiredHandler.bind(this),\n 'error-callback': this.errorHandler.bind(this),\n sitekey: this.siteKey,\n tabindex: tabIndex,\n theme: theme,\n type: type,\n size: 'invisible',\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private responseHandler(response: any): void {\n if (this.executionSuccessBlock) {\n this.executionSuccessBlock(response);\n this.executionSuccessBlock = undefined;\n }\n }\n\n private expiredHandler(): void {\n if (this.executionExpiredBlock) {\n this.executionExpiredBlock();\n this.executionExpiredBlock = undefined;\n }\n }\n\n private errorHandler(): void {\n if (this.executionErrorBlock) {\n this.executionErrorBlock();\n this.executionErrorBlock = undefined;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"recaptcha-manager.js","sourceRoot":"","sources":["../../../src/recaptcha-manager/recaptcha-manager.ts"],"names":[],"mappings":"AAUA,MAAM,OAAO,gBAAgB;IAK3B,YAAY,OAAsE;QAW1E,gBAAW,GAAG,KAAK,CAAC;QAV1B,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CA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,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;YAC9C,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,QAAQ,EAAE,QAAQ;YAClB,KAAK,EAAE,KAAK;YACZ,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,WAAW;SAClB,CAAC,CAAC;IACL,CAAC;IAED,8DAA8D;IACtD,eAAe,CAAC,QAAa;QACnC,IAAI,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC/B,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;YACrC,IAAI,CAAC,qBAAqB,GAAG,SAAS,CAAC;QACzC,CAAC;IACH,CAAC;IAEO,cAAc;QACpB,IAAI,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC/B,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC7B,IAAI,CAAC,qBAAqB,GAAG,SAAS,CAAC;QACzC,CAAC;IACH,CAAC;IAEO,YAAY;QAClB,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;YAC7B,IAAI,CAAC,mBAAmB,EAAE,CAAC;YAC3B,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC;QACvC,CAAC;IACH,CAAC;CACF","sourcesContent":["export interface RecaptchaManagerInterface {\n execute(): Promise<string>;\n setup(\n container: HTMLElement,\n tabIndex: number,\n theme: ReCaptchaV2.Theme,\n type: ReCaptchaV2.Type,\n ): void;\n}\n\nexport class RecaptchaManager implements RecaptchaManagerInterface {\n private grecaptchaLibrary: ReCaptchaV2.ReCaptcha;\n\n private siteKey: string;\n\n constructor(options: { grecaptchaLibrary: ReCaptchaV2.ReCaptcha; siteKey: string }) {\n this.grecaptchaLibrary = options.grecaptchaLibrary;\n this.siteKey = options.siteKey;\n }\n\n private executionSuccessBlock?: (token: string) => void;\n\n private executionExpiredBlock?: () => void;\n\n private executionErrorBlock?: () => void;\n\n private isExecuting = false;\n\n /**\n * Execute Recaptcha and return a Promise containing the response token.\n *\n * This is an interesting flow.. we call `execute()` here, but have to wait for the\n * response and expiration handlers that we bind during the inital `setup` call.\n * For consumers, we want to be able to just call `execute()` and wait for a response.\n * To allow this, we assign two callbacks:\n * - `executionSuccessBlock`\n * - `executionExpiredBlock`\n *\n * We then call those callbacks from inside `responseHandler` and `expiredHandler` to\n * either resolve or reject the Promise.\n *\n * ie:\n *\n * try {\n * const recaptchaResult = await recaptchaManager.execute();\n * console.log('recaptcha token:', recaptchaResult);\n * } catch {\n * console.error('something happened')\n * }\n *\n * @returns {Promise<string>}\n * @memberof RecaptchaManager\n */\n execute(): Promise<string> {\n if (this.isExecuting) {\n this.finishExecution();\n }\n this.isExecuting = true;\n return new Promise((resolve, reject) => {\n this.executionSuccessBlock = (token: string): void => {\n this.finishExecution();\n resolve(token);\n };\n\n this.executionExpiredBlock = (): void => {\n this.finishExecution();\n reject('expired');\n };\n\n this.executionErrorBlock = (): void => {\n this.finishExecution();\n reject('error');\n };\n\n this.grecaptchaLibrary.execute();\n });\n }\n\n private finishExecution(): void {\n this.isExecuting = false;\n this.grecaptchaLibrary.reset();\n }\n\n setup(\n container: HTMLElement,\n tabIndex: number,\n theme: ReCaptchaV2.Theme,\n type: ReCaptchaV2.Type,\n ): void {\n this.grecaptchaLibrary.render(container, {\n callback: this.responseHandler.bind(this),\n 'expired-callback': this.expiredHandler.bind(this),\n 'error-callback': this.errorHandler.bind(this),\n sitekey: this.siteKey,\n tabindex: tabIndex,\n theme: theme,\n type: type,\n size: 'invisible',\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private responseHandler(response: any): void {\n if (this.executionSuccessBlock) {\n this.executionSuccessBlock(response);\n this.executionSuccessBlock = undefined;\n }\n }\n\n private expiredHandler(): void {\n if (this.executionExpiredBlock) {\n this.executionExpiredBlock();\n this.executionExpiredBlock = undefined;\n }\n }\n\n private errorHandler(): void {\n if (this.executionErrorBlock) {\n this.executionErrorBlock();\n this.executionErrorBlock = undefined;\n }\n }\n}\n"]}
@@ -1,5 +1,4 @@
1
1
  import { __awaiter } from "tslib";
2
- /* eslint-disable @typescript-eslint/no-unused-vars */
3
2
  import { createNanoEvents } from 'nanoevents';
4
3
  export class MockCreditCardFlowHandler {
5
4
  constructor() {
@@ -1 +1 @@
1
- {"version":3,"file":"mock-creditcard-flow-handler.js","sourceRoot":"","sources":["../../../../../test/mocks/flow-handlers/individual-handlers/mock-creditcard-flow-handler.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,OAAO,EAAW,gBAAgB,EAAe,MAAM,YAAY,CAAC;AAOpE,MAAM,OAAO,yBAAyB;IAAtC;QACE,kBAAa,GAAG,KAAK,CAAC;QAKd,YAAO,GACb,gBAAgB,EAA+B,CAAC;IA8BpD,CAAC;IA5BC,0BAA0B;QACxB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;IAC7C,CAAC;IAEK,OAAO;;YACX,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC5B,CAAC;KAAA;IAEK,cAAc;;YAClB,OAAO,SAAS,CAAC;QACnB,CAAC;KAAA;IAEK,gBAAgB,CACpB,oBAA2D,EAC3D,YAAiC,EACjC,gBAAkC;;YAElC,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;YACjD,IAAI,CAAC,4BAA4B,GAAG,YAAY,CAAC;YACjD,IAAI,CAAC,gCAAgC,GAAG,gBAAgB,CAAC;QAC3D,CAAC;KAAA;IAED,EAAE,CACA,KAAQ,EACR,QAAwC;QAExC,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC1C,CAAC;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { Emitter, createNanoEvents, Unsubscribe } from 'nanoevents';\nimport {\n CreditCardFlowHandlerInterface,\n CreditCardFlowHandlerEvents,\n} from '../../../../src/payment-flow-handlers/handlers/creditcard-flow-handler';\nimport { DonationPaymentInfo, DonorContactInfo } from '@internetarchive/donation-form-data-models';\n\nexport class MockCreditCardFlowHandler implements CreditCardFlowHandlerInterface {\n startupCalled = false;\n paymentInitiatedDonationInfo?: DonationPaymentInfo;\n paymentInitiatedDonorContactInfo?: DonorContactInfo;\n hostedFieldsResponse?: braintree.HostedFieldsTokenizePayload;\n\n private emitter: Emitter<CreditCardFlowHandlerEvents> =\n createNanoEvents<CreditCardFlowHandlerEvents>();\n\n emitValidHostedFieldsEvent(): void {\n this.emitter.emit('validityChanged', true);\n }\n\n async startup(): Promise<void> {\n this.startupCalled = true;\n }\n\n async tokenizeFields(): Promise<braintree.HostedFieldsTokenizePayload | undefined> {\n return undefined;\n }\n\n async paymentInitiated(\n hostedFieldsResponse: braintree.HostedFieldsTokenizePayload,\n donationInfo: DonationPaymentInfo,\n donorContactInfo: DonorContactInfo,\n ): Promise<void> {\n this.hostedFieldsResponse = hostedFieldsResponse;\n this.paymentInitiatedDonationInfo = donationInfo;\n this.paymentInitiatedDonorContactInfo = donorContactInfo;\n }\n\n on<E extends keyof CreditCardFlowHandlerEvents>(\n event: E,\n callback: CreditCardFlowHandlerEvents[E],\n ): Unsubscribe {\n return this.emitter.on(event, callback);\n }\n}\n"]}
1
+ {"version":3,"file":"mock-creditcard-flow-handler.js","sourceRoot":"","sources":["../../../../../test/mocks/flow-handlers/individual-handlers/mock-creditcard-flow-handler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAW,gBAAgB,EAAe,MAAM,YAAY,CAAC;AAOpE,MAAM,OAAO,yBAAyB;IAAtC;QACE,kBAAa,GAAG,KAAK,CAAC;QAKd,YAAO,GACb,gBAAgB,EAA+B,CAAC;IA8BpD,CAAC;IA5BC,0BAA0B;QACxB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;IAC7C,CAAC;IAEK,OAAO;;YACX,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC5B,CAAC;KAAA;IAEK,cAAc;;YAClB,OAAO,SAAS,CAAC;QACnB,CAAC;KAAA;IAEK,gBAAgB,CACpB,oBAA2D,EAC3D,YAAiC,EACjC,gBAAkC;;YAElC,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;YACjD,IAAI,CAAC,4BAA4B,GAAG,YAAY,CAAC;YACjD,IAAI,CAAC,gCAAgC,GAAG,gBAAgB,CAAC;QAC3D,CAAC;KAAA;IAED,EAAE,CACA,KAAQ,EACR,QAAwC;QAExC,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC1C,CAAC;CACF","sourcesContent":["import { Emitter, createNanoEvents, Unsubscribe } from 'nanoevents';\nimport {\n CreditCardFlowHandlerInterface,\n CreditCardFlowHandlerEvents,\n} from '../../../../src/payment-flow-handlers/handlers/creditcard-flow-handler';\nimport { DonationPaymentInfo, DonorContactInfo } from '@internetarchive/donation-form-data-models';\n\nexport class MockCreditCardFlowHandler implements CreditCardFlowHandlerInterface {\n startupCalled = false;\n paymentInitiatedDonationInfo?: DonationPaymentInfo;\n paymentInitiatedDonorContactInfo?: DonorContactInfo;\n hostedFieldsResponse?: braintree.HostedFieldsTokenizePayload;\n\n private emitter: Emitter<CreditCardFlowHandlerEvents> =\n createNanoEvents<CreditCardFlowHandlerEvents>();\n\n emitValidHostedFieldsEvent(): void {\n this.emitter.emit('validityChanged', true);\n }\n\n async startup(): Promise<void> {\n this.startupCalled = true;\n }\n\n async tokenizeFields(): Promise<braintree.HostedFieldsTokenizePayload | undefined> {\n return undefined;\n }\n\n async paymentInitiated(\n hostedFieldsResponse: braintree.HostedFieldsTokenizePayload,\n donationInfo: DonationPaymentInfo,\n donorContactInfo: DonorContactInfo,\n ): Promise<void> {\n this.hostedFieldsResponse = hostedFieldsResponse;\n this.paymentInitiatedDonationInfo = donationInfo;\n this.paymentInitiatedDonorContactInfo = donorContactInfo;\n }\n\n on<E extends keyof CreditCardFlowHandlerEvents>(\n event: E,\n callback: CreditCardFlowHandlerEvents[E],\n ): Unsubscribe {\n return this.emitter.on(event, callback);\n }\n}\n"]}
@@ -20,8 +20,8 @@ export class MockPaymentFlowHandlers {
20
20
  throw new Error('Method not implemented.');
21
21
  }
22
22
  startup() {
23
- var _a;
24
23
  return __awaiter(this, void 0, void 0, function* () {
24
+ var _a;
25
25
  this.startupCalled = true;
26
26
  (_a = this.venmoHandler) === null || _a === void 0 ? void 0 : _a.startup();
27
27
  });
@@ -1 +1 @@
1
- {"version":3,"file":"mock-payment-flow-handlers.js","sourceRoot":"","sources":["../../../../test/mocks/flow-handlers/mock-payment-flow-handlers.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,oDAAoD,CAAC;AAC/F,OAAO,EAAE,qBAAqB,EAAE,MAAM,gDAAgD,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,kDAAkD,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,+CAA+C,CAAC;AACrF,OAAO,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAC;AAI7F,MAAM,OAAO,uBAAuB;IAApC;QAkBE,kBAAa,GAAG,KAAK,CAAC;QAKtB,sBAAiB,GAA8B,IAAI,yBAAyB,EAAE,CAAC;QAC/E,kBAAa,GAA0B,IAAI,qBAAqB,EAAE,CAAC;QACnE,oBAAe,GAA4B,IAAI,uBAAuB,EAAE,CAAC;QACzE,iBAAY,GAAyB,IAAI,oBAAoB,EAAE,CAAC;QAChE,qBAAgB,GAA6B,IAAI,wBAAwB,EAAE,CAAC;IAC9E,CAAC;IA3BC,eAAe,CAAC,OAOf;QACC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IACD,yBAAyB,CAAC,OAIzB;QACC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAEK,OAAO;;;YACX,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;YAC1B,MAAA,IAAI,CAAC,YAAY,0CAAE,OAAO,EAAE,CAAC;;KAC9B;CAMF","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { PaymentFlowHandlersInterface } from '../../../src/payment-flow-handlers/payment-flow-handlers';\nimport { MockCreditCardFlowHandler } from './individual-handlers/mock-creditcard-flow-handler';\nimport { MockPayPalFlowHandler } from './individual-handlers/mock-paypal-flow-handler';\nimport { MockApplePayFlowHandler } from './individual-handlers/mock-applepay-flow-handler';\nimport { MockVenmoFlowHandler } from './individual-handlers/mock-venmo-flow-handler';\nimport { MockGooglePayFlowHandler } from './individual-handlers/mock-googlepay-flow-handler';\nimport { UpsellModalCTAMode } from '../../../src/modals/upsell-modal-content';\nimport { DonationType } from '@internetarchive/donation-form-data-models';\n\nexport class MockPaymentFlowHandlers implements PaymentFlowHandlersInterface {\n showUpsellModal(options: {\n oneTimeAmount: number;\n ctaMode?: UpsellModalCTAMode;\n yesSelected?: (amount: number) => void;\n noSelected?: () => void;\n amountChanged?: (amount: number) => void;\n userClosedModalCallback?: () => void;\n }): Promise<void> {\n throw new Error('Method not implemented.');\n }\n showConfirmationStepModal(options: {\n amount: number;\n donationType: DonationType;\n currencyType: string;\n }): Promise<void> {\n throw new Error('Method not implemented.');\n }\n startupCalled = false;\n async startup(): Promise<void> {\n this.startupCalled = true;\n this.venmoHandler?.startup();\n }\n creditCardHandler: MockCreditCardFlowHandler = new MockCreditCardFlowHandler();\n paypalHandler: MockPayPalFlowHandler = new MockPayPalFlowHandler();\n applePayHandler: MockApplePayFlowHandler = new MockApplePayFlowHandler();\n venmoHandler: MockVenmoFlowHandler = new MockVenmoFlowHandler();\n googlePayHandler: MockGooglePayFlowHandler = new MockGooglePayFlowHandler();\n}\n"]}
1
+ {"version":3,"file":"mock-payment-flow-handlers.js","sourceRoot":"","sources":["../../../../test/mocks/flow-handlers/mock-payment-flow-handlers.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,oDAAoD,CAAC;AAC/F,OAAO,EAAE,qBAAqB,EAAE,MAAM,gDAAgD,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,kDAAkD,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,+CAA+C,CAAC;AACrF,OAAO,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAC;AAI7F,MAAM,OAAO,uBAAuB;IAApC;QAkBE,kBAAa,GAAG,KAAK,CAAC;QAKtB,sBAAiB,GAA8B,IAAI,yBAAyB,EAAE,CAAC;QAC/E,kBAAa,GAA0B,IAAI,qBAAqB,EAAE,CAAC;QACnE,oBAAe,GAA4B,IAAI,uBAAuB,EAAE,CAAC;QACzE,iBAAY,GAAyB,IAAI,oBAAoB,EAAE,CAAC;QAChE,qBAAgB,GAA6B,IAAI,wBAAwB,EAAE,CAAC;IAC9E,CAAC;IA3BC,eAAe,CAAC,OAOf;QACC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IACD,yBAAyB,CAAC,OAIzB;QACC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAEK,OAAO;;;YACX,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;YAC1B,MAAA,IAAI,CAAC,YAAY,0CAAE,OAAO,EAAE,CAAC;QAC/B,CAAC;KAAA;CAMF","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { PaymentFlowHandlersInterface } from '../../../src/payment-flow-handlers/payment-flow-handlers';\nimport { MockCreditCardFlowHandler } from './individual-handlers/mock-creditcard-flow-handler';\nimport { MockPayPalFlowHandler } from './individual-handlers/mock-paypal-flow-handler';\nimport { MockApplePayFlowHandler } from './individual-handlers/mock-applepay-flow-handler';\nimport { MockVenmoFlowHandler } from './individual-handlers/mock-venmo-flow-handler';\nimport { MockGooglePayFlowHandler } from './individual-handlers/mock-googlepay-flow-handler';\nimport { UpsellModalCTAMode } from '../../../src/modals/upsell-modal-content';\nimport { DonationType } from '@internetarchive/donation-form-data-models';\n\nexport class MockPaymentFlowHandlers implements PaymentFlowHandlersInterface {\n showUpsellModal(options: {\n oneTimeAmount: number;\n ctaMode?: UpsellModalCTAMode;\n yesSelected?: (amount: number) => void;\n noSelected?: () => void;\n amountChanged?: (amount: number) => void;\n userClosedModalCallback?: () => void;\n }): Promise<void> {\n throw new Error('Method not implemented.');\n }\n showConfirmationStepModal(options: {\n amount: number;\n donationType: DonationType;\n currencyType: string;\n }): Promise<void> {\n throw new Error('Method not implemented.');\n }\n startupCalled = false;\n async startup(): Promise<void> {\n this.startupCalled = true;\n this.venmoHandler?.startup();\n }\n creditCardHandler: MockCreditCardFlowHandler = new MockCreditCardFlowHandler();\n paypalHandler: MockPayPalFlowHandler = new MockPayPalFlowHandler();\n applePayHandler: MockApplePayFlowHandler = new MockApplePayFlowHandler();\n venmoHandler: MockVenmoFlowHandler = new MockVenmoFlowHandler();\n googlePayHandler: MockGooglePayFlowHandler = new MockGooglePayFlowHandler();\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"mock-braintree-manager.js","sourceRoot":"","sources":["../../../test/mocks/mock-braintree-manager.ts"],"names":[],"mappings":";AAMA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAIL,gBAAgB,EAEhB,eAAe,EACf,aAAa,GACd,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAE9E,OAAO,EAAE,gBAAgB,EAAe,MAAM,YAAY,CAAC;AAE3D,MAAM,OAAO,oBAAoB;IAS/B,YAAY,OAGX;;QANO,wBAAmB,GAAG,KAAK,CAAC;QAC5B,2BAAsB,GAA0B,SAAS,CAAC;QAU1D,YAAO,GAAG,gBAAgB,EAA0B,CAAC;QAS7D,qBAAgB,GAA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C;gBAEH,OAAO,IAAI,gBAAgB,CAAC;oBAC1B,OAAO,EAAE,IAAI;oBACb,KAAK,EAAE,QAAQ;iBAChB,CAAC,CAAC;aACJ;iBAAM;gBACL,OAAO,IAAI,gBAAgB,CAAC;oBAC1B,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,IAAI,aAAa,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;iBAC/C,CAAC,CAAC;aACJ;QACH,CAAC;KAAA;IAEK,oBAAoB,CAAC,OAG1B;;YACC,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC;gBACpC,OAAO,EAAE,IAAI;gBACb,KAAK,EAAE,mBAAmB;aAC3B,CAAC,CAAC;YACH,OAAO,QAAQ,CAAC;QAClB,CAAC;KAAA;IAED,kBAAkB,CAAC,OAGlB;QACC,IAAI,CAAC,yBAAyB,GAAG,OAAO,CAAC;IAC3C,CAAC;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/no-empty-function */\n/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {\n BraintreeManagerEvents,\n BraintreeManagerInterface,\n} from '../../src/braintree-manager/braintree-interfaces';\nimport { PromisedSingleton } from '@internetarchive/promised-singleton';\nimport {\n PaymentProvider,\n DonationPaymentInfo,\n BillingInfo,\n DonationResponse,\n CustomerInfo,\n SuccessResponse,\n ErrorResponse,\n} from '@internetarchive/donation-form-data-models';\nimport { MockPaymentProviders } from './payment-providers/mock-payment-providers';\nimport { mockSuccessResponse } from './models/mock-success-response';\nimport { MockBraintreeClient } from './payment-clients/mock-braintree-client';\nimport { PaymentProvidersInterface } from '../../src/braintree-manager/payment-providers-interface';\nimport { createNanoEvents, Unsubscribe } from 'nanoevents';\n\nexport class MockBraintreeManager implements BraintreeManagerInterface {\n donationSuccessfulOptions?: {\n successResponse: SuccessResponse;\n upsellSuccessResponse?: SuccessResponse | undefined;\n };\n\n private submitDonationError = false;\n private submitDonationResponse: 'success' | 'failure' = 'success';\n\n constructor(options?: {\n submitDonationError?: boolean;\n submitDonationResponse?: 'success' | 'failure';\n }) {\n this.submitDonationError = options?.submitDonationError ?? false;\n this.submitDonationResponse = options?.submitDonationResponse ?? 'success';\n }\n\n private emitter = createNanoEvents<BraintreeManagerEvents>();\n\n on<E extends keyof BraintreeManagerEvents>(\n event: E,\n callback: BraintreeManagerEvents[E],\n ): Unsubscribe {\n return this.emitter.on(event, callback);\n }\n\n paymentProviders: PaymentProvidersInterface = new MockPaymentProviders();\n\n instance = new PromisedSingleton<braintree.Client>({\n generator: (): Promise<braintree.Client> =>\n new Promise(resolve => {\n resolve(new MockBraintreeClient());\n }),\n });\n\n setReferrer(referrer: string): void {}\n\n setLoggedInUser(loggedInUser: string): void {}\n\n setOrigin(origin: string): void {}\n\n startup(): void {}\n\n async submitDonation(options: {\n nonce: string;\n paymentProvider: PaymentProvider;\n donationInfo: DonationPaymentInfo;\n billingInfo: BillingInfo;\n customerInfo: CustomerInfo;\n upsellOnetimeTransactionId?: string | undefined;\n customerId?: string | undefined;\n recaptchaToken?: string | undefined;\n bin?: string | undefined;\n binName?: string | undefined;\n }): Promise<DonationResponse> {\n if (this.submitDonationError) {\n throw 'oh no';\n }\n\n if (this.submitDonationResponse === 'success') {\n const response = new SuccessResponse({\n paymentMethodNonce: options.nonce,\n paymentProvider: options.paymentProvider,\n amount: options.donationInfo.amount,\n donationType: options.donationInfo.donationType,\n transaction_id: 'foo',\n customer_id: 'bar',\n customer: options.customerInfo,\n billing: options.billingInfo,\n });\n\n return new DonationResponse({\n success: true,\n value: response,\n });\n } else {\n return new DonationResponse({\n success: false,\n value: new ErrorResponse({ message: 'error' }),\n });\n }\n }\n\n async submitUpsellDonation(options: {\n oneTimeDonationResponse: SuccessResponse;\n amount: number;\n }): Promise<DonationResponse> {\n const response = new DonationResponse({\n success: true,\n value: mockSuccessResponse,\n });\n return response;\n }\n\n donationSuccessful(options: {\n successResponse: SuccessResponse;\n upsellSuccessResponse?: SuccessResponse | undefined;\n }): void {\n this.donationSuccessfulOptions = options;\n }\n}\n"]}
1
+ {"version":3,"file":"mock-braintree-manager.js","sourceRoot":"","sources":["../../../test/mocks/mock-braintree-manager.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAIL,gBAAgB,EAEhB,eAAe,EACf,aAAa,GACd,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAE9E,OAAO,EAAE,gBAAgB,EAAe,MAAM,YAAY,CAAC;AAE3D,MAAM,OAAO,oBAAoB;IAS/B,YAAY,OAGX;;QANO,wBAAmB,GAAG,KAAK,CAAC;QAC5B,2BAAsB,GAA0B,SAAS,CAAC;QAU1D,YAAO,GAAG,gBAAgB,EAA0B,CAAC;QAS7D,qBAAgB,GAA8B,IAAI,oBAAoB,EAAE,CAAC;QAEzE,aAAQ,GAAG,IAAI,iBAAiB,CAAmB;YACjD,SAAS,EAAE,GAA8B,EAAE,CACzC,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;gBACpB,OAAO,CAAC,IAAI,mBAAmB,EAAE,CAAC,CAAC;YACrC,CAAC,CAAC;SACL,CAAC,CAAC;QApBD,IAAI,CAAC,mBAAmB,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,mBAAmB,mCAAI,KAAK,CAAC;QACjE,IAAI,CAAC,sBAAsB,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,sBAAsB,mCAAI,SAAS,CAAC;IAC7E,CAAC;IAID,EAAE,CACA,KAAQ,EACR,QAAmC;QAEnC,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAWD,WAAW,CAAC,QAAgB,I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esContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {\n BraintreeManagerEvents,\n BraintreeManagerInterface,\n} from '../../src/braintree-manager/braintree-interfaces';\nimport { PromisedSingleton } from '@internetarchive/promised-singleton';\nimport {\n PaymentProvider,\n DonationPaymentInfo,\n BillingInfo,\n DonationResponse,\n CustomerInfo,\n SuccessResponse,\n ErrorResponse,\n} from '@internetarchive/donation-form-data-models';\nimport { MockPaymentProviders } from './payment-providers/mock-payment-providers';\nimport { mockSuccessResponse } from './models/mock-success-response';\nimport { MockBraintreeClient } from './payment-clients/mock-braintree-client';\nimport { PaymentProvidersInterface } from '../../src/braintree-manager/payment-providers-interface';\nimport { createNanoEvents, Unsubscribe } from 'nanoevents';\n\nexport class MockBraintreeManager implements BraintreeManagerInterface {\n donationSuccessfulOptions?: {\n successResponse: SuccessResponse;\n upsellSuccessResponse?: SuccessResponse | undefined;\n };\n\n private submitDonationError = false;\n private submitDonationResponse: 'success' | 'failure' = 'success';\n\n constructor(options?: {\n submitDonationError?: boolean;\n submitDonationResponse?: 'success' | 'failure';\n }) {\n this.submitDonationError = options?.submitDonationError ?? false;\n this.submitDonationResponse = options?.submitDonationResponse ?? 'success';\n }\n\n private emitter = createNanoEvents<BraintreeManagerEvents>();\n\n on<E extends keyof BraintreeManagerEvents>(\n event: E,\n callback: BraintreeManagerEvents[E],\n ): Unsubscribe {\n return this.emitter.on(event, callback);\n }\n\n paymentProviders: PaymentProvidersInterface = new MockPaymentProviders();\n\n instance = new PromisedSingleton<braintree.Client>({\n generator: (): Promise<braintree.Client> =>\n new Promise(resolve => {\n resolve(new MockBraintreeClient());\n }),\n });\n\n setReferrer(referrer: string): void {}\n\n setLoggedInUser(loggedInUser: string): void {}\n\n setOrigin(origin: string): void {}\n\n startup(): void {}\n\n async submitDonation(options: {\n nonce: string;\n paymentProvider: PaymentProvider;\n donationInfo: DonationPaymentInfo;\n billingInfo: BillingInfo;\n customerInfo: CustomerInfo;\n upsellOnetimeTransactionId?: string | undefined;\n customerId?: string | undefined;\n recaptchaToken?: string | undefined;\n bin?: string | undefined;\n binName?: string | undefined;\n }): Promise<DonationResponse> {\n if (this.submitDonationError) {\n throw 'oh no';\n }\n\n if (this.submitDonationResponse === 'success') {\n const response = new SuccessResponse({\n paymentMethodNonce: options.nonce,\n paymentProvider: options.paymentProvider,\n amount: options.donationInfo.amount,\n donationType: options.donationInfo.donationType,\n transaction_id: 'foo',\n customer_id: 'bar',\n customer: options.customerInfo,\n billing: options.billingInfo,\n });\n\n return new DonationResponse({\n success: true,\n value: response,\n });\n } else {\n return new DonationResponse({\n success: false,\n value: new ErrorResponse({ message: 'error' }),\n });\n }\n }\n\n async submitUpsellDonation(options: {\n oneTimeDonationResponse: SuccessResponse;\n amount: number;\n }): Promise<DonationResponse> {\n const response = new DonationResponse({\n success: true,\n value: mockSuccessResponse,\n });\n return response;\n }\n\n donationSuccessful(options: {\n successResponse: SuccessResponse;\n upsellSuccessResponse?: SuccessResponse | undefined;\n }): void {\n this.donationSuccessfulOptions = options;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"mock-lazy-loader.js","sourceRoot":"","sources":["../../../test/mocks/mock-lazy-loader.ts"],"names":[],"mappings":";AAOA,OAAO,EAAE,gBAAgB,EAAe,MAAM,YAAY,CAAC;AAE3D,MAAM,OAAO,cAAc;IAA3B;QACU,YAAO,GAAG,gBAAgB,EAA2B,CAAC;IAuBhE,CAAC;IArBC,EAAE,CACA,KAAQ,EACR,QAAoC;QAEpC,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAEK,UAAU,CAAC,MAGhB;;YACC,OAAO;QACT,CAAC;KAAA;IAEK,UAAU,CAAC,OAIhB;;YACC,OAAO;QACT,CAAC;KAAA;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {\n LazyLoaderServiceEvents,\n LazyLoaderServiceInterface,\n BundleType,\n} from '@internetarchive/lazy-loader-service';\nimport { createNanoEvents, Unsubscribe } from 'nanoevents';\n\nexport class MockLazyLoader implements LazyLoaderServiceInterface {\n private emitter = createNanoEvents<LazyLoaderServiceEvents>();\n\n on<E extends keyof LazyLoaderServiceEvents>(\n event: E,\n callback: LazyLoaderServiceEvents[E],\n ): Unsubscribe {\n return this.emitter.on(event, callback);\n }\n\n async loadBundle(bundle: {\n module?: string | undefined;\n nomodule?: string | undefined;\n }): Promise<void> {\n return;\n }\n\n async loadScript(options: {\n src: string;\n bundleType?: BundleType | undefined;\n attributes?: Record<string, string> | undefined;\n }): Promise<void> {\n return;\n }\n}\n"]}
1
+ {"version":3,"file":"mock-lazy-loader.js","sourceRoot":"","sources":["../../../test/mocks/mock-lazy-loader.ts"],"names":[],"mappings":";AAMA,OAAO,EAAE,gBAAgB,EAAe,MAAM,YAAY,CAAC;AAE3D,MAAM,OAAO,cAAc;IAA3B;QACU,YAAO,GAAG,gBAAgB,EAA2B,CAAC;IAuBhE,CAAC;IArBC,EAAE,CACA,KAAQ,EACR,QAAoC;QAEpC,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAEK,UAAU,CAAC,MAGhB;;YACC,OAAO;QACT,CAAC;KAAA;IAEK,UAAU,CAAC,OAIhB;;YACC,OAAO;QACT,CAAC;KAAA;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport {\n LazyLoaderServiceEvents,\n LazyLoaderServiceInterface,\n BundleType,\n} from '@internetarchive/lazy-loader-service';\nimport { createNanoEvents, Unsubscribe } from 'nanoevents';\n\nexport class MockLazyLoader implements LazyLoaderServiceInterface {\n private emitter = createNanoEvents<LazyLoaderServiceEvents>();\n\n on<E extends keyof LazyLoaderServiceEvents>(\n event: E,\n callback: LazyLoaderServiceEvents[E],\n ): Unsubscribe {\n return this.emitter.on(event, callback);\n }\n\n async loadBundle(bundle: {\n module?: string | undefined;\n nomodule?: string | undefined;\n }): Promise<void> {\n return;\n }\n\n async loadScript(options: {\n src: string;\n bundleType?: BundleType | undefined;\n attributes?: Record<string, string> | undefined;\n }): Promise<void> {\n return;\n }\n}\n"]}
@@ -1,5 +1,4 @@
1
1
  import { __awaiter, __decorate } from "tslib";
2
- /* eslint-disable @typescript-eslint/no-unused-vars */
3
2
  import { ModalManager, ModalManagerMode } from '@internetarchive/modal-manager';
4
3
  import { customElement } from 'lit/decorators.js';
5
4
  let MockModalManager = class MockModalManager extends ModalManager {
@@ -1 +1 @@
1
- {"version":3,"file":"mock-modal-manager.js","sourceRoot":"","sources":["../../../test/mocks/mock-modal-manager.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,OAAO,EAAE,YAAY,EAAe,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAE7F,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAG3C,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,YAAY;IAA3C;;QACL,gBAAW,GAAG,KAAK,CAAC;IAuBtB,CAAC;IAhBC,UAAU;QACR,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAED,OAAO;QACL,OAAO,gBAAgB,CAAC,MAAM,CAAC;IACjC,CAAC;IAEK,SAAS,CAAC,OAIf;;YACC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC;YAChC,OAAO;QACT,CAAC;KAAA;CACF,CAAA;AAxBY,gBAAgB;IAD5B,aAAa,CAAC,oBAAoB,CAAC;GACvB,gBAAgB,CAwB5B;SAxBY,gBAAgB","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { ModalManager, ModalConfig, ModalManagerMode } from '@internetarchive/modal-manager';\nimport { TemplateResult } from 'lit';\nimport { customElement } from 'lit/decorators.js';\n\n@customElement('mock-modal-manager')\nexport class MockModalManager extends ModalManager {\n closeCalled = false;\n showModalOptions?: {\n config: ModalConfig;\n customModalContent?: TemplateResult;\n userClosedModalCallback?: () => void;\n };\n\n closeModal(): void {\n this.closeCalled = true;\n }\n\n getMode(): ModalManagerMode {\n return ModalManagerMode.Closed;\n }\n\n async showModal(options: {\n config: ModalConfig;\n customModalContent?: TemplateResult;\n userClosedModalCallback?: () => void;\n }): Promise<void> {\n this.showModalOptions = options;\n return;\n }\n}\n"]}
1
+ {"version":3,"file":"mock-modal-manager.js","sourceRoot":"","sources":["../../../test/mocks/mock-modal-manager.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAe,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAE7F,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAG3C,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,YAAY;IAA3C;;QACL,gBAAW,GAAG,KAAK,CAAC;IAuBtB,CAAC;IAhBC,UAAU;QACR,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAED,OAAO;QACL,OAAO,gBAAgB,CAAC,MAAM,CAAC;IACjC,CAAC;IAEK,SAAS,CAAC,OAIf;;YACC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC;YAChC,OAAO;QACT,CAAC;KAAA;CACF,CAAA;AAxBY,gBAAgB;IAD5B,aAAa,CAAC,oBAAoB,CAAC;GACvB,gBAAgB,CAwB5B","sourcesContent":["import { ModalManager, ModalConfig, ModalManagerMode } from '@internetarchive/modal-manager';\nimport { TemplateResult } from 'lit';\nimport { customElement } from 'lit/decorators.js';\n\n@customElement('mock-modal-manager')\nexport class MockModalManager extends ModalManager {\n closeCalled = false;\n showModalOptions?: {\n config: ModalConfig;\n customModalContent?: TemplateResult;\n userClosedModalCallback?: () => void;\n };\n\n closeModal(): void {\n this.closeCalled = true;\n }\n\n getMode(): ModalManagerMode {\n return ModalManagerMode.Closed;\n }\n\n async showModal(options: {\n config: ModalConfig;\n customModalContent?: TemplateResult;\n userClosedModalCallback?: () => void;\n }): Promise<void> {\n this.showModalOptions = options;\n return;\n }\n}\n"]}
@@ -1,5 +1,3 @@
1
- /// <reference types="googlepay" />
2
- /// <reference types="grecaptcha" />
3
1
  import { PaymentClientsInterface } from '../../src/braintree-manager/payment-clients';
4
2
  import { PromisedSingleton } from '@internetarchive/promised-singleton';
5
3
  export declare class MockPaymentClients implements PaymentClientsInterface {
@@ -70,7 +70,6 @@ export class MockPaymentClients {
70
70
  resolve(mockGooglePayLibrary);
71
71
  }),
72
72
  });
73
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
74
73
  this.paypalLibrary =
75
74
  (_j = generators === null || generators === void 0 ? void 0 : generators.paypalLibrary) !== null && _j !== void 0 ? _j : new PromisedSingleton({
76
75
  generator: () => new Promise((resolve, reject) => {
@@ -1 +1 @@
1
- {"version":3,"file":"mock-payment-clients.js","sourceRoot":"","sources":["../../../test/mocks/mock-payment-clients.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAE1E,MAAM,OAAO,kBAAkB;IACvB,wBAAwB,CAAC,KAAc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AAO,EAAE,MAAM,EAAE,EAAE;oBAC9B,MAAM,oBAAoB,GAAG,IAAI,oBAAoB,EAAE,CAAC;oBACxD,oBAAoB,CAAC,UAAU,GAAG,IAAI,CAAC;oBACvC,OAAO,CAAC,oBAAoB,CAAC,CAAC;gBAChC,CAAC,CAAC;aACL,CAAC,CAAC;QACL,8DAA8D;QAC9D,IAAI,CAAC,aAAa;YAChB,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,aAAa,mCACzB,IAAI,iBAAiB,CAAM;gBACzB,SAAS,EAAE,GAAiB,EAAE,CAC5B,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;oBAC9B,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,EAAE,CAAC;oBAClD,OAAO,CAAC,iBAAiB,CAAC,CAAC;gBAC7B,CAAC,CAAC;aACL,CAAC,CAAC;QACL,IAAI,CAAC,gBAAgB;YACnB,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,gBAAgB,mCAC5B,IAAI,iBAAiB,CAAwB;gBAC3C,SAAS,EAAE,GAAmC,EAAE,CAC9C,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;oBAC9B,OAAO,CAAC,IAAI,cAAc,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;gBAC1D,CAAC,CAAC;aACL,CAAC,CAAC;IACP,CAAC;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { PaymentClientsInterface } from '../../src/braintree-manager/payment-clients';\nimport { PromisedSingleton } from '@internetarchive/promised-singleton';\nimport { MockBraintreeClient } from './payment-clients/mock-braintree-client';\nimport { MockDeviceDataCollector } from './payment-clients/mock-data-collector';\nimport { MockHostedFieldsClient } from './payment-clients/mock-hostedfields-client';\nimport { MockVenmoClient } from './payment-clients/mock-venmo-client';\nimport { MockPayPalClient } from './payment-clients/mock-paypal-client';\nimport { MockApplePayClient } from './payment-clients/mock-applepay-client';\nimport { MockGooglePaymentClient } from './payment-clients/mock-googlepay-client';\nimport { MockGooglePayLibrary } from './payment-clients/mock-googlepay-library';\nimport { MockGrecaptcha, MockGrecaptchaMode } from './payment-clients/mock-grecaptcha';\nimport { MockPaypalLibrary } from './payment-clients/mock-paypal-library';\n\nexport class MockPaymentClients implements PaymentClientsInterface {\n async emitValidityChangedEvent(valid: boolean): Promise<void> {\n const hostedFields = (await this.hostedFields.get()) as MockHostedFieldsClient;\n hostedFields.emitValidityChangedEvent(valid);\n }\n\n braintreeClient: PromisedSingleton<braintree.Client>;\n dataCollector: PromisedSingleton<braintree.DataCollector>;\n hostedFields: PromisedSingleton<braintree.HostedFields>;\n venmo: PromisedSingleton<braintree.Venmo>;\n payPal: PromisedSingleton<braintree.PayPalCheckout>;\n applePay: PromisedSingleton<braintree.ApplePay>;\n googlePayBraintreeClient: PromisedSingleton<braintree.GooglePayment>;\n googlePaymentsClient: PromisedSingleton<google.payments.api.PaymentsClient>;\n paypalLibrary: PromisedSingleton<any>;\n recaptchaLibrary: PromisedSingleton<ReCaptchaV2.ReCaptcha>;\n\n constructor(generators?: {\n client?: PromisedSingleton<braintree.Client>;\n dataCollector?: PromisedSingleton<braintree.DataCollector>;\n hostedFields?: PromisedSingleton<braintree.HostedFields>;\n venmo?: PromisedSingleton<braintree.Venmo>;\n payPal?: PromisedSingleton<braintree.PayPalCheckout>;\n applePay?: PromisedSingleton<braintree.ApplePay>;\n googlePayBraintreeClient?: PromisedSingleton<braintree.GooglePayment>;\n googlePaymentsClient?: PromisedSingleton<google.payments.api.PaymentsClient>;\n paypalLibrary?: PromisedSingleton<any>;\n recaptchaLibrary?: PromisedSingleton<ReCaptchaV2.ReCaptcha>;\n }) {\n this.braintreeClient =\n generators?.client ??\n new PromisedSingleton<braintree.Client>({\n generator: (): Promise<braintree.Client> =>\n new Promise((resolve, reject) => {\n resolve(new MockBraintreeClient());\n }),\n });\n this.dataCollector =\n generators?.dataCollector ??\n new PromisedSingleton<braintree.DataCollector>({\n generator: (): Promise<braintree.DataCollector> =>\n new Promise((resolve, reject) => {\n resolve(new MockDeviceDataCollector());\n }),\n });\n this.hostedFields =\n generators?.hostedFields ??\n new PromisedSingleton<braintree.HostedFields>({\n generator: (): Promise<braintree.HostedFields> =>\n new Promise((resolve, reject) => {\n const client = new MockHostedFieldsClient();\n resolve(client);\n }),\n });\n this.venmo =\n generators?.venmo ??\n new PromisedSingleton<braintree.Venmo>({\n generator: (): Promise<braintree.Venmo> =>\n new Promise((resolve, reject) => {\n resolve(new MockVenmoClient({ isBrowserSupported: true }));\n }),\n });\n this.payPal =\n generators?.payPal ??\n new PromisedSingleton<braintree.PayPalCheckout>({\n generator: (): Promise<braintree.PayPalCheckout> =>\n new Promise((resolve, reject) => {\n resolve(new MockPayPalClient());\n }),\n });\n this.applePay =\n generators?.applePay ??\n new PromisedSingleton<braintree.ApplePay>({\n generator: (): Promise<braintree.ApplePay> =>\n new Promise((resolve, reject) => {\n resolve(new MockApplePayClient());\n }),\n });\n this.googlePayBraintreeClient =\n generators?.googlePayBraintreeClient ??\n new PromisedSingleton<braintree.GooglePayment>({\n generator: (): Promise<braintree.GooglePayment> =>\n new Promise((resolve, reject) => {\n resolve(new MockGooglePaymentClient());\n }),\n });\n this.googlePaymentsClient =\n generators?.googlePaymentsClient ??\n new PromisedSingleton<google.payments.api.PaymentsClient>({\n generator: (): Promise<google.payments.api.PaymentsClient> =>\n new Promise((resolve, reject) => {\n const mockGooglePayLibrary = new MockGooglePayLibrary();\n mockGooglePayLibrary.readyToPay = true;\n resolve(mockGooglePayLibrary);\n }),\n });\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.paypalLibrary =\n generators?.paypalLibrary ??\n new PromisedSingleton<any>({\n generator: (): Promise<any> =>\n new Promise((resolve, reject) => {\n const mockPayPalLibrary = new MockPaypalLibrary();\n resolve(mockPayPalLibrary);\n }),\n });\n this.recaptchaLibrary =\n generators?.recaptchaLibrary ??\n new PromisedSingleton<ReCaptchaV2.ReCaptcha>({\n generator: (): Promise<ReCaptchaV2.ReCaptcha> =>\n new Promise((resolve, reject) => {\n resolve(new MockGrecaptcha(MockGrecaptchaMode.Success));\n }),\n });\n }\n}\n"]}
1
+ {"version":3,"file":"mock-payment-clients.js","sourceRoot":"","sources":["../../../test/mocks/mock-payment-clients.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAE1E,MAAM,OAAO,kBAAkB;IACvB,wBAAwB,CAAC,KAAc;;YAC3C,MAAM,YAAY,GAAG,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAA2B,CAAC;YAC/E,YAAY,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC;QAC/C,CAAC;KAAA;IAaD,YAAY,UAWX;;QACC,IAAI,CAAC,eAAe;YAClB,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,mCAClB,IAAI,iBAAiB,CAAmB;gBACtC,SAAS,EAAE,GAA8B,EAAE,CACzC,I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EAAE,GAAiB,EAAE,CAC5B,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;oBAC9B,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,EAAE,CAAC;oBAClD,OAAO,CAAC,iBAAiB,CAAC,CAAC;gBAC7B,CAAC,CAAC;aACL,CAAC,CAAC;QACL,IAAI,CAAC,gBAAgB;YACnB,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,gBAAgB,mCAC5B,IAAI,iBAAiB,CAAwB;gBAC3C,SAAS,EAAE,GAAmC,EAAE,CAC9C,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;oBAC9B,OAAO,CAAC,IAAI,cAAc,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;gBAC1D,CAAC,CAAC;aACL,CAAC,CAAC;IACP,CAAC;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { PaymentClientsInterface } from '../../src/braintree-manager/payment-clients';\nimport { PromisedSingleton } from '@internetarchive/promised-singleton';\nimport { MockBraintreeClient } from './payment-clients/mock-braintree-client';\nimport { MockDeviceDataCollector } from './payment-clients/mock-data-collector';\nimport { MockHostedFieldsClient } from './payment-clients/mock-hostedfields-client';\nimport { MockVenmoClient } from './payment-clients/mock-venmo-client';\nimport { MockPayPalClient } from './payment-clients/mock-paypal-client';\nimport { MockApplePayClient } from './payment-clients/mock-applepay-client';\nimport { MockGooglePaymentClient } from './payment-clients/mock-googlepay-client';\nimport { MockGooglePayLibrary } from './payment-clients/mock-googlepay-library';\nimport { MockGrecaptcha, MockGrecaptchaMode } from './payment-clients/mock-grecaptcha';\nimport { MockPaypalLibrary } from './payment-clients/mock-paypal-library';\n\nexport class MockPaymentClients implements PaymentClientsInterface {\n async emitValidityChangedEvent(valid: boolean): Promise<void> {\n const hostedFields = (await this.hostedFields.get()) as MockHostedFieldsClient;\n hostedFields.emitValidityChangedEvent(valid);\n }\n\n braintreeClient: PromisedSingleton<braintree.Client>;\n dataCollector: PromisedSingleton<braintree.DataCollector>;\n hostedFields: PromisedSingleton<braintree.HostedFields>;\n venmo: PromisedSingleton<braintree.Venmo>;\n payPal: PromisedSingleton<braintree.PayPalCheckout>;\n applePay: PromisedSingleton<braintree.ApplePay>;\n googlePayBraintreeClient: PromisedSingleton<braintree.GooglePayment>;\n googlePaymentsClient: PromisedSingleton<google.payments.api.PaymentsClient>;\n paypalLibrary: PromisedSingleton<any>;\n recaptchaLibrary: PromisedSingleton<ReCaptchaV2.ReCaptcha>;\n\n constructor(generators?: {\n client?: PromisedSingleton<braintree.Client>;\n dataCollector?: PromisedSingleton<braintree.DataCollector>;\n hostedFields?: PromisedSingleton<braintree.HostedFields>;\n venmo?: PromisedSingleton<braintree.Venmo>;\n payPal?: PromisedSingleton<braintree.PayPalCheckout>;\n applePay?: PromisedSingleton<braintree.ApplePay>;\n googlePayBraintreeClient?: PromisedSingleton<braintree.GooglePayment>;\n googlePaymentsClient?: PromisedSingleton<google.payments.api.PaymentsClient>;\n paypalLibrary?: PromisedSingleton<any>;\n recaptchaLibrary?: PromisedSingleton<ReCaptchaV2.ReCaptcha>;\n }) {\n this.braintreeClient =\n generators?.client ??\n new PromisedSingleton<braintree.Client>({\n generator: (): Promise<braintree.Client> =>\n new Promise((resolve, reject) => {\n resolve(new MockBraintreeClient());\n }),\n });\n this.dataCollector =\n generators?.dataCollector ??\n new PromisedSingleton<braintree.DataCollector>({\n generator: (): Promise<braintree.DataCollector> =>\n new Promise((resolve, reject) => {\n resolve(new MockDeviceDataCollector());\n }),\n });\n this.hostedFields =\n generators?.hostedFields ??\n new PromisedSingleton<braintree.HostedFields>({\n generator: (): Promise<braintree.HostedFields> =>\n new Promise((resolve, reject) => {\n const client = new MockHostedFieldsClient();\n resolve(client);\n }),\n });\n this.venmo =\n generators?.venmo ??\n new PromisedSingleton<braintree.Venmo>({\n generator: (): Promise<braintree.Venmo> =>\n new Promise((resolve, reject) => {\n resolve(new MockVenmoClient({ isBrowserSupported: true }));\n }),\n });\n this.payPal =\n generators?.payPal ??\n new PromisedSingleton<braintree.PayPalCheckout>({\n generator: (): Promise<braintree.PayPalCheckout> =>\n new Promise((resolve, reject) => {\n resolve(new MockPayPalClient());\n }),\n });\n this.applePay =\n generators?.applePay ??\n new PromisedSingleton<braintree.ApplePay>({\n generator: (): Promise<braintree.ApplePay> =>\n new Promise((resolve, reject) => {\n resolve(new MockApplePayClient());\n }),\n });\n this.googlePayBraintreeClient =\n generators?.googlePayBraintreeClient ??\n new PromisedSingleton<braintree.GooglePayment>({\n generator: (): Promise<braintree.GooglePayment> =>\n new Promise((resolve, reject) => {\n resolve(new MockGooglePaymentClient());\n }),\n });\n this.googlePaymentsClient =\n generators?.googlePaymentsClient ??\n new PromisedSingleton<google.payments.api.PaymentsClient>({\n generator: (): Promise<google.payments.api.PaymentsClient> =>\n new Promise((resolve, reject) => {\n const mockGooglePayLibrary = new MockGooglePayLibrary();\n mockGooglePayLibrary.readyToPay = true;\n resolve(mockGooglePayLibrary);\n }),\n });\n\n this.paypalLibrary =\n generators?.paypalLibrary ??\n new PromisedSingleton<any>({\n generator: (): Promise<any> =>\n new Promise((resolve, reject) => {\n const mockPayPalLibrary = new MockPaypalLibrary();\n resolve(mockPayPalLibrary);\n }),\n });\n this.recaptchaLibrary =\n generators?.recaptchaLibrary ??\n new PromisedSingleton<ReCaptchaV2.ReCaptcha>({\n generator: (): Promise<ReCaptchaV2.ReCaptcha> =>\n new Promise((resolve, reject) => {\n resolve(new MockGrecaptcha(MockGrecaptchaMode.Success));\n }),\n });\n }\n}\n"]}
@@ -1,4 +1,3 @@
1
- /// <reference types="grecaptcha" />
2
1
  import { RecaptchaManagerInterface } from '../../src/recaptcha-manager/recaptcha-manager';
3
2
  export declare class MockRecaptchaManager implements RecaptchaManagerInterface {
4
3
  setupCalled: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"mock-applepay-client.js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C;IAEK,QAAQ,CAAC,OAAuB,EAAE,QAA6B;;YACnE,IAAI,IAAI,CAAC,0BAA0B,EAAE;gBACnC,IAAI,QAAQ,EAAE;oBACZ,QAAQ,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;iBACrC;qBAAM;oBACL,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;iBACvB;aACF;iBAAM;gBACL,MAAM,KAAK,GAA6B;oBACtC,IAAI,EAAE,KAAK;oBACX,OAAO,EAAE,KAAK;oBACd,IAAI,EAAE,UAAU;oBAChB,OAAO,EAAE,SAAS;iBACnB,CAAC;gBACF,IAAI,QAAQ,EAAE;oBACZ,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;iBAC5B;qBAAM;oBACL,MAAM,KAAK,CAAC;iBACb;aACF;QACH,CAAC;KAAA;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unused-vars */\nexport class MockApplePayClient implements braintree.ApplePay {\n private shouldValidateMerchant = true;\n private shouldTokenizeSuccessfully = true;\n\n constructor(options?: {\n shouldValidateMerchant?: boolean;\n shouldTokenizeSuccessfully?: boolean;\n }) {\n this.shouldValidateMerchant = options?.shouldValidateMerchant ?? true;\n this.shouldTokenizeSuccessfully = options?.shouldTokenizeSuccessfully ?? true;\n }\n\n async create(options: { client: braintree.Client }): Promise<braintree.ApplePay> {\n return this;\n }\n\n VERSION = 'foo';\n\n createPaymentRequest(\n paymentRequest: braintree.ApplePayPaymentRequest,\n ): braintree.ApplePayPaymentRequest {\n return {\n total: {\n label: 'Foo Donation',\n amount: '3.50',\n },\n countryCode: 'US',\n currencyCode: 'USD',\n supportedNetworks: ['Foo', 'Bar'],\n merchantCapabilities: [],\n\n requiredBillingContactFields: ['postalAddress'],\n requiredShippingContactFields: ['name', 'email'],\n };\n }\n\n performValidation(\n options: {\n validationURL: string;\n displayName?: string | undefined;\n merchantIdentifier?: string | undefined;\n },\n callback: braintree.callback,\n ): void {\n if (this.shouldValidateMerchant) {\n callback(undefined, { foo: 'bar' });\n } else {\n const error: braintree.BraintreeError = {\n code: 'foo',\n message: 'bar',\n type: 'CUSTOMER',\n details: 'foo bar',\n };\n callback(error, undefined);\n }\n }\n\n async tokenize(options: { token: any }, callback?: braintree.callback): Promise<any> {\n if (this.shouldTokenizeSuccessfully) {\n if (callback) {\n callback(undefined, { foo: 'bar' });\n } else {\n return { foo: 'bar' };\n }\n } else {\n const error: braintree.BraintreeError = {\n code: 'foo',\n message: 'bar',\n type: 'CUSTOMER',\n details: 'foo bar',\n };\n if (callback) {\n callback(error, undefined);\n } else {\n throw error;\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"mock-applepay-client.js","sourceRoot":"","sources":["../../../../test/mocks/payment-clients/mock-applepay-client.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,sDAAsD;AACtD,MAAM,OAAO,kBAAkB;IAI7B,YAAY,OAGX;;QANO,2BAAsB,GAAG,IAAI,CAAC;QAC9B,+BAA0B,GAAG,IAAI,CAAC;QAc1C,YAAO,GAAG,KAAK,CAAC;QARd,IAAI,CAAC,sBAAsB,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,sBAAsB,mCAAI,IAAI,CAAC;QACtE,IAAI,CAAC,0BAA0B,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,0BAA0B,mCAAI,IAAI,CAAC;IAChF,CAAC;IAEK,MAAM,CAAC,OAAqC;;YAChD,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;IAID,oBAAoB,CAClB,cAAgD;QAEhD,OAAO;YACL,KAAK,EAAE;gBACL,KAAK,EAAE,cAAc;gBACrB,MAAM,EAAE,MAAM;aACf;YACD,WAAW,EAAE,IAAI;YACjB,YAAY,EAAE,KAAK;YACnB,iBAAiB,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;YACjC,oBAAoB,EAAE,EAAE;YAExB,4BAA4B,EAAE,CAAC,eAAe,CAAC;YAC/C,6BAA6B,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;SACjD,CAAC;IACJ,CAAC;IAED,iBAAiB,CACf,OAIC,EACD,QAA4B;QAE5B,IAAI,IAAI,CAAC,sBAAsB,EAAE,CAAC;YAChC,QAAQ,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;QACtC,CAAC;aAAM,CAAC;YACN,MAAM,KAAK,GAA6B;gBACtC,IAAI,EAAE,KAAK;gBACX,OAAO,EAAE,KAAK;gBACd,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,SAAS;aACnB,CAAC;YACF,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAEK,QAAQ,CAAC,OAAuB,EAAE,QAA6B;;YACnE,IAAI,IAAI,CAAC,0BAA0B,EAAE,CAAC;gBACpC,IAAI,QAAQ,EAAE,CAAC;oBACb,QAAQ,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;gBACtC,CAAC;qBAAM,CAAC;oBACN,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;gBACxB,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,MAAM,KAAK,GAA6B;oBACtC,IAAI,EAAE,KAAK;oBACX,OAAO,EAAE,KAAK;oBACd,IAAI,EAAE,UAAU;oBAChB,OAAO,EAAE,SAAS;iBACnB,CAAC;gBACF,IAAI,QAAQ,EAAE,CAAC;oBACb,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;gBAC7B,CAAC;qBAAM,CAAC;oBACN,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC;KAAA;CACF","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unused-vars */\nexport class MockApplePayClient implements braintree.ApplePay {\n private shouldValidateMerchant = true;\n private shouldTokenizeSuccessfully = true;\n\n constructor(options?: {\n shouldValidateMerchant?: boolean;\n shouldTokenizeSuccessfully?: boolean;\n }) {\n this.shouldValidateMerchant = options?.shouldValidateMerchant ?? true;\n this.shouldTokenizeSuccessfully = options?.shouldTokenizeSuccessfully ?? true;\n }\n\n async create(options: { client: braintree.Client }): Promise<braintree.ApplePay> {\n return this;\n }\n\n VERSION = 'foo';\n\n createPaymentRequest(\n paymentRequest: braintree.ApplePayPaymentRequest,\n ): braintree.ApplePayPaymentRequest {\n return {\n total: {\n label: 'Foo Donation',\n amount: '3.50',\n },\n countryCode: 'US',\n currencyCode: 'USD',\n supportedNetworks: ['Foo', 'Bar'],\n merchantCapabilities: [],\n\n requiredBillingContactFields: ['postalAddress'],\n requiredShippingContactFields: ['name', 'email'],\n };\n }\n\n performValidation(\n options: {\n validationURL: string;\n displayName?: string | undefined;\n merchantIdentifier?: string | undefined;\n },\n callback: braintree.callback,\n ): void {\n if (this.shouldValidateMerchant) {\n callback(undefined, { foo: 'bar' });\n } else {\n const error: braintree.BraintreeError = {\n code: 'foo',\n message: 'bar',\n type: 'CUSTOMER',\n details: 'foo bar',\n };\n callback(error, undefined);\n }\n }\n\n async tokenize(options: { token: any }, callback?: braintree.callback): Promise<any> {\n if (this.shouldTokenizeSuccessfully) {\n if (callback) {\n callback(undefined, { foo: 'bar' });\n } else {\n return { foo: 'bar' };\n }\n } else {\n const error: braintree.BraintreeError = {\n code: 'foo',\n message: 'bar',\n type: 'CUSTOMER',\n details: 'foo bar',\n };\n if (callback) {\n callback(error, undefined);\n } else {\n throw error;\n }\n }\n }\n}\n"]}
@@ -1,4 +1,3 @@
1
- /// <reference types="applepayjs" />
2
1
  export declare class MockApplePayPayment implements ApplePayJS.ApplePayPayment {
3
2
  token: ApplePayJS.ApplePayPaymentToken;
4
3
  billingContact?: ApplePayJS.ApplePayPaymentContact | undefined;
@@ -1,4 +1,3 @@
1
- /// <reference types="applepayjs" />
2
1
  export declare class MockApplePayPaymentAuthorizedEvent implements ApplePayJS.ApplePayPaymentAuthorizedEvent {
3
2
  payment: ApplePayJS.ApplePayPayment;
4
3
  bubbles: boolean;
@@ -1,4 +1,3 @@
1
- /// <reference types="applepayjs" />
2
1
  export declare class MockApplePaySession implements ApplePaySession {
3
2
  versionCheck: number;
4
3
  paymentRequestCheck?: ApplePayJS.ApplePayPaymentRequest;
@@ -1,5 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-empty-function */
2
- /* eslint-disable @typescript-eslint/explicit-function-return-type */
3
1
  /* eslint-disable @typescript-eslint/no-unused-vars */
4
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
5
3
  export class MockApplePaySession {