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

Fix express checkout methods dependency #3847

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* Fix - Improve the appearance of Stripe elements in checkout pages to match the store theme.
* Fix - Hide ECE button for synced subscription variations.
* Fix - Use the original shipping address for Amazon Pay pay for orders.
* Fix - Express checkout methods dependency.
* Tweak - Improve settings page load by delaying oauth URL generation.
* Tweak - Update the Woo logo in the Configure connection modal

Expand Down
26 changes: 20 additions & 6 deletions client/entrypoints/express-checkout/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/*global wcStripeExpressCheckoutPayForOrderParams */
/* global wcStripeExpressCheckoutPayForOrderParams */
/* global wc_stripe_express_checkout_params */

import { __ } from '@wordpress/i18n';
import { debounce } from 'lodash';
import jQuery from 'jquery';
Expand Down Expand Up @@ -150,16 +152,28 @@ jQuery( function ( $ ) {

const shippingRates = getShippingRates();

const isPaymentRequestEnabled =
wc_stripe_express_checkout_params?.stripe // eslint-disable-line camelcase
?.is_payment_request_enabled;
const isAmazonPayEnabled =
wc_stripe_express_checkout_params?.stripe // eslint-disable-line camelcase
?.is_amazon_pay_enabled;
const isLinkEnabled =
wc_stripe_express_checkout_params?.stripe?.is_link_enabled; // eslint-disable-line camelcase

// For each supported express payment type, create their own
// express checkout element. This is necessary as some express payment types
// may require different options or configurations, e.g. Amazon Pay
// does not support paymentMethodCreation: 'manual'.
const expressPaymentTypes = [
EXPRESS_PAYMENT_METHOD_SETTING_APPLE_PAY,
EXPRESS_PAYMENT_METHOD_SETTING_GOOGLE_PAY,
EXPRESS_PAYMENT_METHOD_SETTING_AMAZON_PAY,
EXPRESS_PAYMENT_METHOD_SETTING_LINK,
];
isPaymentRequestEnabled &&
EXPRESS_PAYMENT_METHOD_SETTING_APPLE_PAY,
isPaymentRequestEnabled &&
EXPRESS_PAYMENT_METHOD_SETTING_GOOGLE_PAY,
isAmazonPayEnabled && EXPRESS_PAYMENT_METHOD_SETTING_AMAZON_PAY,
isLinkEnabled && EXPRESS_PAYMENT_METHOD_SETTING_LINK,
].filter( Boolean );

expressPaymentTypes.forEach( ( expressPaymentType ) => {
wcStripeECE.createExpressCheckoutElement( expressPaymentType, {
...options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ describe( 'PaymentRequestSection', () => {
useAmazonPayEnabledSettings.mockReturnValue( [ false, jest.fn() ] );
global.wc_stripe_settings_params = {
...globalValues,
is_ece_enabled: true,
is_amazon_pay_available: true,
};
} );
Expand Down Expand Up @@ -118,22 +117,20 @@ describe( 'PaymentRequestSection', () => {
expect( linkCheckbox ).not.toBeChecked();
} );

it( 'hide Amazon Pay if ECE is disabled', () => {
it( 'render Amazon Pay if feature flag is on', () => {
global.wc_stripe_settings_params = {
...globalValues,
is_ece_enabled: false,
is_amazon_pay_available: true,
};

render( <PaymentRequestSection /> );

expect( screen.queryByText( 'Amazon Pay' ) ).toBeNull();
expect( screen.queryByText( 'Amazon Pay' ) ).toBeInTheDocument();
} );

it( 'hide Amazon Pay if feature flag is off', () => {
global.wc_stripe_settings_params = {
...globalValues,
is_ece_enabled: true,
is_amazon_pay_available: false,
};

Expand Down
3 changes: 1 addition & 2 deletions client/settings/payment-request-section/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ const PaymentRequestSection = () => {
}
);

const isECEEnabled = wc_stripe_settings_params.is_ece_enabled; // eslint-disable-line camelcase
const isAmazonPayAvailable =
wc_stripe_settings_params.is_amazon_pay_available; // eslint-disable-line camelcase

Expand Down Expand Up @@ -238,7 +237,7 @@ const PaymentRequestSection = () => {
</div>
</li>
) }
{ isAmazonPayAvailable && isECEEnabled && (
{ isAmazonPayAvailable && (
<li className="express-checkout has-icon-border">
<div className="express-checkout__checkbox">
<CheckboxControl
Expand Down
1 change: 0 additions & 1 deletion includes/admin/class-wc-stripe-settings-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ public function admin_scripts( $hook_suffix ) {
'plugin_version' => WC_STRIPE_VERSION,
'account_country' => $this->account->get_account_country(),
'are_apms_deprecated' => WC_Stripe_Feature_Flags::are_apms_deprecated(),
'is_ece_enabled' => WC_Stripe_Feature_Flags::is_stripe_ece_enabled(),
'is_amazon_pay_available' => WC_Stripe_Feature_Flags::is_amazon_pay_available(),
'oauth_nonce' => wp_create_nonce( 'wc_stripe_get_oauth_urls' ),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public function javascript_params() {
'is_link_enabled' => WC_Stripe_UPE_Payment_Method_Link::is_link_enabled(),
'is_express_checkout_enabled' => $this->express_checkout_helper->is_express_checkout_enabled(),
'is_amazon_pay_enabled' => $this->express_checkout_helper->is_amazon_pay_enabled(),
'is_payment_request_enabled' => $this->express_checkout_helper->is_payment_request_enabled(),
],
'nonce' => [
'payment' => wp_create_nonce( 'wc-stripe-express-checkout' ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1354,13 +1354,20 @@ public function get_button_locations() {
}

/**
* Returns whether Stripe express checkout element is enabled.
*
* This option defines whether Apple Pay and Google Pay buttons are enabled.
* Returns whether any of the Stripe express checkout element is enabled.=
*
* @return boolean
*/
public function is_express_checkout_enabled() {
return $this->is_payment_request_enabled() || $this->is_amazon_pay_enabled() || WC_Stripe_UPE_Payment_Method_Link::is_link_enabled();
}

/**
* Checks if Apple Pay and Google Pay buttons are enabled.
*
* @return boolean
*/
public function is_payment_request_enabled() {
return isset( $this->stripe_settings['payment_request'] ) && 'yes' === $this->stripe_settings['payment_request'];
}

Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
* Fix - Improve the appearance of Stripe elements in checkout pages to match the store theme.
* Fix - Hide ECE button for synced subscription variations.
* Fix - Use the original shipping address for Amazon Pay pay for orders.
* Fix - Express checkout methods dependency.
* Tweak - Improve settings page load by delaying oauth URL generation.
* Tweak - Update the Woo logo in the Configure connection modal

Expand Down
Loading