Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow billingAddress to be passed in via customer options on AlternativePaymentMethod #904

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's allow an override here if a new billingAddress is provided:

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
Loading