Skip to content

Commit

Permalink
Merge pull request #904 from recurly/billing-address-via-options
Browse files Browse the repository at this point in the history
Allow billingAddress to be passed in via customer options on AlternativePaymentMethod
  • Loading branch information
chrissrogers authored Oct 25, 2024
2 parents 92e30ef + 9f19208 commit 723836b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -185,7 +185,7 @@ class AlternativePaymentMethods extends Emitter {
});
}

validateBillingAddress (billingAddress) {
static validateBillingAddress (billingAddress) {
if (!billingAddress) {
return;
}
Expand Down
9 changes: 8 additions & 1 deletion lib/recurly/alternative-payment-methods/gateways/adyen.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Base from './base';
import AlternativePaymentMethods from '../alternative-payment-methods';


class AdyenGateway extends Base {
constructor (options, recurly) {
Expand All @@ -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 () {
Expand Down Expand Up @@ -89,7 +96,7 @@ class AdyenGateway extends Base {
}

async submitWebComponent (billingAddress) {
this.customerBillingAddress = billingAddress;
if (billingAddress) { this.customerBillingAddress = billingAddress; }
return this.webComponent.submit();
}

Expand Down
14 changes: 13 additions & 1 deletion types/lib/alternative-payment-methods.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 723836b

Please sign in to comment.