Skip to content

Commit

Permalink
allow billingAddress to be passed in via customer options when
Browse files Browse the repository at this point in the history
initializing AlternativePaymentMethods class

update typescript types
  • Loading branch information
gilv93 committed Oct 25, 2024
1 parent 92e30ef commit 0daf4c3
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 (this.customerBillingAddress === undefined) { 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 0daf4c3

Please sign in to comment.