Skip to content

Commit 8f2b1ac

Browse files
Add error handling for loadError in ECE (#9416)
1 parent 2eaebf6 commit 8f2b1ac

File tree

6 files changed

+42
-10
lines changed

6 files changed

+42
-10
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+
Handle loadError in ECE for Block Context Initialization.

client/checkout/express-checkout-buttons.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
margin-top: 1em;
33
width: 100%;
44
clear: both;
5-
margin-bottom: 1.5em;
65

76
.woocommerce-cart & {
87
margin-bottom: 0;

client/express-checkout/index.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,17 @@ jQuery( ( $ ) => {
242242
getExpressCheckoutButtonStyleSettings()
243243
);
244244

245-
wcpayECE.showButton( eceButton );
245+
wcpayECE.renderButton( eceButton );
246+
247+
eceButton.on( 'loaderror', () => {
248+
wcPayECEError = __(
249+
'The cart is incompatible with express checkout.',
250+
'woocommerce-payments'
251+
);
252+
if ( ! document.getElementById( 'wcpay-woopay-button' ) ) {
253+
wcpayECE?.getButtonSeparator()?.hide();
254+
}
255+
} );
246256

247257
eceButton.on( 'click', function ( event ) {
248258
// If login is required for checkout, display redirect confirmation dialog.
@@ -326,7 +336,19 @@ jQuery( ( $ ) => {
326336
onCancelHandler();
327337
} );
328338

329-
eceButton.on( 'ready', onReadyHandler );
339+
eceButton.on( 'ready', ( onReadyParams ) => {
340+
onReadyHandler( onReadyParams );
341+
342+
if (
343+
onReadyParams?.availablePaymentMethods &&
344+
Object.values(
345+
onReadyParams.availablePaymentMethods
346+
).filter( Boolean ).length
347+
) {
348+
wcpayECE.show();
349+
wcpayECE.getButtonSeparator().show();
350+
}
351+
} );
330352

331353
if ( getExpressCheckoutData( 'is_product_page' ) ) {
332354
wcpayECE.attachProductPageEventListeners( elements );
@@ -520,18 +542,24 @@ jQuery( ( $ ) => {
520542
},
521543

522544
getElements: () => {
523-
return $(
524-
'.wcpay-payment-request-wrapper,#wcpay-express-checkout-button-separator'
525-
);
545+
return $( '#wcpay-express-checkout-element' );
546+
},
547+
548+
getButtonSeparator: () => {
549+
return $( '#wcpay-express-checkout-button-separator' );
526550
},
527551

528552
show: () => {
529553
wcpayECE.getElements().show();
530554
},
531555

532-
showButton: ( eceButton ) => {
556+
hide: () => {
557+
wcpayECE.getElements().hide();
558+
wcpayECE.getButtonSeparator().hide();
559+
},
560+
561+
renderButton: ( eceButton ) => {
533562
if ( $( '#wcpay-express-checkout-element' ).length ) {
534-
wcpayECE.show();
535563
eceButton.mount( '#wcpay-express-checkout-element' );
536564
}
537565
},

client/express-checkout/utils/checkPaymentMethodIsAvailable.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const checkPaymentMethodIsAvailable = memoize(
4747
} }
4848
>
4949
<ExpressCheckoutElement
50+
onLoadError={ () => resolve( false ) }
5051
options={ {
5152
paymentMethods: {
5253
amazonPay: 'never',

includes/express-checkout/class-wc-payments-express-checkout-button-display-handler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function display_express_checkout_buttons() {
141141

142142
// When Payment Request button is enabled, we need the separator markup on the page, but hidden in case the browser doesn't have any payment request methods to display.
143143
// More details: https://github.com/Automattic/woocommerce-payments/pull/5399#discussion_r1073633776.
144-
$separator_starts_hidden = ( $should_show_payment_request || $should_show_express_checkout_button ) && ! $should_show_woopay;
144+
$separator_starts_hidden = ! $should_show_woopay;
145145
if ( $should_show_woopay || $should_show_payment_request || $should_show_express_checkout_button ) {
146146
?>
147147
<div class='wcpay-payment-request-wrapper' >

includes/express-checkout/class-wc-payments-express-checkout-button-handler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public function display_express_checkout_button_html() {
288288
return;
289289
}
290290
?>
291-
<div id="wcpay-express-checkout-element"></div>
291+
<div id="wcpay-express-checkout-element" style="display: none;"></div>
292292
<?php
293293
}
294294

0 commit comments

Comments
 (0)