Skip to content

Commit d1c77f4

Browse files
authored
Fix: Set link wallets option for Stripe Payment Element based on isLinkEnabled (#11032)
1 parent 3de2e96 commit d1c77f4

File tree

4 files changed

+67
-16
lines changed

4 files changed

+67
-16
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fix
3+
4+
Conditionally set Stripe Link wallet option based on payment method configuration

client/checkout/classic/payment-processing.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ async function createStripePaymentElement(
290290
wallets: {
291291
applePay: 'never',
292292
googlePay: 'never',
293+
link: isLinkEnabled( getUPEConfig( 'paymentMethodsConfig' ) )
294+
? 'auto'
295+
: 'never',
293296
},
294297
} );
295298

client/checkout/utils/__tests__/upe.test.js

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ describe( 'getStripeElementOptions', () => {
639639
},
640640
},
641641
terms: { bancontact: 'always', card: 'always', eps: 'always' },
642-
wallets: { applePay: 'never', googlePay: 'never' },
642+
wallets: { applePay: 'never', googlePay: 'never', link: 'never' },
643643
} );
644644
} );
645645

@@ -687,7 +687,7 @@ describe( 'getStripeElementOptions', () => {
687687
},
688688
},
689689
terms: { bancontact: 'always', card: 'always', eps: 'always' },
690-
wallets: { applePay: 'never', googlePay: 'never' },
690+
wallets: { applePay: 'never', googlePay: 'never', link: 'never' },
691691
} );
692692
} );
693693

@@ -727,7 +727,50 @@ describe( 'getStripeElementOptions', () => {
727727
},
728728
},
729729
terms: { card: 'never' },
730-
wallets: { applePay: 'never', googlePay: 'never' },
730+
wallets: { applePay: 'never', googlePay: 'never', link: 'never' },
731+
} );
732+
} );
733+
734+
test( 'should return options with link: "auto" when both card and link are available', () => {
735+
const shouldSavePayment = false;
736+
const paymentMethodsConfig = {
737+
card: {
738+
isReusable: true,
739+
},
740+
link: {
741+
isReusable: false,
742+
},
743+
};
744+
745+
getUPEConfig.mockImplementation( ( argument ) => {
746+
if ( argument === 'cartContainsSubscription' ) {
747+
return false;
748+
}
749+
} );
750+
751+
const options = getStripeElementOptions(
752+
shouldSavePayment,
753+
paymentMethodsConfig
754+
);
755+
756+
expect( options ).toEqual( {
757+
fields: {
758+
billingDetails: {
759+
address: {
760+
city: 'never',
761+
country: 'never',
762+
line1: 'never',
763+
line2: 'never',
764+
postalCode: 'never',
765+
state: 'never',
766+
},
767+
email: 'never',
768+
name: 'never',
769+
phone: 'never',
770+
},
771+
},
772+
terms: { card: 'never' },
773+
wallets: { applePay: 'never', googlePay: 'never', link: 'auto' },
731774
} );
732775
} );
733776
} );

client/checkout/utils/upe.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,19 @@ export function dispatchChangeEventFor( element ) {
224224
element.dispatchEvent( event );
225225
}
226226

227+
/**
228+
* Check whether Stripe Link is enabled.
229+
*
230+
* @param {Object} paymentMethodsConfig Checkout payment methods configuration settings object.
231+
* @return {boolean} True, if enabled; false otherwise.
232+
*/
233+
export const isLinkEnabled = ( paymentMethodsConfig ) => {
234+
return (
235+
paymentMethodsConfig.link !== undefined &&
236+
paymentMethodsConfig.card !== undefined
237+
);
238+
};
239+
227240
/**
228241
* Returns the prepared set of options needed to initialize the Stripe elements for UPE in Block Checkout.
229242
* The initial options have all the fields set to 'never' to hide them from the UPE, because all the
@@ -258,6 +271,7 @@ export const getStripeElementOptions = (
258271
wallets: {
259272
applePay: 'never',
260273
googlePay: 'never',
274+
link: isLinkEnabled( paymentMethodsConfig ) ? 'auto' : 'never',
261275
},
262276
};
263277

@@ -271,19 +285,6 @@ export const getStripeElementOptions = (
271285
return options;
272286
};
273287

274-
/**
275-
* Check whether Stripe Link is enabled.
276-
*
277-
* @param {Object} paymentMethodsConfig Checkout payment methods configuration settings object.
278-
* @return {boolean} True, if enabled; false otherwise.
279-
*/
280-
export const isLinkEnabled = ( paymentMethodsConfig ) => {
281-
return (
282-
paymentMethodsConfig.link !== undefined &&
283-
paymentMethodsConfig.card !== undefined
284-
);
285-
};
286-
287288
/**
288289
* Get array of payment method types to use with intent.
289290
*

0 commit comments

Comments
 (0)