Skip to content

Commit

Permalink
Merge branch 'develop' into tweak/hiding-actions-for-pending-amazon-p…
Browse files Browse the repository at this point in the history
…ay-orders
  • Loading branch information
wjrosa committed Feb 10, 2025
2 parents 65a0c5c + beb2828 commit 98cd987
Show file tree
Hide file tree
Showing 18 changed files with 236 additions and 45 deletions.
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

= 9.2.0 - xxxx-xx-xx =
* Fix - Hides "pay" and "cancel" buttons on the order received page when an Amazon Pay order is pending, since it may take a while to be confirmed.
* Dev - Replaces part of the StoreAPI call code for the cart endpoints to use the newly introduced filter.
* Dev - Add new E2E tests for Link express checkout.
* Add - Add Amazon Pay to block cart and block checkout.
* Fix - Remove intentional delay when displaying tax-related notice for express checkout, causing click event to time out.
* Fix - Fixes an issue when saving Bancontact and iDEAL methods with SEPA Direct Debit disabled.
Expand Down Expand Up @@ -45,6 +47,8 @@
* Tweak - Improve slow query for legacy SEPA subscriptions on WC status tools page by caching the data.
* Tweak - Improve settings page load by delaying oauth URL generation.
* Tweak - Update the Woo logo in the Configure connection modal
* Add - Add currency restriction pill on Amazon Pay.
* Fix - Express checkout methods dependency.

= 9.1.1 - 2025-01-10 =
* Fix - Fixes the webhook order retrieval by intent charges. The processed event is an object, not an array.
Expand Down
1 change: 1 addition & 0 deletions client/blocks/express-checkout/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
normalizeLineItems,
} from 'wcstripe/express-checkout/utils';
import 'wcstripe/express-checkout/compatibility/wc-order-attribution';
import 'wcstripe/express-checkout/compatibility/wc-product-page';

export const useExpressCheckout = ( {
api,
Expand Down
17 changes: 10 additions & 7 deletions client/blocks/upe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,18 @@ Object.entries( paymentMethodsConfig )
} );
} );

