@internetarchive/donation-monthly-portal 7.7.1 → 7.7.2

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.
@@ -40,6 +40,8 @@ export declare class MGCBraintreeManager extends LitElement {
40
40
  renderPayPalVaultButton(): Promise<void>;
41
41
  private handlePayPalAuthorized;
42
42
  startVenmoPayment(): Promise<void>;
43
+ startGooglePayPayment(): Promise<void>;
44
+ startApplePayPayment(originalEvent: Event): Promise<void>;
43
45
  private checkVenmoRestoration;
44
46
  private setupBraintreeManager;
45
47
  get contactForm(): HTMLFormElement | null;
@@ -268,6 +268,123 @@ let MGCBraintreeManager = class MGCBraintreeManager extends LitElement {
268
268
  }
269
269
  }
270
270
  }
271
+ async startGooglePayPayment() {
272
+ var _a, _b, _c;
273
+ const handler = await ((_a = this.braintreeManager) === null || _a === void 0 ? void 0 : _a.paymentProviders.googlePayHandler.get());
274
+ if (!handler)
275
+ return;
276
+ try {
277
+ const instance = await handler.instance.get();
278
+ if (!instance)
279
+ return;
280
+ const paymentDataRequest = await instance.createPaymentDataRequest({
281
+ emailRequired: true,
282
+ transactionInfo: {
283
+ currencyCode: 'USD',
284
+ totalPriceStatus: 'FINAL',
285
+ totalPrice: `${(_c = (_b = this.plan) === null || _b === void 0 ? void 0 : _b.amount) !== null && _c !== void 0 ? _c : 0}`,
286
+ },
287
+ });
288
+ const paymentData = await handler.paymentsClient.loadPaymentData(paymentDataRequest);
289
+ const payload = await instance.parseResponse(paymentData);
290
+ this.dispatchEvent(new CustomEvent('GooglePayVaultAuthorized', {
291
+ detail: {
292
+ paymentMethodInfo: {
293
+ description: `Google Pay - ${payload.details.cardType} - ${payload.details.lastFour}`,
294
+ nonce: payload.nonce,
295
+ type: payload.type,
296
+ details: {
297
+ cardType: payload.details.cardType,
298
+ lastFour: payload.details.lastFour,
299
+ },
300
+ },
301
+ },
302
+ }));
303
+ }
304
+ catch (e) {
305
+ const statusCode = e === null || e === void 0 ? void 0 : e.statusCode;
306
+ if (statusCode === 'CANCELED') {
307
+ console.log('Google Pay payment cancelled');
308
+ }
309
+ else {
310
+ console.error('Google Pay payment error:', e);
311
+ this.dispatchEvent(new CustomEvent('GooglePayError', { detail: { error: e } }));
312
+ }
313
+ }
314
+ }
315
+ // In order to trigger the Apple Pay flow, you HAVE to call this from
316
+ // directly within the user-gesture handler that produced `originalEvent`
317
+ // (Safari requires this). Notice we're not actually using the event itself.
318
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
319
+ async startApplePayPayment(originalEvent) {
320
+ var _a, _b, _c;
321
+ const handler = await ((_a = this.braintreeManager) === null || _a === void 0 ? void 0 : _a.paymentProviders.applePayHandler.get());
322
+ if (!handler)
323
+ return;
324
+ try {
325
+ const applePayInstance = await handler.instance.get();
326
+ if (!applePayInstance)
327
+ return;
328
+ const paymentRequest = applePayInstance.createPaymentRequest({
329
+ total: {
330
+ label: 'Internet Archive Monthly',
331
+ amount: `${(_c = (_b = this.plan) === null || _b === void 0 ? void 0 : _b.amount) !== null && _c !== void 0 ? _c : 0}`,
332
+ },
333
+ requiredBillingContactFields: ['postalAddress'],
334
+ });
335
+ const session = new ApplePaySession(3, paymentRequest);
336
+ session.onvalidatemerchant = (event) => {
337
+ applePayInstance.performValidation({
338
+ validationURL: event.validationURL,
339
+ displayName: 'Internet Archive',
340
+ }, (validationErr, validationData) => {
341
+ if (validationErr) {
342
+ console.error('Apple Pay merchant validation error:', validationErr);
343
+ session.abort();
344
+ this.dispatchEvent(new CustomEvent('ApplePayError', {
345
+ detail: { error: validationErr },
346
+ }));
347
+ return;
348
+ }
349
+ session.completeMerchantValidation(validationData);
350
+ });
351
+ };
352
+ session.onpaymentauthorized = async (event) => {
353
+ try {
354
+ const payload = await applePayInstance.tokenize({
355
+ token: event.payment.token,
356
+ });
357
+ session.completePayment(ApplePaySession.STATUS_SUCCESS);
358
+ this.dispatchEvent(new CustomEvent('ApplePayVaultAuthorized', {
359
+ detail: {
360
+ paymentMethodInfo: {
361
+ description: `Apple Pay - ${payload.details.cardType} - ${payload.details.dpanLastTwo}`,
362
+ nonce: payload.nonce,
363
+ type: payload.type,
364
+ details: {
365
+ cardType: payload.details.cardType,
366
+ lastTwo: payload.details.dpanLastTwo,
367
+ },
368
+ },
369
+ },
370
+ }));
371
+ }
372
+ catch (e) {
373
+ session.completePayment(ApplePaySession.STATUS_FAILURE);
374
+ console.error('Apple Pay tokenization error:', e);
375
+ this.dispatchEvent(new CustomEvent('ApplePayError', { detail: { error: e } }));
376
+ }
377
+ };
378
+ session.oncancel = () => {
379
+ console.log('Apple Pay payment cancelled');
380
+ };
381
+ session.begin();
382
+ }
383
+ catch (e) {
384
+ console.error('Apple Pay error:', e);
385
+ this.dispatchEvent(new CustomEvent('ApplePayError', { detail: { error: e } }));
386
+ }
387
+ }
271
388
  async checkVenmoRestoration() {
272
389
  var _a, _b, _c, _d, _e, _f, _g;
273
390
  const planId = (_a = this.plan) === null || _a === void 0 ? void 0 : _a.id;
@@ -1 +1 @@
1
- {"version":3,"file":"braintree-manager.js","sourceRoot":"","sources":["../../../../src/form-sections/parts/braintree-manager.ts"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAA+B,MAAM,KAAK,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EACL,oBAAoB,EACpB,eAAe,GAChB,MAAM,gHAAgH,CAAC;AACxH,OAAO,EACL,gBAAgB,GAGjB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,mBAAmB,EACnB,YAAY,GACb,MAAM,4CAA4C,CAAC;AAIpD,OAAO,aAAa,MAAM,4CAA4C,CAAC;AACvE,OAAO,WAAW,MAAM,yCAAyC,CAAC;AAClE,OAAO,OAAO,MAAM,qCAAqC,CAAC;AAiBnD,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,UAAU;I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AAA,IAAI,CAAC,aAAa,0CAAE,mBAAmB,CAAA,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtE,sEAAsE;YACtE,uEAAuE;YACvE,mEAAmE;YACnE,0EAA0E;YAC1E,8DAA8D;YAC7D,IAAI,CAAC,gBAAgB,CAAC,gBAAwB,CAAC,gBAAgB,GAAG;gBACjE,GAAG,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI;aACtB,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,CAAC,qBAAqB,EAAE,CAAC;QACnC,IAAI,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,aAAa,CAAC,2BAA2B,CAAC,CAAC;IACzD,CAAC;CACF,CAAA;AAvc6B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;iDAAoB;AAEH;IAA3C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;8DACnC;AAEoB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wDAA0B;AAEzB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;0DAA+B;AAE9B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;6DAA8C;AAExD;IAAhB,KAAK,EAAE;6DAA2C;AAEvB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gEAA2C;AAd3D,mBAAmB;IAD/B,aAAa,CAAC,0BAA0B,CAAC;GAC7B,mBAAmB,CAwc/B","sourcesContent":["/* eslint-disable no-console */\nimport { LitElement, html, css, CSSResult, PropertyValueMap } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\n\nimport {\n HostedFieldContainer,\n HostedFieldName,\n} from '@internetarchive/donation-form/dist/src/braintree-manager/payment-providers/credit-card/hosted-field-container';\nimport {\n BraintreeManager,\n BraintreeManagerInterface,\n HostingEnvironment,\n} from '@internetarchive/donation-form';\nimport {\n DonationPaymentInfo,\n DonationType,\n} from '@internetarchive/donation-form-data-models';\nimport type { BraintreeEndpointManagerInterface } from '@internetarchive/donation-form/dist/src/braintree-manager/braintree-interfaces.js';\nimport type { PaymentClientsInterface } from '@internetarchive/donation-form/dist/src/braintree-manager/payment-clients.js';\n\nimport creditCardImg from '@internetarchive/icon-credit-card/index.js';\nimport calendarImg from '@internetarchive/icon-calendar/index.js';\nimport lockImg from '@internetarchive/icon-lock/index.js';\nimport { VenmoPendingStorage } from '../../utils/venmo-pending-storage';\n\nimport type { MonthlyPlan } from '../../models/plan';\n\nexport type PaymentConfig = {\n braintreeAuthToken?: string;\n endpointManager?: BraintreeEndpointManagerInterface;\n paymentClients?: PaymentClientsInterface;\n environment?: HostingEnvironment;\n venmoProfileId?: string;\n googlePayMerchantId?: string;\n referrer: string;\n origin: string;\n};\n\n@customElement('ia-mgc-braintree-manager')\nexport class MGCBraintreeManager extends LitElement {\n @property({ type: Object }) plan?: MonthlyPlan;\n\n @property({ type: Boolean, reflect: true }) displayCreditCard: boolean =\n false;\n\n @property({ type: String }) patronEmail: string = '';\n\n @property({ type: Object }) paymentConfig?: PaymentConfig;\n\n @property({ type: Object }) braintreeManager?: BraintreeManagerInterface;\n\n @state() private elementConnected: boolean = false;\n\n @property({ type: Object }) venmoPendingStorage?: VenmoPendingStorage;\n\n get braintreeInputs(): {\n errorMessage: HTMLDivElement | null;\n number: HTMLDivElement | null;\n cvv: HTMLDivElement | null;\n expirationDate: HTMLDivElement | null;\n } {\n return {\n errorMessage: this.querySelector(\n '#braintree-error-message',\n ) as HTMLDivElement | null,\n number: this.querySelector(\n '#braintree-creditcard',\n ) as HTMLDivElement | null,\n cvv: this.querySelector('#braintree-cvv') as HTMLDivElement | null,\n expirationDate: this.querySelector(\n '#braintree-expiration',\n ) as HTMLDivElement | null,\n };\n }\n\n createRenderRoot() {\n return this;\n }\n\n disconnectedCallback(): void {\n this.elementConnected = false;\n }\n\n connectedCallback(): void {\n // eslint-disable-next-line wc/guard-super-call\n super.connectedCallback();\n\n console.log('connectedCallback', { paymentConfig: this.paymentConfig });\n\n this.elementConnected = true;\n }\n\n protected updated(\n changed: PropertyValueMap<any> | Map<PropertyKey, unknown>,\n ): void {\n const elementHasConnectedToDOM =\n changed.has('elementConnected') && this.elementConnected;\n if (elementHasConnectedToDOM) {\n if (this.paymentConfig) {\n const {\n braintreeAuthToken,\n endpointManager,\n paymentClients,\n environment,\n } = this.paymentConfig || {};\n\n const needsBraintreeManager =\n !this.braintreeManager &&\n braintreeAuthToken &&\n endpointManager &&\n paymentClients &&\n environment;\n if (needsBraintreeManager) {\n this.setupBraintreeManager();\n }\n }\n }\n\n if (\n this.braintreeManager &&\n changed.has('displayCreditCard') &&\n this.displayCreditCard\n ) {\n this.setupCreditCardHandler();\n }\n }\n\n async validateCreditCardFields() {\n const handler =\n await this.braintreeManager?.paymentProviders.creditCardHandler.get();\n let tokenized = false;\n let hostedFieldsResponse = null;\n try {\n hostedFieldsResponse = await handler?.tokenizeHostedFields();\n tokenized = true;\n } catch (e) {\n const error = e as unknown as any;\n\n handler?.showErrorMessage();\n\n // todo: move these codes to an enum/type\n switch (error.code) {\n case 'HOSTED_FIELDS_FIELDS_EMPTY':\n // occurs when none of the fields are filled in\n handler?.markFieldErrors([\n HostedFieldName.Number,\n HostedFieldName.CVV,\n HostedFieldName.ExpirationDate,\n ]);\n break;\n case 'HOSTED_FIELDS_FIELDS_INVALID':\n // occurs when certain fields do not pass client side validationto\n // Object.keys(.details.invalidFields).forEach(key => {\n // handler?.markFieldErrors([key as HostedFieldName]);\n // });\n break;\n case 'HOSTED_FIELDS_TOKENIZATION_FAIL_ON_DUPLICATE':\n // occurs when:\n // * the client token used for client authorization was generated\n // with a customer ID and the fail on duplicate payment method\n // option is set to true\n // * the card being tokenized has previously been vaulted (with any customer)\n break;\n case 'HOSTED_FIELDS_TOKENIZATION_CVV_VERIFICATION_FAILED':\n // occurs when:\n // * the client token used for client authorization was generated\n // with a customer ID and the verify card option is set to true\n // and you have credit card verification turned on in the Braintree\n // control panel\n // * the cvv does not pass verfication\n handler?.markFieldErrors([HostedFieldName.CVV]);\n break;\n case 'HOSTED_FIELDS_FAILED_TOKENIZATION':\n // occurs for any other tokenization error on the server\n break;\n case 'HOSTED_FIELDS_TOKENIZATION_NETWORK_ERROR':\n // occurs when the Braintree gateway cannot be contacted\n break;\n default:\n // something else happened\n break;\n }\n }\n\n if (!tokenized) {\n return false;\n }\n\n return hostedFieldsResponse;\n }\n\n async setupCreditCardHandler() {\n // braintree turn on hosted fields\n const handler =\n await this.braintreeManager?.paymentProviders.creditCardHandler.get();\n try {\n await handler?.tokenizeHostedFields();\n } catch (e) {\n // todo: show error message only about fields not loading\n }\n\n handler?.removeFieldErrors([\n HostedFieldName.Number,\n HostedFieldName.CVV,\n HostedFieldName.ExpirationDate,\n ]);\n }\n\n render() {\n return html` <div>${this.creditCardTemplate}</div> `;\n }\n\n lightDomCSS(): CSSResult {\n return css`\n contact-form form badged-input {\n width: 100%;\n }\n\n #ia-mgc-cc-area .braintree-input {\n width: 100%;\n display: block;\n height: stretch;\n height: -webkit-fill-available;\n }\n `;\n }\n\n get creditCardTemplate() {\n return html`\n <div id=\"ia-mgc-cc-area\" style=\"border: 1px sold red;\">\n <style>\n ${this.lightDomCSS()}\n </style>\n <div id=\"braintree-error-message\"></div>\n <div class=\"braintree-row\">\n <badged-input\n .icon=${creditCardImg}\n ?required=${true}\n class=\"creditcard\"\n >\n <div class=\"braintree-input\" id=\"braintree-creditcard\"></div>\n </badged-input>\n </div>\n <div class=\"braintree-row\">\n <badged-input\n .icon=${calendarImg}\n ?required=${true}\n class=\"expiration\"\n >\n <div class=\"braintree-input\" id=\"braintree-expiration\"></div>\n </badged-input>\n <badged-input .icon=${lockImg} ?required=${true} class=\"cvv\">\n <div class=\"braintree-input\" id=\"braintree-cvv\"></div>\n </badged-input>\n </div>\n </div>\n `;\n }\n\n async renderPayPalVaultButton(): Promise<void> {\n console.log('[PayPal] renderPayPalVaultButton called');\n\n const handler =\n await this.braintreeManager?.paymentProviders.paypalHandler.get();\n console.log('[PayPal] handler:', handler);\n if (!handler) return;\n\n const container = document.querySelector('#ia-mgc-paypal-button');\n console.log('[PayPal] container element:', container);\n\n const donationInfo = new DonationPaymentInfo({\n donationType: DonationType.Monthly,\n amount: this.plan?.amount ?? 0,\n coverFees: false,\n });\n\n const dataSource = await handler.renderPayPalButton({\n selector: '#ia-mgc-paypal-button',\n style: { color: 'blue', shape: 'rect', size: 'medium' },\n donationInfo,\n });\n console.log('[PayPal] dataSource:', dataSource);\n\n if (!dataSource) return;\n\n dataSource.delegate = {\n payPalPaymentStarted: async () => {\n console.log('PayPal payment started');\n },\n payPalPaymentAuthorized: async (_ds: any, payload: any) => {\n this.handlePayPalAuthorized(payload);\n },\n payPalPaymentConfirmed: async (_ds: any, payload: any) => {\n this.handlePayPalAuthorized(payload);\n },\n payPalPaymentCancelled: async () => {\n console.log('PayPal payment cancelled');\n },\n payPalPaymentError: async (_ds: any, error: unknown) => {\n console.error('PayPal vault error:', error);\n this.dispatchEvent(\n new CustomEvent('PayPalVaultError', { detail: { error } }),\n );\n },\n };\n }\n\n private handlePayPalAuthorized(payload: {\n nonce: string;\n type: string;\n details: { email: string };\n }): void {\n this.dispatchEvent(\n new CustomEvent('PayPalVaultAuthorized', {\n detail: {\n paymentMethodInfo: {\n description: `PayPal - ${payload.details.email}`,\n nonce: payload.nonce,\n type: payload.type,\n details: { email: payload.details.email },\n },\n },\n }),\n );\n }\n\n async startVenmoPayment(): Promise<void> {\n const handler =\n await this.braintreeManager?.paymentProviders.venmoHandler.get();\n if (!handler) return;\n\n if (this.plan?.id) this.venmoPendingStorage?.setPending(this.plan.id);\n\n try {\n const payload = await handler.startPayment();\n if (this.plan?.id) this.venmoPendingStorage?.clearPending(this.plan.id);\n this.dispatchEvent(\n new CustomEvent('VenmoAuthorized', {\n detail: {\n paymentMethodInfo: {\n description: `Venmo - ${payload.details.username}`,\n nonce: payload.nonce,\n type: payload.type,\n details: { username: payload.details.username },\n },\n },\n }),\n );\n } catch (e: unknown) {\n if (this.plan?.id) this.venmoPendingStorage?.clearPending(this.plan.id);\n const code = (e as { code?: string })?.code;\n if (code === 'VENMO_APP_CANCELED' || code === 'VENMO_CANCELED') {\n console.log('Venmo payment cancelled');\n } else {\n console.error('Venmo payment error:', e);\n this.dispatchEvent(\n new CustomEvent('VenmoError', { detail: { error: e } }),\n );\n }\n }\n }\n\n private async checkVenmoRestoration(): Promise<void> {\n const planId = this.plan?.id;\n if (!planId) return;\n const pending = this.venmoPendingStorage?.getPending(planId);\n if (!pending) return;\n\n try {\n const handler =\n await this.braintreeManager?.paymentProviders.venmoHandler.get();\n if (!handler) {\n this.venmoPendingStorage?.clearPending(planId);\n return;\n }\n\n const instance = await handler.instance.get();\n if (!instance) {\n this.venmoPendingStorage?.clearPending(planId);\n return;\n }\n\n // Clear before tokenizing to prevent retry loops on failure\n this.venmoPendingStorage?.clearPending(planId);\n\n if (!instance.hasTokenizationResult()) return;\n\n // startPayment() re-checks hasTokenizationResult() internally and\n // calls instance.tokenize() on the cached result — it does NOT launch\n // a new Venmo redirect when a tokenization result is already present.\n const payload = await handler.startPayment();\n this.dispatchEvent(\n new CustomEvent('VenmoAuthorized', {\n detail: {\n paymentMethodInfo: {\n description: `Venmo - ${payload.details.username}`,\n nonce: payload.nonce,\n type: payload.type,\n details: { username: payload.details.username },\n },\n },\n }),\n );\n } catch (e: unknown) {\n this.venmoPendingStorage?.clearPending(planId);\n const code = (e as { code?: string })?.code;\n if (code !== 'VENMO_APP_CANCELED' && code !== 'VENMO_CANCELED') {\n console.error('Venmo restoration error:', e);\n this.dispatchEvent(\n new CustomEvent('VenmoError', { detail: { error: e } }),\n );\n }\n }\n }\n\n private async setupBraintreeManager(): Promise<void> {\n this.braintreeManager = new BraintreeManager({\n paymentClients:\n this.paymentConfig?.paymentClients ?? ({} as PaymentClientsInterface),\n endpointManager: this.paymentConfig\n ?.endpointManager as BraintreeEndpointManagerInterface,\n authorizationToken: this.paymentConfig?.braintreeAuthToken ?? '',\n venmoProfileId: this.paymentConfig?.venmoProfileId,\n googlePayMerchantId: this.paymentConfig?.googlePayMerchantId,\n hostedFieldConfig: {\n hostedFieldStyle: {}, // Provide your custom style object here\n hostedFieldFieldOptions: {\n number: {\n selector: '#braintree-creditcard',\n placeholder: 'Card number',\n },\n cvv: {\n selector: '#braintree-cvv',\n placeholder: 'CVC',\n },\n expirationDate: {\n selector: '#braintree-expiration',\n placeholder: 'MM / YY',\n },\n }, // Provide your custom field options here\n hostedFieldContainer: new HostedFieldContainer({\n number: this.braintreeInputs.number as HTMLDivElement,\n cvv: this.braintreeInputs.cvv as HTMLDivElement,\n expirationDate: this.braintreeInputs.expirationDate as HTMLDivElement,\n errorContainer: this.braintreeInputs.errorMessage as HTMLDivElement,\n }),\n },\n hostingEnvironment: this.paymentConfig?.environment as HostingEnvironment,\n referrer: window.location.href,\n loggedInUser: this.patronEmail,\n origin: window.location.origin,\n });\n\n this.braintreeManager.on(\n 'paymentProvidersHostedFieldsRetry',\n (retryNumber: number) => {\n const event = new CustomEvent('paymentProvidersHostedFieldsRetry', {\n detail: { retryNumber },\n });\n this.dispatchEvent(event);\n },\n );\n\n this.braintreeManager.on(\n 'paymentProvidersHostedFieldsFailed',\n (error: unknown) => {\n const event = new CustomEvent('paymentProvidersHostedFieldsFailed', {\n detail: { error },\n });\n this.dispatchEvent(event);\n },\n );\n\n // BraintreeManager (@internetarchive/donation-form) has no config option to\n // suppress Google Pay, so we replace the handler directly. The upstream path\n // is `BraintreeManager.paymentProviders.googlePayHandler` — if that changes\n // this cast will silently stop working and the button may reappear.\n if (!this.paymentConfig?.googlePayMerchantId && this.braintreeManager) {\n // BraintreeManager has no config option to suppress Google Pay, so we\n // replace the handler directly. Casting only paymentProviders (not the\n // whole manager) keeps the access chain type-checked — if upstream\n // renames paymentProviders or googlePayHandler, TypeScript will catch it.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (this.braintreeManager.paymentProviders as any).googlePayHandler = {\n get: async () => null,\n };\n }\n\n await this.checkVenmoRestoration();\n this.dispatchEvent(new Event('BraintreeManagerSetupComplete'));\n }\n\n get contactForm(): HTMLFormElement | null {\n return this.querySelector('form[name=\"contact-form\"]');\n }\n}\n"]}
1
+ {"version":3,"file":"braintree-manager.js","sourceRoot":"","sources":["../../../../src/form-sections/parts/braintree-manager.ts"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAA+B,MAAM,KAAK,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EACL,oBAAoB,EACpB,eAAe,GAChB,MAAM,gHAAgH,CAAC;AACxH,OAAO,EACL,gBAAgB,GAGjB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,mBAAmB,EACnB,YAAY,GACb,MAAM,4CAA4C,CAAC;AAIpD,OAAO,aAAa,MAAM,4CAA4C,CAAC;AACvE,OAAO,WAAW,MAAM,yCAAyC,CAAC;AAClE,OAAO,OAAO,MAAM,qCAAqC,CAAC;AAiBnD,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,UAAU;IAA5C;;QAGuC,sBAAiB,GAC3D,KAAK,CAAC;QAEoB,gBAAW,GAAW,EAAE,CAAC;QAMpC,qBAAgB,GAAY,KAAK,CAAC;IA4kBrD,CAAC;IAxkBC,IAAI,eAAe;QAMjB,OAAO;YACL,YAAY,EAAE,IAAI,CAAC,aAAa,CAC9B,0BAA0B,CACF;YAC1B,MAAM,EAAE,IAAI,CAAC,aAAa,CACxB,uBAAuB,CACC;YAC1B,GAAG,EAAE,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAA0B;YACl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E9B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;6DAA8C;AAExD;IAAhB,KAAK,EAAE;6DAA2C;AAEvB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gEAA2C;AAd3D,mBAAmB;IAD/B,aAAa,CAAC,0BAA0B,CAAC;GAC7B,mBAAmB,CAwlB/B","sourcesContent":["/* eslint-disable no-console */\nimport { LitElement, html, css, CSSResult, PropertyValueMap } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\n\nimport {\n HostedFieldContainer,\n HostedFieldName,\n} from '@internetarchive/donation-form/dist/src/braintree-manager/payment-providers/credit-card/hosted-field-container';\nimport {\n BraintreeManager,\n BraintreeManagerInterface,\n HostingEnvironment,\n} from '@internetarchive/donation-form';\nimport {\n DonationPaymentInfo,\n DonationType,\n} from '@internetarchive/donation-form-data-models';\nimport type { BraintreeEndpointManagerInterface } from '@internetarchive/donation-form/dist/src/braintree-manager/braintree-interfaces.js';\nimport type { PaymentClientsInterface } from '@internetarchive/donation-form/dist/src/braintree-manager/payment-clients.js';\n\nimport creditCardImg from '@internetarchive/icon-credit-card/index.js';\nimport calendarImg from '@internetarchive/icon-calendar/index.js';\nimport lockImg from '@internetarchive/icon-lock/index.js';\nimport { VenmoPendingStorage } from '../../utils/venmo-pending-storage';\n\nimport type { MonthlyPlan } from '../../models/plan';\n\nexport type PaymentConfig = {\n braintreeAuthToken?: string;\n endpointManager?: BraintreeEndpointManagerInterface;\n paymentClients?: PaymentClientsInterface;\n environment?: HostingEnvironment;\n venmoProfileId?: string;\n googlePayMerchantId?: string;\n referrer: string;\n origin: string;\n};\n\n@customElement('ia-mgc-braintree-manager')\nexport class MGCBraintreeManager extends LitElement {\n @property({ type: Object }) plan?: MonthlyPlan;\n\n @property({ type: Boolean, reflect: true }) displayCreditCard: boolean =\n false;\n\n @property({ type: String }) patronEmail: string = '';\n\n @property({ type: Object }) paymentConfig?: PaymentConfig;\n\n @property({ type: Object }) braintreeManager?: BraintreeManagerInterface;\n\n @state() private elementConnected: boolean = false;\n\n @property({ type: Object }) venmoPendingStorage?: VenmoPendingStorage;\n\n get braintreeInputs(): {\n errorMessage: HTMLDivElement | null;\n number: HTMLDivElement | null;\n cvv: HTMLDivElement | null;\n expirationDate: HTMLDivElement | null;\n } {\n return {\n errorMessage: this.querySelector(\n '#braintree-error-message',\n ) as HTMLDivElement | null,\n number: this.querySelector(\n '#braintree-creditcard',\n ) as HTMLDivElement | null,\n cvv: this.querySelector('#braintree-cvv') as HTMLDivElement | null,\n expirationDate: this.querySelector(\n '#braintree-expiration',\n ) as HTMLDivElement | null,\n };\n }\n\n createRenderRoot() {\n return this;\n }\n\n disconnectedCallback(): void {\n this.elementConnected = false;\n }\n\n connectedCallback(): void {\n // eslint-disable-next-line wc/guard-super-call\n super.connectedCallback();\n\n console.log('connectedCallback', { paymentConfig: this.paymentConfig });\n\n this.elementConnected = true;\n }\n\n protected updated(\n changed: PropertyValueMap<any> | Map<PropertyKey, unknown>,\n ): void {\n const elementHasConnectedToDOM =\n changed.has('elementConnected') && this.elementConnected;\n if (elementHasConnectedToDOM) {\n if (this.paymentConfig) {\n const {\n braintreeAuthToken,\n endpointManager,\n paymentClients,\n environment,\n } = this.paymentConfig || {};\n\n const needsBraintreeManager =\n !this.braintreeManager &&\n braintreeAuthToken &&\n endpointManager &&\n paymentClients &&\n environment;\n if (needsBraintreeManager) {\n this.setupBraintreeManager();\n }\n }\n }\n\n if (\n this.braintreeManager &&\n changed.has('displayCreditCard') &&\n this.displayCreditCard\n ) {\n this.setupCreditCardHandler();\n }\n }\n\n async validateCreditCardFields() {\n const handler =\n await this.braintreeManager?.paymentProviders.creditCardHandler.get();\n let tokenized = false;\n let hostedFieldsResponse = null;\n try {\n hostedFieldsResponse = await handler?.tokenizeHostedFields();\n tokenized = true;\n } catch (e) {\n const error = e as unknown as any;\n\n handler?.showErrorMessage();\n\n // todo: move these codes to an enum/type\n switch (error.code) {\n case 'HOSTED_FIELDS_FIELDS_EMPTY':\n // occurs when none of the fields are filled in\n handler?.markFieldErrors([\n HostedFieldName.Number,\n HostedFieldName.CVV,\n HostedFieldName.ExpirationDate,\n ]);\n break;\n case 'HOSTED_FIELDS_FIELDS_INVALID':\n // occurs when certain fields do not pass client side validationto\n // Object.keys(.details.invalidFields).forEach(key => {\n // handler?.markFieldErrors([key as HostedFieldName]);\n // });\n break;\n case 'HOSTED_FIELDS_TOKENIZATION_FAIL_ON_DUPLICATE':\n // occurs when:\n // * the client token used for client authorization was generated\n // with a customer ID and the fail on duplicate payment method\n // option is set to true\n // * the card being tokenized has previously been vaulted (with any customer)\n break;\n case 'HOSTED_FIELDS_TOKENIZATION_CVV_VERIFICATION_FAILED':\n // occurs when:\n // * the client token used for client authorization was generated\n // with a customer ID and the verify card option is set to true\n // and you have credit card verification turned on in the Braintree\n // control panel\n // * the cvv does not pass verfication\n handler?.markFieldErrors([HostedFieldName.CVV]);\n break;\n case 'HOSTED_FIELDS_FAILED_TOKENIZATION':\n // occurs for any other tokenization error on the server\n break;\n case 'HOSTED_FIELDS_TOKENIZATION_NETWORK_ERROR':\n // occurs when the Braintree gateway cannot be contacted\n break;\n default:\n // something else happened\n break;\n }\n }\n\n if (!tokenized) {\n return false;\n }\n\n return hostedFieldsResponse;\n }\n\n async setupCreditCardHandler() {\n // braintree turn on hosted fields\n const handler =\n await this.braintreeManager?.paymentProviders.creditCardHandler.get();\n try {\n await handler?.tokenizeHostedFields();\n } catch (e) {\n // todo: show error message only about fields not loading\n }\n\n handler?.removeFieldErrors([\n HostedFieldName.Number,\n HostedFieldName.CVV,\n HostedFieldName.ExpirationDate,\n ]);\n }\n\n render() {\n return html` <div>${this.creditCardTemplate}</div> `;\n }\n\n lightDomCSS(): CSSResult {\n return css`\n contact-form form badged-input {\n width: 100%;\n }\n\n #ia-mgc-cc-area .braintree-input {\n width: 100%;\n display: block;\n height: stretch;\n height: -webkit-fill-available;\n }\n `;\n }\n\n get creditCardTemplate() {\n return html`\n <div id=\"ia-mgc-cc-area\" style=\"border: 1px sold red;\">\n <style>\n ${this.lightDomCSS()}\n </style>\n <div id=\"braintree-error-message\"></div>\n <div class=\"braintree-row\">\n <badged-input\n .icon=${creditCardImg}\n ?required=${true}\n class=\"creditcard\"\n >\n <div class=\"braintree-input\" id=\"braintree-creditcard\"></div>\n </badged-input>\n </div>\n <div class=\"braintree-row\">\n <badged-input\n .icon=${calendarImg}\n ?required=${true}\n class=\"expiration\"\n >\n <div class=\"braintree-input\" id=\"braintree-expiration\"></div>\n </badged-input>\n <badged-input .icon=${lockImg} ?required=${true} class=\"cvv\">\n <div class=\"braintree-input\" id=\"braintree-cvv\"></div>\n </badged-input>\n </div>\n </div>\n `;\n }\n\n async renderPayPalVaultButton(): Promise<void> {\n console.log('[PayPal] renderPayPalVaultButton called');\n\n const handler =\n await this.braintreeManager?.paymentProviders.paypalHandler.get();\n console.log('[PayPal] handler:', handler);\n if (!handler) return;\n\n const container = document.querySelector('#ia-mgc-paypal-button');\n console.log('[PayPal] container element:', container);\n\n const donationInfo = new DonationPaymentInfo({\n donationType: DonationType.Monthly,\n amount: this.plan?.amount ?? 0,\n coverFees: false,\n });\n\n const dataSource = await handler.renderPayPalButton({\n selector: '#ia-mgc-paypal-button',\n style: { color: 'blue', shape: 'rect', size: 'medium' },\n donationInfo,\n });\n console.log('[PayPal] dataSource:', dataSource);\n\n if (!dataSource) return;\n\n dataSource.delegate = {\n payPalPaymentStarted: async () => {\n console.log('PayPal payment started');\n },\n payPalPaymentAuthorized: async (_ds: any, payload: any) => {\n this.handlePayPalAuthorized(payload);\n },\n payPalPaymentConfirmed: async (_ds: any, payload: any) => {\n this.handlePayPalAuthorized(payload);\n },\n payPalPaymentCancelled: async () => {\n console.log('PayPal payment cancelled');\n },\n payPalPaymentError: async (_ds: any, error: unknown) => {\n console.error('PayPal vault error:', error);\n this.dispatchEvent(\n new CustomEvent('PayPalVaultError', { detail: { error } }),\n );\n },\n };\n }\n\n private handlePayPalAuthorized(payload: {\n nonce: string;\n type: string;\n details: { email: string };\n }): void {\n this.dispatchEvent(\n new CustomEvent('PayPalVaultAuthorized', {\n detail: {\n paymentMethodInfo: {\n description: `PayPal - ${payload.details.email}`,\n nonce: payload.nonce,\n type: payload.type,\n details: { email: payload.details.email },\n },\n },\n }),\n );\n }\n\n async startVenmoPayment(): Promise<void> {\n const handler =\n await this.braintreeManager?.paymentProviders.venmoHandler.get();\n if (!handler) return;\n\n if (this.plan?.id) this.venmoPendingStorage?.setPending(this.plan.id);\n\n try {\n const payload = await handler.startPayment();\n if (this.plan?.id) this.venmoPendingStorage?.clearPending(this.plan.id);\n this.dispatchEvent(\n new CustomEvent('VenmoAuthorized', {\n detail: {\n paymentMethodInfo: {\n description: `Venmo - ${payload.details.username}`,\n nonce: payload.nonce,\n type: payload.type,\n details: { username: payload.details.username },\n },\n },\n }),\n );\n } catch (e: unknown) {\n if (this.plan?.id) this.venmoPendingStorage?.clearPending(this.plan.id);\n const code = (e as { code?: string })?.code;\n if (code === 'VENMO_APP_CANCELED' || code === 'VENMO_CANCELED') {\n console.log('Venmo payment cancelled');\n } else {\n console.error('Venmo payment error:', e);\n this.dispatchEvent(\n new CustomEvent('VenmoError', { detail: { error: e } }),\n );\n }\n }\n }\n\n async startGooglePayPayment(): Promise<void> {\n const handler =\n await this.braintreeManager?.paymentProviders.googlePayHandler.get();\n if (!handler) return;\n\n try {\n const instance = await handler.instance.get();\n if (!instance) return;\n\n const paymentDataRequest = await instance.createPaymentDataRequest({\n emailRequired: true,\n transactionInfo: {\n currencyCode: 'USD',\n totalPriceStatus: 'FINAL',\n totalPrice: `${this.plan?.amount ?? 0}`,\n },\n });\n\n const paymentData =\n await handler.paymentsClient.loadPaymentData(paymentDataRequest);\n const payload = await instance.parseResponse(paymentData);\n this.dispatchEvent(\n new CustomEvent('GooglePayVaultAuthorized', {\n detail: {\n paymentMethodInfo: {\n description: `Google Pay - ${payload.details.cardType} - ${payload.details.lastFour}`,\n nonce: payload.nonce,\n type: payload.type,\n details: {\n cardType: payload.details.cardType,\n lastFour: payload.details.lastFour,\n },\n },\n },\n }),\n );\n } catch (e: unknown) {\n const statusCode = (e as { statusCode?: string })?.statusCode;\n if (statusCode === 'CANCELED') {\n console.log('Google Pay payment cancelled');\n } else {\n console.error('Google Pay payment error:', e);\n this.dispatchEvent(\n new CustomEvent('GooglePayError', { detail: { error: e } }),\n );\n }\n }\n }\n\n // In order to trigger the Apple Pay flow, you HAVE to call this from\n // directly within the user-gesture handler that produced `originalEvent`\n // (Safari requires this). Notice we're not actually using the event itself.\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async startApplePayPayment(originalEvent: Event): Promise<void> {\n const handler =\n await this.braintreeManager?.paymentProviders.applePayHandler.get();\n if (!handler) return;\n\n try {\n const applePayInstance = await handler.instance.get();\n if (!applePayInstance) return;\n\n const paymentRequest = applePayInstance.createPaymentRequest({\n total: {\n label: 'Internet Archive Monthly',\n amount: `${this.plan?.amount ?? 0}`,\n },\n requiredBillingContactFields: ['postalAddress'],\n });\n\n const session = new ApplePaySession(3, paymentRequest);\n\n session.onvalidatemerchant = (\n event: ApplePayJS.ApplePayValidateMerchantEvent,\n ) => {\n applePayInstance.performValidation(\n {\n validationURL: event.validationURL,\n displayName: 'Internet Archive',\n },\n (validationErr: unknown, validationData: unknown) => {\n if (validationErr) {\n console.error(\n 'Apple Pay merchant validation error:',\n validationErr,\n );\n session.abort();\n this.dispatchEvent(\n new CustomEvent('ApplePayError', {\n detail: { error: validationErr },\n }),\n );\n return;\n }\n session.completeMerchantValidation(validationData);\n },\n );\n };\n\n session.onpaymentauthorized = async (\n event: ApplePayJS.ApplePayPaymentAuthorizedEvent,\n ) => {\n try {\n const payload = await applePayInstance.tokenize({\n token: event.payment.token,\n });\n session.completePayment(ApplePaySession.STATUS_SUCCESS);\n this.dispatchEvent(\n new CustomEvent('ApplePayVaultAuthorized', {\n detail: {\n paymentMethodInfo: {\n description: `Apple Pay - ${payload.details.cardType} - ${payload.details.dpanLastTwo}`,\n nonce: payload.nonce,\n type: payload.type,\n details: {\n cardType: payload.details.cardType,\n lastTwo: payload.details.dpanLastTwo,\n },\n },\n },\n }),\n );\n } catch (e: unknown) {\n session.completePayment(ApplePaySession.STATUS_FAILURE);\n console.error('Apple Pay tokenization error:', e);\n this.dispatchEvent(\n new CustomEvent('ApplePayError', { detail: { error: e } }),\n );\n }\n };\n\n session.oncancel = () => {\n console.log('Apple Pay payment cancelled');\n };\n\n session.begin();\n } catch (e: unknown) {\n console.error('Apple Pay error:', e);\n this.dispatchEvent(\n new CustomEvent('ApplePayError', { detail: { error: e } }),\n );\n }\n }\n\n private async checkVenmoRestoration(): Promise<void> {\n const planId = this.plan?.id;\n if (!planId) return;\n const pending = this.venmoPendingStorage?.getPending(planId);\n if (!pending) return;\n\n try {\n const handler =\n await this.braintreeManager?.paymentProviders.venmoHandler.get();\n if (!handler) {\n this.venmoPendingStorage?.clearPending(planId);\n return;\n }\n\n const instance = await handler.instance.get();\n if (!instance) {\n this.venmoPendingStorage?.clearPending(planId);\n return;\n }\n\n // Clear before tokenizing to prevent retry loops on failure\n this.venmoPendingStorage?.clearPending(planId);\n\n if (!instance.hasTokenizationResult()) return;\n\n // startPayment() re-checks hasTokenizationResult() internally and\n // calls instance.tokenize() on the cached result — it does NOT launch\n // a new Venmo redirect when a tokenization result is already present.\n const payload = await handler.startPayment();\n this.dispatchEvent(\n new CustomEvent('VenmoAuthorized', {\n detail: {\n paymentMethodInfo: {\n description: `Venmo - ${payload.details.username}`,\n nonce: payload.nonce,\n type: payload.type,\n details: { username: payload.details.username },\n },\n },\n }),\n );\n } catch (e: unknown) {\n this.venmoPendingStorage?.clearPending(planId);\n const code = (e as { code?: string })?.code;\n if (code !== 'VENMO_APP_CANCELED' && code !== 'VENMO_CANCELED') {\n console.error('Venmo restoration error:', e);\n this.dispatchEvent(\n new CustomEvent('VenmoError', { detail: { error: e } }),\n );\n }\n }\n }\n\n private async setupBraintreeManager(): Promise<void> {\n this.braintreeManager = new BraintreeManager({\n paymentClients:\n this.paymentConfig?.paymentClients ?? ({} as PaymentClientsInterface),\n endpointManager: this.paymentConfig\n ?.endpointManager as BraintreeEndpointManagerInterface,\n authorizationToken: this.paymentConfig?.braintreeAuthToken ?? '',\n venmoProfileId: this.paymentConfig?.venmoProfileId,\n googlePayMerchantId: this.paymentConfig?.googlePayMerchantId,\n hostedFieldConfig: {\n hostedFieldStyle: {}, // Provide your custom style object here\n hostedFieldFieldOptions: {\n number: {\n selector: '#braintree-creditcard',\n placeholder: 'Card number',\n },\n cvv: {\n selector: '#braintree-cvv',\n placeholder: 'CVC',\n },\n expirationDate: {\n selector: '#braintree-expiration',\n placeholder: 'MM / YY',\n },\n }, // Provide your custom field options here\n hostedFieldContainer: new HostedFieldContainer({\n number: this.braintreeInputs.number as HTMLDivElement,\n cvv: this.braintreeInputs.cvv as HTMLDivElement,\n expirationDate: this.braintreeInputs.expirationDate as HTMLDivElement,\n errorContainer: this.braintreeInputs.errorMessage as HTMLDivElement,\n }),\n },\n hostingEnvironment: this.paymentConfig?.environment as HostingEnvironment,\n referrer: window.location.href,\n loggedInUser: this.patronEmail,\n origin: window.location.origin,\n });\n\n this.braintreeManager.on(\n 'paymentProvidersHostedFieldsRetry',\n (retryNumber: number) => {\n const event = new CustomEvent('paymentProvidersHostedFieldsRetry', {\n detail: { retryNumber },\n });\n this.dispatchEvent(event);\n },\n );\n\n this.braintreeManager.on(\n 'paymentProvidersHostedFieldsFailed',\n (error: unknown) => {\n const event = new CustomEvent('paymentProvidersHostedFieldsFailed', {\n detail: { error },\n });\n this.dispatchEvent(event);\n },\n );\n\n // BraintreeManager (@internetarchive/donation-form) has no config option to\n // suppress Google Pay, so we replace the handler directly. The upstream path\n // is `BraintreeManager.paymentProviders.googlePayHandler` — if that changes\n // this cast will silently stop working and the button may reappear.\n if (!this.paymentConfig?.googlePayMerchantId && this.braintreeManager) {\n // BraintreeManager has no config option to suppress Google Pay, so we\n // replace the handler directly. Casting only paymentProviders (not the\n // whole manager) keeps the access chain type-checked — if upstream\n // renames paymentProviders or googlePayHandler, TypeScript will catch it.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (this.braintreeManager.paymentProviders as any).googlePayHandler = {\n get: async () => null,\n };\n }\n\n await this.checkVenmoRestoration();\n this.dispatchEvent(new Event('BraintreeManagerSetupComplete'));\n }\n\n get contactForm(): HTMLFormElement | null {\n return this.querySelector('form[name=\"contact-form\"]');\n }\n}\n"]}
@@ -34,10 +34,12 @@ export declare class MGCEditPaymentMethod extends LitElement {
34
34
  updateMessage: string;
35
35
  updateStatus: 'success' | 'fail' | '';
36
36
  venmoPendingStorage?: VenmoPendingStorage;
37
+ private authorizedPaymentMethodRequest?;
37
38
  createRenderRoot(): this;
38
39
  firstUpdated(): void;
39
40
  private checkAndRestoreVenmoState;
40
41
  submitPaymentMethodChange(e: Event): void;
42
+ private selectProvider;
41
43
  clearStatusMessaging(): void;
42
44
  paymentMethodUpdated(status: 'success' | 'fail'): Promise<void>;
43
45
  get updateRequestButton(): MGCButton;
@@ -50,6 +52,8 @@ export declare class MGCEditPaymentMethod extends LitElement {
50
52
  render(): TemplateResult<1>;
51
53
  showVenmoError(message?: string): void;
52
54
  private handleVenmoAuthorized;
55
+ private handleGooglePayVaultAuthorized;
56
+ private handleApplePayVaultAuthorized;
53
57
  private handlePayPalVaultAuthorized;
54
58
  get styles(): import("lit").CSSResult;
55
59
  }
@@ -1,7 +1,7 @@
1
1
  import { __decorate } from "tslib";
2
2
  /* eslint-disable arrow-body-style */
3
3
  import { LitElement, html, nothing, css } from 'lit';
4
- import { customElement, property } from 'lit/decorators.js';
4
+ import { customElement, property, state } from 'lit/decorators.js';
5
5
  import '@internetarchive/donation-form-section';
6
6
  import '@internetarchive/donation-form/dist/src/form-elements/contact-form/contact-form.js';
7
7
  import lockImg from '@internetarchive/icon-lock/index.js';
@@ -64,6 +64,12 @@ let MGCEditPaymentMethod = class MGCEditPaymentMethod extends LitElement {
64
64
  submitPaymentMethodChange(e) {
65
65
  e.preventDefault();
66
66
  }
67
+ selectProvider(provider) {
68
+ this.selectedPaymentProvider = provider;
69
+ // A previously authorized wallet nonce must not carry over to a different
70
+ // method, so drop it whenever the selection changes.
71
+ this.authorizedPaymentMethodRequest = undefined;
72
+ }
67
73
  clearStatusMessaging() {
68
74
  this.updateMessage = '';
69
75
  this.updateStatus = '';
@@ -77,6 +83,7 @@ let MGCEditPaymentMethod = class MGCEditPaymentMethod extends LitElement {
77
83
  if (status === 'success') {
78
84
  this.currentlyEditing = false;
79
85
  this.selectedPaymentProvider = '';
86
+ this.authorizedPaymentMethodRequest = undefined;
80
87
  return;
81
88
  }
82
89
  this.updateRequestButton.isDisabled = false;
@@ -133,9 +140,12 @@ let MGCEditPaymentMethod = class MGCEditPaymentMethod extends LitElement {
133
140
  const displayContactForm = this.selectedPaymentProvider === PaymentProvider.CreditCard ||
134
141
  this.selectedPaymentProvider === PaymentProvider.Venmo;
135
142
  const displayCCFields = this.selectedPaymentProvider === PaymentProvider.CreditCard;
136
- const displayBraintreeManager = this.selectedPaymentProvider === PaymentProvider.CreditCard ||
137
- this.selectedPaymentProvider === PaymentProvider.PayPal ||
138
- this.selectedPaymentProvider === PaymentProvider.Venmo;
143
+ const displayBraintreeManager = !!this.selectedPaymentProvider;
144
+ // Credit Card can be submitted as soon as it's selected (fields are
145
+ // validated on submit); the wallet providers can only be submitted once
146
+ // they've authorized and handed us a payment method request.
147
+ const submitEnabled = this.selectedPaymentProvider === PaymentProvider.CreditCard ||
148
+ !!this.authorizedPaymentMethodRequest;
139
149
  return html `
140
150
  <style>
141
151
  ${this.styles}
@@ -167,22 +177,26 @@ let MGCEditPaymentMethod = class MGCEditPaymentMethod extends LitElement {
167
177
  (_a = e.target) === null || _a === void 0 ? void 0 : _a.showPaypalButton();
168
178
  }}
169
179
  @creditCardSelected=${() => {
170
- this.selectedPaymentProvider = PaymentProvider.CreditCard;
180
+ this.selectProvider(PaymentProvider.CreditCard);
171
181
  }}
172
182
  @venmoSelected=${() => {
173
- this.selectedPaymentProvider = PaymentProvider.Venmo;
183
+ this.selectProvider(PaymentProvider.Venmo);
174
184
  }}
175
- @applePaySelected=${() => {
176
- this.selectedPaymentProvider = PaymentProvider.ApplePay;
185
+ @applePaySelected=${(e) => {
186
+ var _a;
187
+ this.selectProvider(PaymentProvider.ApplePay);
188
+ (_a = this.braintreeManagerElement) === null || _a === void 0 ? void 0 : _a.startApplePayPayment(e.detail.originalEvent);
177
189
  }}
178
190
  @googlePaySelected=${() => {
179
- this.selectedPaymentProvider = PaymentProvider.GooglePay;
191
+ var _a;
192
+ this.selectProvider(PaymentProvider.GooglePay);
193
+ (_a = this.braintreeManagerElement) === null || _a === void 0 ? void 0 : _a.startGooglePayPayment();
180
194
  }}
181
195
  @paypalSelected=${() => {
182
- this.selectedPaymentProvider = PaymentProvider.PayPal;
196
+ this.selectProvider(PaymentProvider.PayPal);
183
197
  }}
184
198
  @resetPaymentMethod=${async () => {
185
- this.selectedPaymentProvider = '';
199
+ this.selectProvider('');
186
200
  }}
187
201
  tabindex="0"
188
202
  >
@@ -225,6 +239,20 @@ let MGCEditPaymentMethod = class MGCEditPaymentMethod extends LitElement {
225
239
  bubbles: true,
226
240
  composed: true,
227
241
  }));
242
+ }}
243
+ @GooglePayVaultAuthorized=${(e) => {
244
+ this.handleGooglePayVaultAuthorized(e);
245
+ }}
246
+ @GooglePayError=${() => {
247
+ this.updateStatus = 'fail';
248
+ this.updateMessage = 'Google Pay error, please try again';
249
+ }}
250
+ @ApplePayVaultAuthorized=${(e) => {
251
+ this.handleApplePayVaultAuthorized(e);
252
+ }}
253
+ @ApplePayError=${() => {
254
+ this.updateStatus = 'fail';
255
+ this.updateMessage = 'Apple Pay error, please try again';
228
256
  }}
229
257
  ></ia-mgc-braintree-manager>
230
258
 
@@ -239,44 +267,56 @@ let MGCEditPaymentMethod = class MGCEditPaymentMethod extends LitElement {
239
267
  }
240
268
  this.currentlyEditing = false;
241
269
  this.selectedPaymentProvider = '';
270
+ this.authorizedPaymentMethodRequest = undefined;
242
271
  this.clearStatusMessaging();
243
272
  }}
244
273
  >Cancel</ia-mgc-button
245
274
  >
246
- ${this.selectedPaymentProvider !== PaymentProvider.PayPal &&
247
- this.selectedPaymentProvider !== PaymentProvider.Venmo
248
- ? html `<ia-mgc-button
249
- id="edit-plan-payment-method-submit"
250
- class="primary"
251
- type="submit"
252
- .isDisabled=${!this.selectedPaymentProvider}
253
- .clickHandler=${async (event, iaButton) => {
254
- var _a, _b, _c;
255
- const button = iaButton;
256
- button.isDisabled = true;
257
- const isContactFormValid = (_a = this.creditCardElement) === null || _a === void 0 ? void 0 : _a.reportValidity();
258
- if (!isContactFormValid) {
259
- button.isDisabled = false;
260
- return;
261
- }
262
- const paymentMethodInfo = (await ((_b = this.braintreeManagerElement) === null || _b === void 0 ? void 0 : _b.validateCreditCardFields()));
263
- if (!paymentMethodInfo) {
275
+ <ia-mgc-button
276
+ id="edit-plan-payment-method-submit"
277
+ class="primary"
278
+ type="submit"
279
+ .isDisabled=${!submitEnabled}
280
+ .clickHandler=${async (event, iaButton) => {
281
+ var _a, _b, _c;
282
+ const button = iaButton;
283
+ button.isDisabled = true;
284
+ // Wallet providers have already authorized by this point, so
285
+ // submit just saves the request captured on authorization.
286
+ if (this.selectedPaymentProvider !== PaymentProvider.CreditCard) {
287
+ if (!this.authorizedPaymentMethodRequest) {
264
288
  button.isDisabled = false;
265
289
  return;
266
290
  }
267
- const newPaymentMethodRequest = new PaymentMethodRequest({
268
- paymentMethodInfo,
269
- donorContactInfo: (_c = this.contactFormElement) === null || _c === void 0 ? void 0 : _c.donorContactInfo,
270
- paymentProvider: this
271
- .selectedPaymentProvider,
272
- });
273
291
  this.dispatchEvent(new CustomEvent('UpdatePaymentMethod', {
274
- detail: { newPaymentMethodRequest },
292
+ detail: {
293
+ newPaymentMethodRequest: this.authorizedPaymentMethodRequest,
294
+ },
275
295
  }));
276
- }}
277
- >Update payment method</ia-mgc-button
278
- >`
279
- : nothing}
296
+ return;
297
+ }
298
+ // Credit card validates its hosted fields on submit.
299
+ const isContactFormValid = (_a = this.creditCardElement) === null || _a === void 0 ? void 0 : _a.reportValidity();
300
+ if (!isContactFormValid) {
301
+ button.isDisabled = false;
302
+ return;
303
+ }
304
+ const paymentMethodInfo = (await ((_b = this.braintreeManagerElement) === null || _b === void 0 ? void 0 : _b.validateCreditCardFields()));
305
+ if (!paymentMethodInfo) {
306
+ button.isDisabled = false;
307
+ return;
308
+ }
309
+ const newPaymentMethodRequest = new PaymentMethodRequest({
310
+ paymentMethodInfo,
311
+ donorContactInfo: (_c = this.contactFormElement) === null || _c === void 0 ? void 0 : _c.donorContactInfo,
312
+ paymentProvider: PaymentProvider.CreditCard,
313
+ });
314
+ this.dispatchEvent(new CustomEvent('UpdatePaymentMethod', {
315
+ detail: { newPaymentMethodRequest },
316
+ }));
317
+ }}
318
+ >Update payment method</ia-mgc-button
319
+ >
280
320
  ${this.selectedPaymentProvider === PaymentProvider.Venmo
281
321
  ? html `<ia-mgc-button
282
322
  id="edit-plan-payment-method-venmo-submit"
@@ -319,14 +359,29 @@ let MGCEditPaymentMethod = class MGCEditPaymentMethod extends LitElement {
319
359
  handleVenmoAuthorized(e) {
320
360
  var _a, _b;
321
361
  const { paymentMethodInfo } = e.detail;
322
- const newPaymentMethodRequest = new PaymentMethodRequest({
362
+ this.authorizedPaymentMethodRequest = new PaymentMethodRequest({
323
363
  paymentMethodInfo,
324
364
  donorContactInfo: (_b = (_a = this.contactFormElement) === null || _a === void 0 ? void 0 : _a.donorContactInfo) !== null && _b !== void 0 ? _b : {},
325
365
  paymentProvider: PaymentProvider.Venmo,
326
366
  });
327
- this.dispatchEvent(new CustomEvent('UpdatePaymentMethod', {
328
- detail: { newPaymentMethodRequest },
329
- }));
367
+ }
368
+ handleGooglePayVaultAuthorized(e) {
369
+ var _a, _b;
370
+ const { paymentMethodInfo } = e.detail;
371
+ this.authorizedPaymentMethodRequest = new PaymentMethodRequest({
372
+ paymentMethodInfo,
373
+ donorContactInfo: (_b = (_a = this.contactFormElement) === null || _a === void 0 ? void 0 : _a.donorContactInfo) !== null && _b !== void 0 ? _b : {},
374
+ paymentProvider: PaymentProvider.GooglePay,
375
+ });
376
+ }
377
+ handleApplePayVaultAuthorized(e) {
378
+ var _a, _b;
379
+ const { paymentMethodInfo } = e.detail;
380
+ this.authorizedPaymentMethodRequest = new PaymentMethodRequest({
381
+ paymentMethodInfo,
382
+ donorContactInfo: (_b = (_a = this.contactFormElement) === null || _a === void 0 ? void 0 : _a.donorContactInfo) !== null && _b !== void 0 ? _b : {},
383
+ paymentProvider: PaymentProvider.ApplePay,
384
+ });
330
385
  }
331
386
  handlePayPalVaultAuthorized(e) {
332
387
  var _a, _b, _c, _d;
@@ -335,14 +390,11 @@ let MGCEditPaymentMethod = class MGCEditPaymentMethod extends LitElement {
335
390
  const donorContactInfo = (_d = (_c = this.contactFormElement) === null || _c === void 0 ? void 0 : _c.donorContactInfo) !== null && _d !== void 0 ? _d : {
336
391
  customer: { email: paypalEmail },
337
392
  };
338
- const newPaymentMethodRequest = new PaymentMethodRequest({
393
+ this.authorizedPaymentMethodRequest = new PaymentMethodRequest({
339
394
  paymentMethodInfo,
340
395
  donorContactInfo,
341
396
  paymentProvider: PaymentProvider.PayPal,
342
397
  });
343
- this.dispatchEvent(new CustomEvent('UpdatePaymentMethod', {
344
- detail: { newPaymentMethodRequest },
345
- }));
346
398
  }
347
399
  get styles() {
348
400
  return css `
@@ -420,6 +472,9 @@ __decorate([
420
472
  __decorate([
421
473
  property({ type: Object })
422
474
  ], MGCEditPaymentMethod.prototype, "venmoPendingStorage", void 0);
475
+ __decorate([
476
+ state()
477
+ ], MGCEditPaymentMethod.prototype, "authorizedPaymentMethodRequest", void 0);
423
478
  MGCEditPaymentMethod = __decorate([
424
479
  customElement('ia-mgc-edit-payment-method')
425
480
  ], MGCEditPaymentMethod);