Skip to content

Commit 50a0da1

Browse files
authored
Fix express checkout methods dependency (#3847)
* Respect express checkout methods dependency * Filter express payment types before render buttons * Remove unnecessary check on render Amazon Pay checkbox * Add changelog entry * Render Amazon Pay if Amazon Pay is enabled * Update tests for payment request section * Fix Blocks cart and checkout pages express buttons dependency
1 parent 3634860 commit 50a0da1

File tree

10 files changed

+51
-24
lines changed

10 files changed

+51
-24
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
* Tweak - Improve settings page load by delaying oauth URL generation.
4747
* Tweak - Update the Woo logo in the Configure connection modal
4848
* Add - Add currency restriction pill on Amazon Pay.
49+
* Fix - Express checkout methods dependency.
4950

5051
= 9.1.1 - 2025-01-10 =
5152
* Fix - Fixes the webhook order retrieval by intent charges. The processed event is an object, not an array.

client/blocks/upe/index.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,18 @@ Object.entries( paymentMethodsConfig )
109109
} );
110110
} );
111111

112-
if ( getBlocksConfiguration()?.isECEEnabled ) {
113-
// Register Express Checkout Elements.
114-
115-
// Hide behind feature flag so the editor does not show the button.
116-
if ( getBlocksConfiguration()?.isAmazonPayAvailable ) {
117-
registerExpressPaymentMethod( expressCheckoutElementAmazonPay( api ) );
118-
}
112+
// Register Express Checkout Elements.
113+
if (
114+
getBlocksConfiguration()?.isAmazonPayAvailable && // Hide behind feature flag so the editor does not show the button.
115+
getBlocksConfiguration()?.isAmazonPayEnabled
116+
) {
117+
registerExpressPaymentMethod( expressCheckoutElementAmazonPay( api ) );
118+
}
119+
if ( getBlocksConfiguration()?.isPaymentRequestEnabled ) {
119120
registerExpressPaymentMethod( expressCheckoutElementApplePay( api ) );
120121
registerExpressPaymentMethod( expressCheckoutElementGooglePay( api ) );
122+
}
123+
if ( getBlocksConfiguration()?.isLinkEnabled ) {
121124
registerExpressPaymentMethod( expressCheckoutElementStripeLink( api ) );
122125
} else {
123126
// Register Stripe Payment Request.

client/entrypoints/express-checkout/index.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
/*global wcStripeExpressCheckoutPayForOrderParams */
1+
/* global wcStripeExpressCheckoutPayForOrderParams */
2+
/* global wc_stripe_express_checkout_params */
3+
24
import { __ } from '@wordpress/i18n';
35
import { debounce } from 'lodash';
46
import jQuery from 'jquery';
@@ -150,16 +152,28 @@ jQuery( function ( $ ) {
150152

151153
const shippingRates = getShippingRates();
152154

155+
const isPaymentRequestEnabled =
156+
wc_stripe_express_checkout_params?.stripe // eslint-disable-line camelcase
157+
?.is_payment_request_enabled;
158+
const isAmazonPayEnabled =
159+
wc_stripe_express_checkout_params?.stripe // eslint-disable-line camelcase
160+
?.is_amazon_pay_enabled;
161+
const isLinkEnabled =
162+
wc_stripe_express_checkout_params?.stripe?.is_link_enabled; // eslint-disable-line camelcase
163+
153164
// For each supported express payment type, create their own
154165
// express checkout element. This is necessary as some express payment types
155166
// may require different options or configurations, e.g. Amazon Pay
156167
// does not support paymentMethodCreation: 'manual'.
157168
const expressPaymentTypes = [
158-
EXPRESS_PAYMENT_METHOD_SETTING_APPLE_PAY,
159-
EXPRESS_PAYMENT_METHOD_SETTING_GOOGLE_PAY,
160-
EXPRESS_PAYMENT_METHOD_SETTING_AMAZON_PAY,
161-
EXPRESS_PAYMENT_METHOD_SETTING_LINK,
162-
];
169+
isPaymentRequestEnabled &&
170+
EXPRESS_PAYMENT_METHOD_SETTING_APPLE_PAY,
171+
isPaymentRequestEnabled &&
172+
EXPRESS_PAYMENT_METHOD_SETTING_GOOGLE_PAY,
173+
isAmazonPayEnabled && EXPRESS_PAYMENT_METHOD_SETTING_AMAZON_PAY,
174+
isLinkEnabled && EXPRESS_PAYMENT_METHOD_SETTING_LINK,
175+
].filter( Boolean );
176+
163177
expressPaymentTypes.forEach( ( expressPaymentType ) => {
164178
wcStripeECE.createExpressCheckoutElement( expressPaymentType, {
165179
...options,

client/settings/payment-request-section/__tests__/index.test.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ describe( 'PaymentRequestSection', () => {
4141
useAmazonPayEnabledSettings.mockReturnValue( [ false, jest.fn() ] );
4242
global.wc_stripe_settings_params = {
4343
...globalValues,
44-
is_ece_enabled: true,
4544
is_amazon_pay_available: true,
4645
};
4746
} );
@@ -118,22 +117,20 @@ describe( 'PaymentRequestSection', () => {
118117
expect( linkCheckbox ).not.toBeChecked();
119118
} );
120119

121-
it( 'hide Amazon Pay if ECE is disabled', () => {
120+
it( 'render Amazon Pay if feature flag is on', () => {
122121
global.wc_stripe_settings_params = {
123122
...globalValues,
124-
is_ece_enabled: false,
125123
is_amazon_pay_available: true,
126124
};
127125

128126
render( <PaymentRequestSection /> );
129127

130-
expect( screen.queryByText( 'Amazon Pay' ) ).toBeNull();
128+
expect( screen.queryByText( 'Amazon Pay' ) ).toBeInTheDocument();
131129
} );
132130

133131
it( 'hide Amazon Pay if feature flag is off', () => {
134132
global.wc_stripe_settings_params = {
135133
...globalValues,
136-
is_ece_enabled: true,
137134
is_amazon_pay_available: false,
138135
};
139136

client/settings/payment-request-section/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ const PaymentRequestSection = () => {
7676
}
7777
);
7878

79-
const isECEEnabled = wc_stripe_settings_params.is_ece_enabled; // eslint-disable-line camelcase
8079
const isAmazonPayAvailable =
8180
wc_stripe_settings_params.is_amazon_pay_available; // eslint-disable-line camelcase
8281

@@ -239,7 +238,7 @@ const PaymentRequestSection = () => {
239238
</div>
240239
</li>
241240
) }
242-
{ isAmazonPayAvailable && isECEEnabled && (
241+
{ isAmazonPayAvailable && (
243242
<li className="express-checkout has-icon-border">
244243
<div className="express-checkout__checkbox">
245244
<CheckboxControl

includes/admin/class-wc-stripe-settings-controller.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ public function admin_scripts( $hook_suffix ) {
245245
'plugin_version' => WC_STRIPE_VERSION,
246246
'account_country' => $this->account->get_account_country(),
247247
'are_apms_deprecated' => WC_Stripe_Feature_Flags::are_apms_deprecated(),
248-
'is_ece_enabled' => WC_Stripe_Feature_Flags::is_stripe_ece_enabled(),
249248
'is_amazon_pay_available' => WC_Stripe_Feature_Flags::is_amazon_pay_available(),
250249
'oauth_nonce' => wp_create_nonce( 'wc_stripe_get_oauth_urls' ),
251250
];

includes/payment-methods/class-wc-stripe-express-checkout-element.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ public function javascript_params() {
191191
'is_link_enabled' => WC_Stripe_UPE_Payment_Method_Link::is_link_enabled(),
192192
'is_express_checkout_enabled' => $this->express_checkout_helper->is_express_checkout_enabled(),
193193
'is_amazon_pay_enabled' => $this->express_checkout_helper->is_amazon_pay_enabled(),
194+
'is_payment_request_enabled' => $this->express_checkout_helper->is_payment_request_enabled(),
194195
],
195196
'nonce' => [
196197
'payment' => wp_create_nonce( 'wc-stripe-express-checkout' ),

includes/payment-methods/class-wc-stripe-express-checkout-helper.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,13 +1354,20 @@ public function get_button_locations() {
13541354
}
13551355

13561356
/**
1357-
* Returns whether Stripe express checkout element is enabled.
1358-
*
1359-
* This option defines whether Apple Pay and Google Pay buttons are enabled.
1357+
* Returns whether any of the Stripe express checkout element is enabled.=
13601358
*
13611359
* @return boolean
13621360
*/
13631361
public function is_express_checkout_enabled() {
1362+
return $this->is_payment_request_enabled() || $this->is_amazon_pay_enabled() || WC_Stripe_UPE_Payment_Method_Link::is_link_enabled();
1363+
}
1364+
1365+
/**
1366+
* Checks if Apple Pay and Google Pay buttons are enabled.
1367+
*
1368+
* @return boolean
1369+
*/
1370+
public function is_payment_request_enabled() {
13641371
return isset( $this->stripe_settings['payment_request'] ) && 'yes' === $this->stripe_settings['payment_request'];
13651372
}
13661373

includes/payment-methods/class-wc-stripe-upe-payment-gateway.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ public function javascript_params() {
411411
}
412412
}
413413

414+
$express_checkout_helper = new WC_Stripe_Express_Checkout_Helper();
415+
414416
$stripe_params['isCheckout'] = ( is_checkout() || has_block( 'woocommerce/checkout' ) ) && empty( $_GET['pay_for_order'] ); // wpcs: csrf ok.
415417
$stripe_params['return_url'] = $this->get_stripe_return_url();
416418
$stripe_params['ajax_url'] = WC_AJAX::get_endpoint( '%%endpoint%%' );
@@ -428,6 +430,9 @@ public function javascript_params() {
428430
$stripe_params['enabledBillingFields'] = $enabled_billing_fields;
429431
$stripe_params['cartContainsSubscription'] = $this->is_subscription_item_in_cart();
430432
$stripe_params['accountCountry'] = WC_Stripe::get_instance()->account->get_account_country();
433+
$stripe_params['isPaymentRequestEnabled'] = $express_checkout_helper->is_payment_request_enabled();
434+
$stripe_params['isAmazonPayEnabled'] = $express_checkout_helper->is_amazon_pay_enabled();
435+
$stripe_params['isLinkEnabled'] = WC_Stripe_UPE_Payment_Method_Link::is_link_enabled();
431436

432437
// Add appearance settings.
433438
$stripe_params['appearance'] = get_transient( $this->get_appearance_transient_key() );

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
156156
* Tweak - Improve settings page load by delaying oauth URL generation.
157157
* Tweak - Update the Woo logo in the Configure connection modal
158158
* Add - Add currency restriction pill on Amazon Pay.
159+
* Fix - Express checkout methods dependency.
159160

160161
[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

0 commit comments

Comments
 (0)