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

Refactor loadStripe for Express Checkouts #9582

Merged
merged 4 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions changelog/as-improve-stripe-for-ece
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: update

Refactor loadStripe for Express Checkouts.
8 changes: 4 additions & 4 deletions client/checkout/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ export default class WCPayAPI {
}

/**
* Load Stripe for payment request button.
* Load Stripe for Express Checkout with the merchant’s connected account.
*
* @param {boolean} forceAccountRequest True to instantiate the Stripe object with the merchant's account key.
* @return {Promise} Promise with the Stripe object or an error.
*/
loadStripe( forceAccountRequest = false ) {
loadStripeForExpressCheckout() {
return new Promise( ( resolve ) => {
try {
resolve( this.getStripe( forceAccountRequest ) );
// Force Stripe to be loadded with the connected account.
resolve( this.getStripe( true ) );
} catch ( error ) {
// In order to avoid showing console error publicly to users,
// we resolve instead of rejecting when there is an error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ExpressCheckoutContainer = ( props ) => {
const { api, billing, buttonAttributes } = props;

const stripePromise = useMemo( () => {
return api.loadStripe( true );
return api.loadStripeForExpressCheckout();
}, [ api ] );

const options = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const checkPaymentMethodIsAvailable = memoize(

root.render(
<Elements
stripe={ api.loadStripe( true ) }
stripe={ api.loadStripeForExpressCheckout() }
options={ {
mode: 'payment',
paymentMethodCreation: 'manual',
Expand Down
7 changes: 5 additions & 2 deletions client/payment-request/blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ const paymentRequestPaymentMethod = ( api ) => ( {
),
gatewayId: 'woocommerce_payments',
content: (
<PaymentRequestExpress api={ api } stripe={ api.loadStripe( true ) } />
<PaymentRequestExpress
api={ api }
stripe={ api.loadStripeForExpressCheckout() }
/>
),
edit: <ApplePayPreview />,
canMakePayment: ( cartData ) => {
Expand All @@ -46,7 +49,7 @@ const paymentRequestPaymentMethod = ( api ) => ( {
return false;
}

return api.loadStripe( true ).then( ( stripe ) => {
return api.loadStripeForExpressCheckout().then( ( stripe ) => {
// Create a payment request and check if we can make a payment to determine whether to
// show the Payment Request Button or not. This is necessary because a browser might be
// able to load the Stripe JS object, but not support Payment Requests.
Expand Down
7 changes: 5 additions & 2 deletions client/tokenized-payment-request/blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ const ApplePayPreview = () => <img src={ applePayImage } alt="" />;
const tokenizedCartPaymentRequestPaymentMethod = ( api ) => ( {
name: PAYMENT_METHOD_NAME_PAYMENT_REQUEST,
content: (
<PaymentRequestExpress api={ api } stripe={ api.loadStripe( true ) } />
<PaymentRequestExpress
api={ api }
stripe={ api.loadStripeForExpressCheckout() }
/>
),
edit: <ApplePayPreview />,
canMakePayment: ( cartData ) => {
Expand All @@ -40,7 +43,7 @@ const tokenizedCartPaymentRequestPaymentMethod = ( api ) => ( {
return false;
}

return api.loadStripe( true ).then( ( stripe ) => {
return api.loadStripeForExpressCheckout().then( ( stripe ) => {
// Create a payment request and check if we can make a payment to determine whether to
// show the Payment Request Button or not. This is necessary because a browser might be
// able to load the Stripe JS object, but not support Payment Requests.
Expand Down
Loading