From 0daf4c3f7b7ec7c56775e737ebd0a00584ef98de Mon Sep 17 00:00:00 2001 From: gil Date: Thu, 24 Oct 2024 21:24:45 -0700 Subject: [PATCH] allow billingAddress to be passed in via customer options when initializing AlternativePaymentMethods class update typescript types --- .../alternative-payment-methods.js | 4 ++-- .../alternative-payment-methods/gateways/adyen.js | 9 ++++++++- types/lib/alternative-payment-methods.d.ts | 14 +++++++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/recurly/alternative-payment-methods/alternative-payment-methods.js b/lib/recurly/alternative-payment-methods/alternative-payment-methods.js index 332f1bd0..e179e520 100644 --- a/lib/recurly/alternative-payment-methods/alternative-payment-methods.js +++ b/lib/recurly/alternative-payment-methods/alternative-payment-methods.js @@ -33,7 +33,7 @@ class AlternativePaymentMethods extends Emitter { } async submit ({ billingAddress } = {}) { - this.validateBillingAddress(billingAddress); + AlternativePaymentMethods.validateBillingAddress(billingAddress); if (this.gatewayStrategy.data?.paymentMethod?.type == 'cashapp') { return await this.gatewayStrategy.submitWebComponent(billingAddress); } @@ -185,7 +185,7 @@ class AlternativePaymentMethods extends Emitter { }); } - validateBillingAddress (billingAddress) { + static validateBillingAddress (billingAddress) { if (!billingAddress) { return; } diff --git a/lib/recurly/alternative-payment-methods/gateways/adyen.js b/lib/recurly/alternative-payment-methods/gateways/adyen.js index 2525a951..3a40358e 100644 --- a/lib/recurly/alternative-payment-methods/gateways/adyen.js +++ b/lib/recurly/alternative-payment-methods/gateways/adyen.js @@ -1,4 +1,6 @@ import Base from './base'; +import AlternativePaymentMethods from '../alternative-payment-methods'; + class AdyenGateway extends Base { constructor (options, recurly) { @@ -8,6 +10,11 @@ class AdyenGateway extends Base { this.gatewayType = 'adyen'; this.webComponent = undefined; this.customerBillingAddress = undefined; + + if (options.customer?.billingAddress) { + AlternativePaymentMethods.validateBillingAddress(options.customer.billingAddress); + this.customerBillingAddress = options.customer.billingAddress; + } } scripts () { @@ -89,7 +96,7 @@ class AdyenGateway extends Base { } async submitWebComponent (billingAddress) { - this.customerBillingAddress = billingAddress; + if (this.customerBillingAddress === undefined) { this.customerBillingAddress = billingAddress; } return this.webComponent.submit(); } diff --git a/types/lib/alternative-payment-methods.d.ts b/types/lib/alternative-payment-methods.d.ts index 942173ce..96168dd7 100644 --- a/types/lib/alternative-payment-methods.d.ts +++ b/types/lib/alternative-payment-methods.d.ts @@ -32,6 +32,13 @@ export type AdyenAlternativePaymentMethodOptions = { componentConfig?: { [key: string]: any } }; +export type CustomerOptions = { + /** + * The customer's billing address. + */ + billingAddress?: Address; +}; + export type AlternativePaymentMethodStartOptions = { /** * List of payment methods to be presented to the customer. @@ -77,7 +84,12 @@ export type AlternativePaymentMethodStartOptions = { /** * Adyen options. */ - adyen?: AdyenAlternativePaymentMethodOptions + adyen?: AdyenAlternativePaymentMethodOptions, + + /** + * Sets additional customer fields on the generated token. + */ + customer?: CustomerOptions }; export type AlternativePaymentMethodSubmitOptions = {