Skip to content

Commit 624852f

Browse files
committed
Add subscriptionPaymentMethods prop to filter available payment methods when there is a subscription order
1 parent d416cd5 commit 624852f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

packages/react-components/src/components/payment_source/AdyenPayment.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,26 @@ interface PaymentMethodsStyle {
3737
paypal?: PayPalConfiguration["style"]
3838
}
3939

40+
type PaymentMethodType =
41+
| "scheme"
42+
| "giftcard"
43+
| "paypal"
44+
| "applepay"
45+
| "googlepay"
46+
| (string & {})
47+
4048
/**
4149
* Configuration options for the Adyen payment component.
4250
*/
4351
export interface AdyenPaymentConfig {
52+
/**
53+
* Payment methods to be used for subscriptions.
54+
* This is an array of payment method types that are supported for subscription payments.
55+
* For example, it can include "scheme" for card payments.
56+
* @default all available payment methods
57+
* @example ["scheme"]
58+
*/
59+
subscriptionPaymentMethods?: PaymentMethodType[]
4460
/**
4561
* Optional CSS class name for the card container.
4662
*/
@@ -115,6 +131,7 @@ export function AdyenPayment({
115131
giftcardErrorComponent,
116132
onReady,
117133
onSelect,
134+
subscriptionPaymentMethods,
118135
} = {
119136
...defaultConfig,
120137
...config,
@@ -486,6 +503,18 @@ export function AdyenPayment({
486503
* to avoid showing them when the order has subscriptions
487504
*/
488505
paymentMethodsResponse.storedPaymentMethods = []
506+
/**
507+
* Remove scheme payment methods
508+
* because they are not supported in subscriptions
509+
*/
510+
paymentMethodsResponse.paymentMethods =
511+
subscriptionPaymentMethods != null &&
512+
subscriptionPaymentMethods.length > 0
513+
? paymentMethodsResponse.paymentMethods.filter(
514+
(pm: { type: "scheme" }) =>
515+
subscriptionPaymentMethods.includes(pm.type),
516+
)
517+
: paymentMethodsResponse.paymentMethods
489518
}
490519
const options = {
491520
locale: order?.language_code ?? locale,

0 commit comments

Comments
 (0)