if ( getBlocksConfiguration()?.isECEEnabled ) {
// Register Express Checkout Elements.

// Hide behind feature flag so the editor does not show the button.
if ( getBlocksConfiguration()?.isAmazonPayAvailable ) {
registerExpressPaymentMethod( expressCheckoutElementAmazonPay( api ) );
}
// Register Express Checkout Elements.
if (
getBlocksConfiguration()?.isAmazonPayAvailable && // Hide behind feature flag so the editor does not show the button.
getBlocksConfiguration()?.isAmazonPayEnabled
) {
registerExpressPaymentMethod( expressCheckoutElementAmazonPay( api ) );
}
if ( getBlocksConfiguration()?.isPaymentRequestEnabled ) {
registerExpressPaymentMethod( expressCheckoutElementApplePay( api ) );
registerExpressPaymentMethod( expressCheckoutElementGooglePay( api ) );
}
if ( getBlocksConfiguration()?.isLinkEnabled ) {
registerExpressPaymentMethod( expressCheckoutElementStripeLink( api ) );
} else {
// Register Stripe Payment Request.
Expand Down
56 changes: 32 additions & 24 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 All @@ -9,8 +11,8 @@ import {
getExpressCheckoutButtonAppearance,
getExpressCheckoutButtonStyleSettings,
getExpressCheckoutData,
isManualPaymentMethodCreation,
getPaymentMethodTypesForExpressMethod,
isManualPaymentMethodCreation,
normalizeLineItems,
} from 'wcstripe/express-checkout/utils';
import {
Expand All @@ -26,6 +28,7 @@ import {
import { getStripeServerData } from 'wcstripe/stripe-utils';
import { getAddToCartVariationParams } from 'wcstripe/utils';
import 'wcstripe/express-checkout/compatibility/wc-order-attribution';
import 'wcstripe/express-checkout/compatibility/wc-product-page';
import './styles.scss';
import {
EXPRESS_PAYMENT_METHOD_SETTING_AMAZON_PAY,
Expand Down Expand Up @@ -150,16 +153,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 Expand Up @@ -513,27 +528,12 @@ jQuery( function ( $ ) {
addToCart: () => {
let productId = $( '.single_add_to_cart_button' ).val();

// Check if product is a variable product.
if ( $( '.single_variation_wrap' ).length ) {
productId = $( '.single_variation_wrap' )
.find( 'input[name="product_id"]' )
.val();
}

if ( $( '.wc-bookings-booking-form' ).length ) {
productId = $( '.wc-booking-product-id' ).val();
}

const data = {
qty: $( quantityInputSelector ).val(),
};

if ( useLegacyCartEndpoints ) {
data.product_id = productId;
data.attributes = wcStripeECE.getAttributes().data;
} else {
data.id = productId;
data.variation = [];
if ( $( '.wc-bookings-booking-form' ).length ) {
productId = $( '.wc-booking-product-id' ).val();
}

// Add extension data to the POST body
Expand All @@ -556,10 +556,18 @@ jQuery( function ( $ ) {
}
} );

// Legacy support for variations.
if ( useLegacyCartEndpoints ) {
data.product_id = productId;
data.attributes = wcStripeECE.getAttributes().data;

return api.expressCheckoutAddToCartLegacy( data );
}

// BlocksAPI partial support (lacking support for variations).
data.id = productId;
data.variation = [];

return api.expressCheckoutAddToCart( data );
},

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { applyFilters } from '@wordpress/hooks';
import { render } from '@testing-library/react';
import 'wcstripe/express-checkout/compatibility/wc-product-page';

describe( 'ECE product page compatibility', () => {
describe( 'filters out data when adding item to the cart', () => {
it( 'single variation form is present', () => {
function App() {
return (
<div className="single_variation_wrap">
<input name="product_id" defaultValue="123" />
</div>
);
}
render( <App /> );

const cartAddItemData = applyFilters(
'wcstripe.express-checkout.cart-add-item',
{}
);

expect( cartAddItemData ).toStrictEqual( { id: 123 } );
} );
} );
} );
3 changes: 0 additions & 3 deletions client/express-checkout/compatibility/wc-order-attribution.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
* External dependencies
*/
import { addFilter } from '@wordpress/hooks';
import { extractOrderAttributionData } from 'wcstripe/blocks/utils';

Expand Down
24 changes: 24 additions & 0 deletions client/express-checkout/compatibility/wc-product-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import jQuery from 'jquery';
import { addFilter } from '@wordpress/hooks';

/**
* Sets the product ID when using the BlocksAPI and single variation form is present.
*/
addFilter(
'wcstripe.express-checkout.cart-add-item',
'automattic/wcstripe/express-checkout',
( productData ) => {
const $variationInformation = jQuery( '.single_variation_wrap' );
if ( ! $variationInformation.length ) {
return productData;
}

const productId = $variationInformation
.find( 'input[name="product_id"]' )
.val();
return {
...productData,
id: parseInt( productId, 10 ),
};
}
);
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
11 changes: 9 additions & 2 deletions client/settings/payment-request-section/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '../../data';
import './styles.scss';
import AmazonPayIcon from '../../payment-method-icons/amazon-pay';
import PaymentMethodMissingCurrencyPill from '../../components/payment-method-missing-currency-pill';
import {
PAYMENT_METHOD_CARD,
PAYMENT_METHOD_LINK,
Expand Down Expand Up @@ -75,7 +76,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 +238,7 @@ const PaymentRequestSection = () => {
</div>
</li>
) }
{ isAmazonPayAvailable && isECEEnabled && (
{ isAmazonPayAvailable && (
<li className="express-checkout has-icon-border">
<div className="express-checkout__checkbox">
<CheckboxControl
Expand All @@ -259,6 +259,13 @@ const PaymentRequestSection = () => {
'Amazon Pay',
'woocommerce-gateway-stripe'
) }
<PaymentMethodMissingCurrencyPill
id="amazon_pay"
label={ __(
'Amazon Pay',
'woocommerce-gateway-stripe'
) }
/>
</div>
<div className="express-checkout__description">
{
Expand Down
13 changes: 13 additions & 0 deletions client/utils/use-payment-method-currencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
PAYMENT_METHOD_ALIPAY,
PAYMENT_METHOD_KLARNA,
PAYMENT_METHOD_WECHAT_PAY,
PAYMENT_METHOD_AMAZON_PAY,
} from 'wcstripe/stripe-utils/constants';

const accountCountry =
Expand Down Expand Up @@ -152,6 +153,7 @@ const getWechatPayCurrencies = () => {
'PT',
'ES',
];

if ( EuroSupportedCountries.includes( accountCountry ) ) {
upeCurrencies = [ 'EUR', 'CNY' ];
}
Expand Down Expand Up @@ -206,6 +208,15 @@ const getKlarnaCurrencies = () => {
);
};

const getAmazonPayCurrencies = () => {
switch ( accountCountry ) {
case 'US':
return [ 'USD' ];
default:
return [ 'USD' ];
}
};

export const usePaymentMethodCurrencies = ( paymentMethodId ) => {
const { isUpeEnabled } = useContext( UpeToggleContext );

Expand All @@ -216,6 +227,8 @@ export const usePaymentMethodCurrencies = ( paymentMethodId ) => {
return getWechatPayCurrencies();
case PAYMENT_METHOD_KLARNA:
return getKlarnaCurrencies();
case PAYMENT_METHOD_AMAZON_PAY:
return getAmazonPayCurrencies();
default:
return PaymentMethodsMap[ paymentMethodId ]?.currencies || [];
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ public function javascript_params() {
}
}

$express_checkout_helper = new WC_Stripe_Express_Checkout_Helper();

$stripe_params['isCheckout'] = ( is_checkout() || has_block( 'woocommerce/checkout' ) ) && empty( $_GET['pay_for_order'] ); // wpcs: csrf ok.
$stripe_params['return_url'] = $this->get_stripe_return_url();
$stripe_params['ajax_url'] = WC_AJAX::get_endpoint( '%%endpoint%%' );
Expand All @@ -431,6 +433,9 @@ public function javascript_params() {
$stripe_params['enabledBillingFields'] = $enabled_billing_fields;
$stripe_params['cartContainsSubscription'] = $this->is_subscription_item_in_cart();
$stripe_params['accountCountry'] = WC_Stripe::get_instance()->account->get_account_country();
$stripe_params['isPaymentRequestEnabled'] = $express_checkout_helper->is_payment_request_enabled();
$stripe_params['isAmazonPayEnabled'] = $express_checkout_helper->is_amazon_pay_enabled();
$stripe_params['isLinkEnabled'] = WC_Stripe_UPE_Payment_Method_Link::is_link_enabled();

// Add appearance settings.
$stripe_params['appearance'] = get_transient( $this->get_appearance_transient_key() );
Expand Down
Loading

0 comments on commit 98cd987

Please sign in to comment.