From 22cb35a2a778fcbd2b68701992fb73e1d5f6c226 Mon Sep 17 00:00:00 2001 From: Alejandro Iglesias Date: Mon, 18 Sep 2023 11:44:06 +0200 Subject: [PATCH 1/7] do not estimated order amount if currency not supported --- .../class-wc-amazon-payments-advanced-api-abstract.php | 8 ++++++-- includes/class-wc-gateway-amazon-payments-advanced.php | 8 +++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/includes/class-wc-amazon-payments-advanced-api-abstract.php b/includes/class-wc-amazon-payments-advanced-api-abstract.php index ac448a7d..fef7b743 100644 --- a/includes/class-wc-amazon-payments-advanced-api-abstract.php +++ b/includes/class-wc-amazon-payments-advanced-api-abstract.php @@ -213,12 +213,16 @@ public static function get_payment_regions() { * @since 1.8.0 * @version 1.8.0 * + * @param string $currency Currency code. + * * @return bool Returns true if shop currency is supported by current payment region. */ - public static function is_region_supports_shop_currency() { + public static function is_region_supports_shop_currency( $currency = false ) { $region = self::get_region(); // Take into consideration external multi-currency plugins when not supported multicurrency region. - $currency = apply_filters( 'woocommerce_amazon_pa_active_currency', get_option( 'woocommerce_currency' ) ); + if ( ! $currency ) { + $currency = apply_filters( 'woocommerce_amazon_pa_active_currency', get_option( 'woocommerce_currency' ) ); + } switch ( $region ) { case 'eu': diff --git a/includes/class-wc-gateway-amazon-payments-advanced.php b/includes/class-wc-gateway-amazon-payments-advanced.php index bf1d69e7..1148827c 100644 --- a/includes/class-wc-gateway-amazon-payments-advanced.php +++ b/includes/class-wc-gateway-amazon-payments-advanced.php @@ -3030,10 +3030,16 @@ protected static function get_estimated_order_amount() { return ''; } + $active_currency = WC_Amazon_Payments_Advanced_Multi_Currency::is_active() ? WC_Amazon_Payments_Advanced_Multi_Currency::get_selected_currency() : get_woocommerce_currency(); + + if ( ! WC_Amazon_Payments_Advanced_API::is_region_supports_shop_currency( $active_currency ) ) { + return ''; + } + return wp_json_encode( array( 'amount' => WC()->cart->get_total( 'amount' ), - 'currencyCode' => get_woocommerce_currency(), + 'currencyCode' => $active_currency, ) ); } From 4b12d68c60629b14cc30b08e097051ba3b3d2667 Mon Sep 17 00:00:00 2001 From: Alejandro Iglesias Date: Mon, 18 Sep 2023 17:56:27 +0200 Subject: [PATCH 2/7] Add unit tests --- ...st-wc-gateway-amazon-payments-advanced.php | 42 ++++++++++++++++--- ...wc-mocker-amazon-payments-advanced-api.php | 20 +++++++++ ...ocker-gateway-amazon-payments-advanced.php | 14 ++++++- 3 files changed, 68 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/includes/test-wc-gateway-amazon-payments-advanced.php b/tests/phpunit/includes/test-wc-gateway-amazon-payments-advanced.php index 1110f7ac..3f92b752 100644 --- a/tests/phpunit/includes/test-wc-gateway-amazon-payments-advanced.php +++ b/tests/phpunit/includes/test-wc-gateway-amazon-payments-advanced.php @@ -113,17 +113,47 @@ public function test_classic_process_payment_succeeds() : void { 'result' => 'success', 'redirect' => '#amazon-pay-classic-id-that-should-not-exist', 'amazonCreateCheckoutParams' => wp_json_encode( WC_Mocker_Amazon_Payments_Advanced_API::get_create_checkout_classic_session_config( array( 'test' ) ) ), - 'amazonEstimatedOrderAmount' => wp_json_encode( - array( - 'amount' => $order_total, - 'currencyCode' => get_woocommerce_currency(), - ) - ), + 'amazonEstimatedOrderAmount' => $mock_gateway::get_estimated_order_amount(), ), $mock_gateway->process_payment( $order->get_id() ) ); } + /** + * Test estimated order amount with multi-currency. + * + * @return void + */ + public function test_estimated_order_amount_output() : void { + $checkout_session_key = apply_filters( 'woocommerce_amazon_pa_checkout_session_key', 'amazon_checkout_session_id' ); + WC()->session->set( $checkout_session_key, null ); + WC()->session->save_data(); + + $order_total = 100; + + update_option( 'woocommerce_default_country', 'ES:B' ); + update_option( 'woocommerce_currency', 'EUR' ); + + $eu_mock_gateway = new WC_Mocker_Gateway_Amazon_Payments_Advanced( $order_total ); + + $this->assertEquals( + wp_json_encode( + array( + 'amount' => $order_total, + 'currencyCode' => 'EUR', + ) + ), + $eu_mock_gateway::get_estimated_order_amount(), + ); + + update_option( 'woocommerce_currency', 'USD' ); + + $this->assertEquals( + '', + $eu_mock_gateway::get_estimated_order_amount() + ); + } + /** * Test maybe_separator_and_checkout_button_single_product method. * diff --git a/tests/phpunit/mockers/class-wc-mocker-amazon-payments-advanced-api.php b/tests/phpunit/mockers/class-wc-mocker-amazon-payments-advanced-api.php index 673d1741..b579cec2 100644 --- a/tests/phpunit/mockers/class-wc-mocker-amazon-payments-advanced-api.php +++ b/tests/phpunit/mockers/class-wc-mocker-amazon-payments-advanced-api.php @@ -51,4 +51,24 @@ public static function get_create_checkout_classic_session_config( array $payloa 'signature' => $signature, ); } + + public static function is_region_supports_shop_currency( $region, $currency = false ) : bool { + + if ( ! $currency ) { + $currency = get_woocommerce_currency(); + } + + switch ( $region ) { + case 'eu': + return 'EUR' === $currency; + case 'gb': + return 'GBP' === $currency; + case 'us': + return 'USD' === $currency; + case 'jp': + return 'JPY' === $currency; + } + + return false; + } } diff --git a/tests/phpunit/mockers/class-wc-mocker-gateway-amazon-payments-advanced.php b/tests/phpunit/mockers/class-wc-mocker-gateway-amazon-payments-advanced.php index 608a7bf2..25949677 100644 --- a/tests/phpunit/mockers/class-wc-mocker-gateway-amazon-payments-advanced.php +++ b/tests/phpunit/mockers/class-wc-mocker-gateway-amazon-payments-advanced.php @@ -77,11 +77,21 @@ protected function get_create_checkout_classic_session_config( $payload ) : arra * * @return string */ - protected static function get_estimated_order_amount() : string { + public static function get_estimated_order_amount() : string { + if ( null === WC()->cart ) { + return ''; + } + + $active_currency = get_woocommerce_currency(); + + if ( ! WC_Mocker_Amazon_Payments_Advanced_API::is_region_supports_shop_currency( WC_Amazon_Payments_Advanced_API::get_settings('payment_region'), $active_currency ) ) { + return ''; + } + return wp_json_encode( array( 'amount' => self::$order_total, - 'currencyCode' => get_woocommerce_currency(), + 'currencyCode' => $active_currency, ) ); } From 93dfbcf59d31f2e8544268ca1aa8e2c1b6c62034 Mon Sep 17 00:00:00 2001 From: Alejandro Iglesias Date: Wed, 20 Sep 2023 13:47:16 +0200 Subject: [PATCH 3/7] amends from CR --- includes/class-wc-gateway-amazon-payments-advanced.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/class-wc-gateway-amazon-payments-advanced.php b/includes/class-wc-gateway-amazon-payments-advanced.php index 1148827c..fd5a87cb 100644 --- a/includes/class-wc-gateway-amazon-payments-advanced.php +++ b/includes/class-wc-gateway-amazon-payments-advanced.php @@ -3030,15 +3030,17 @@ protected static function get_estimated_order_amount() { return ''; } + $total = WC()->cart->get_total( 'amount' ); + $active_currency = WC_Amazon_Payments_Advanced_Multi_Currency::is_active() ? WC_Amazon_Payments_Advanced_Multi_Currency::get_selected_currency() : get_woocommerce_currency(); if ( ! WC_Amazon_Payments_Advanced_API::is_region_supports_shop_currency( $active_currency ) ) { - return ''; + $total = ''; } return wp_json_encode( array( - 'amount' => WC()->cart->get_total( 'amount' ), + 'amount' => $total, 'currencyCode' => $active_currency, ) ); From 3f1e12de4d3697343ae056509d3d8aab12220d94 Mon Sep 17 00:00:00 2001 From: Alejandro Iglesias Date: Wed, 20 Sep 2023 14:00:19 +0200 Subject: [PATCH 4/7] update tests --- .../includes/test-wc-gateway-amazon-payments-advanced.php | 7 ++++++- .../class-wc-mocker-amazon-payments-advanced-api.php | 4 +++- .../class-wc-mocker-gateway-amazon-payments-advanced.php | 8 +++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/includes/test-wc-gateway-amazon-payments-advanced.php b/tests/phpunit/includes/test-wc-gateway-amazon-payments-advanced.php index 3f92b752..91f8b7cb 100644 --- a/tests/phpunit/includes/test-wc-gateway-amazon-payments-advanced.php +++ b/tests/phpunit/includes/test-wc-gateway-amazon-payments-advanced.php @@ -149,7 +149,12 @@ public function test_estimated_order_amount_output() : void { update_option( 'woocommerce_currency', 'USD' ); $this->assertEquals( - '', + wp_json_encode( + array( + 'amount' => '', + 'currencyCode' => 'USD', + ) + ), $eu_mock_gateway::get_estimated_order_amount() ); } diff --git a/tests/phpunit/mockers/class-wc-mocker-amazon-payments-advanced-api.php b/tests/phpunit/mockers/class-wc-mocker-amazon-payments-advanced-api.php index b579cec2..e8f15012 100644 --- a/tests/phpunit/mockers/class-wc-mocker-amazon-payments-advanced-api.php +++ b/tests/phpunit/mockers/class-wc-mocker-amazon-payments-advanced-api.php @@ -52,7 +52,9 @@ public static function get_create_checkout_classic_session_config( array $payloa ); } - public static function is_region_supports_shop_currency( $region, $currency = false ) : bool { + public static function is_region_supports_shop_currency( $currency = false ) : bool { + + $region = WC_Amazon_Payments_Advanced_API::get_payment_region_from_country( WC()->countries->get_base_country() ); if ( ! $currency ) { $currency = get_woocommerce_currency(); diff --git a/tests/phpunit/mockers/class-wc-mocker-gateway-amazon-payments-advanced.php b/tests/phpunit/mockers/class-wc-mocker-gateway-amazon-payments-advanced.php index 25949677..20ec2492 100644 --- a/tests/phpunit/mockers/class-wc-mocker-gateway-amazon-payments-advanced.php +++ b/tests/phpunit/mockers/class-wc-mocker-gateway-amazon-payments-advanced.php @@ -82,15 +82,17 @@ public static function get_estimated_order_amount() : string { return ''; } + $total = self::$order_total; + $active_currency = get_woocommerce_currency(); - if ( ! WC_Mocker_Amazon_Payments_Advanced_API::is_region_supports_shop_currency( WC_Amazon_Payments_Advanced_API::get_settings('payment_region'), $active_currency ) ) { - return ''; + if ( ! WC_Mocker_Amazon_Payments_Advanced_API::is_region_supports_shop_currency( $active_currency ) ) { + $total = ''; } return wp_json_encode( array( - 'amount' => self::$order_total, + 'amount' => $total, 'currencyCode' => $active_currency, ) ); From 617866b6bbcec1ff8a1ab43032d6f690860e02c3 Mon Sep 17 00:00:00 2001 From: Alejandro Iglesias Date: Wed, 20 Sep 2023 18:25:11 +0200 Subject: [PATCH 5/7] do not set the parameter if EOA is empty --- includes/class-wc-gateway-amazon-payments-advanced.php | 6 ++---- src/js/_renderAmazonButton.js | 5 ++++- src/js/non-block/amazon-wc-checkout.js | 4 +++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/includes/class-wc-gateway-amazon-payments-advanced.php b/includes/class-wc-gateway-amazon-payments-advanced.php index fd5a87cb..1148827c 100644 --- a/includes/class-wc-gateway-amazon-payments-advanced.php +++ b/includes/class-wc-gateway-amazon-payments-advanced.php @@ -3030,17 +3030,15 @@ protected static function get_estimated_order_amount() { return ''; } - $total = WC()->cart->get_total( 'amount' ); - $active_currency = WC_Amazon_Payments_Advanced_Multi_Currency::is_active() ? WC_Amazon_Payments_Advanced_Multi_Currency::get_selected_currency() : get_woocommerce_currency(); if ( ! WC_Amazon_Payments_Advanced_API::is_region_supports_shop_currency( $active_currency ) ) { - $total = ''; + return ''; } return wp_json_encode( array( - 'amount' => $total, + 'amount' => WC()->cart->get_total( 'amount' ), 'currencyCode' => $active_currency, ) ); diff --git a/src/js/_renderAmazonButton.js b/src/js/_renderAmazonButton.js index 3cddadf0..44f09937 100644 --- a/src/js/_renderAmazonButton.js +++ b/src/js/_renderAmazonButton.js @@ -18,13 +18,16 @@ const getButtonSettings = ( buttonSettingsFlag, checkoutConfig, estimatedOrderAm // customize the buyer experience placement: amazon_payments_advanced.placement, buttonColor: amazon_payments_advanced.button_color, - estimatedOrderAmount: estimatedOrderAmount, checkoutLanguage: amazon_payments_advanced.button_language !== '' ? amazon_payments_advanced.button_language.replace( '-', '_' ) : undefined }; + if ( estimatedOrderAmount ) { + obj.estimatedOrderAmount = estimatedOrderAmount; + } + if ( 'express' === buttonSettingsFlag ) { obj.productType = amazon_payments_advanced.action; obj.createCheckoutSessionConfig = amazon_payments_advanced.create_checkout_session_config; diff --git a/src/js/non-block/amazon-wc-checkout.js b/src/js/non-block/amazon-wc-checkout.js index f60fdca8..54ff6bb4 100644 --- a/src/js/non-block/amazon-wc-checkout.js +++ b/src/js/non-block/amazon-wc-checkout.js @@ -280,7 +280,9 @@ } } else { obj.createCheckoutSessionConfig = amazon_payments_advanced.create_checkout_session_config; - obj.estimatedOrderAmount = amazon_payments_advanced.estimated_order_amount; + if ( amazon_payments_advanced.estimated_order_amount ) { + obj.estimatedOrderAmount = amazon_payments_advanced.estimated_order_amount; + } } return obj; } From 6a500290bd39ce83ebf4376d89fa05f952de7ff6 Mon Sep 17 00:00:00 2001 From: Alejandro Iglesias Date: Wed, 20 Sep 2023 18:27:50 +0200 Subject: [PATCH 6/7] update tests --- .../test-wc-gateway-amazon-payments-advanced.php | 10 +--------- ...lass-wc-mocker-gateway-amazon-payments-advanced.php | 6 ++---- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/tests/phpunit/includes/test-wc-gateway-amazon-payments-advanced.php b/tests/phpunit/includes/test-wc-gateway-amazon-payments-advanced.php index 91f8b7cb..033f061f 100644 --- a/tests/phpunit/includes/test-wc-gateway-amazon-payments-advanced.php +++ b/tests/phpunit/includes/test-wc-gateway-amazon-payments-advanced.php @@ -148,15 +148,7 @@ public function test_estimated_order_amount_output() : void { update_option( 'woocommerce_currency', 'USD' ); - $this->assertEquals( - wp_json_encode( - array( - 'amount' => '', - 'currencyCode' => 'USD', - ) - ), - $eu_mock_gateway::get_estimated_order_amount() - ); + $this->assertEquals( '', $eu_mock_gateway::get_estimated_order_amount() ); } /** diff --git a/tests/phpunit/mockers/class-wc-mocker-gateway-amazon-payments-advanced.php b/tests/phpunit/mockers/class-wc-mocker-gateway-amazon-payments-advanced.php index 20ec2492..75b66f9b 100644 --- a/tests/phpunit/mockers/class-wc-mocker-gateway-amazon-payments-advanced.php +++ b/tests/phpunit/mockers/class-wc-mocker-gateway-amazon-payments-advanced.php @@ -82,17 +82,15 @@ public static function get_estimated_order_amount() : string { return ''; } - $total = self::$order_total; - $active_currency = get_woocommerce_currency(); if ( ! WC_Mocker_Amazon_Payments_Advanced_API::is_region_supports_shop_currency( $active_currency ) ) { - $total = ''; + return ''; } return wp_json_encode( array( - 'amount' => $total, + 'amount' => self::$order_total, 'currencyCode' => $active_currency, ) ); From 2a60c426634bfbda7edf5acd8587f1e56cc23ed1 Mon Sep 17 00:00:00 2001 From: Alejandro Iglesias Date: Wed, 27 Sep 2023 16:50:38 +0200 Subject: [PATCH 7/7] prevent set eoa on blocks --- ...ayments-advanced-block-compat-abstract.php | 27 +++++++++++ ...payments-advanced-block-compat-classic.php | 13 +++--- ...payments-advanced-block-compat-express.php | 45 ++++++++++--------- .../express/_payment-methods-express.js | 15 +++++++ 4 files changed, 72 insertions(+), 28 deletions(-) diff --git a/includes/compats/woo-blocks/class-wc-amazon-payments-advanced-block-compat-abstract.php b/includes/compats/woo-blocks/class-wc-amazon-payments-advanced-block-compat-abstract.php index 4a61c3de..24deb69a 100644 --- a/includes/compats/woo-blocks/class-wc-amazon-payments-advanced-block-compat-abstract.php +++ b/includes/compats/woo-blocks/class-wc-amazon-payments-advanced-block-compat-abstract.php @@ -118,4 +118,31 @@ protected function get_allowed_currencies() { return array_values( WC_Amazon_Payments_Advanced_API::get_selected_currencies() ); } + + /** + * Get base currency per region. + * + * @param string $region The current region. + * + * @return array + */ + protected function region_base_currencies( $region = '' ) { + + if ( empty( $region ) ) { + $region = WC_Amazon_Payments_Advanced_API::get_region(); + } + + switch ( $region ) { + case 'eu': + return array( 'EUR' ); + case 'gb': + return array( 'GBP' ); + case 'us': + return array( 'USD' ); + case 'jp': + return array( 'JPY' ); + default: + return array(); + } + } } diff --git a/includes/compats/woo-blocks/class-wc-amazon-payments-advanced-block-compat-classic.php b/includes/compats/woo-blocks/class-wc-amazon-payments-advanced-block-compat-classic.php index 6e3d1dd4..f8134110 100644 --- a/includes/compats/woo-blocks/class-wc-amazon-payments-advanced-block-compat-classic.php +++ b/includes/compats/woo-blocks/class-wc-amazon-payments-advanced-block-compat-classic.php @@ -44,12 +44,13 @@ public function is_active() { */ public function get_payment_method_data() { return array( - 'title' => $this->settings['title'], - 'description' => $this->settings['description'], - 'supports' => $this->get_supported_features(), - 'amazonPayPreviewUrl' => esc_url( wc_apa()->plugin_url . '/build/images/amazon-pay-preview.png' ), - 'action' => wc_apa()->get_gateway()->get_current_cart_action(), - 'allowedCurrencies' => $this->get_allowed_currencies(), + 'title' => $this->settings['title'], + 'description' => $this->settings['description'], + 'supports' => $this->get_supported_features(), + 'amazonPayPreviewUrl' => esc_url( wc_apa()->plugin_url . '/build/images/amazon-pay-preview.png' ), + 'action' => wc_apa()->get_gateway()->get_current_cart_action(), + 'allowedCurrencies' => $this->get_allowed_currencies(), + 'regionBaseCurrencies' => $this->region_base_currencies(), ); } diff --git a/includes/compats/woo-blocks/class-wc-amazon-payments-advanced-block-compat-express.php b/includes/compats/woo-blocks/class-wc-amazon-payments-advanced-block-compat-express.php index dd561731..627381a0 100644 --- a/includes/compats/woo-blocks/class-wc-amazon-payments-advanced-block-compat-express.php +++ b/includes/compats/woo-blocks/class-wc-amazon-payments-advanced-block-compat-express.php @@ -42,28 +42,29 @@ public function is_active() { * @return array */ public function get_payment_method_data() { - $wc_apa_gateway = wc_apa()->get_gateway(); - - $checkout_session = $wc_apa_gateway->get_checkout_session_id() ? $wc_apa_gateway->get_checkout_session() : null; - - return array( - 'title' => $this->settings['title'], - 'description' => $this->settings['description'], - 'hide_button_mode' => $this->settings['hide_button_mode'], - 'loggedIn' => ! is_admin() && $checkout_session && ! is_wp_error( $checkout_session ) && true === $wc_apa_gateway->is_checkout_session_still_valid( $checkout_session ), - 'supports' => $this->get_supported_features(), - 'logoutUrl' => $wc_apa_gateway->get_amazon_logout_url(), - 'logoutMessage' => apply_filters( 'woocommerce_amazon_pa_checkout_logout_message', __( 'You\'re logged in with your Amazon Account.', 'woocommerce-gateway-amazon-payments-advanced' ) ), - 'selectedPaymentMethod' => esc_html( $wc_apa_gateway->get_selected_payment_label( $checkout_session ) ), - 'hasPaymentPreferences' => $wc_apa_gateway->has_payment_preferences( $checkout_session ), - 'allOtherGateways' => $this->gateways_to_unset_on_fe(), - 'allowedCurrencies' => $this->get_allowed_currencies(), - 'amazonPayPreviewUrl' => esc_url( wc_apa()->plugin_url . '/build/images/amazon-pay-preview.png' ), - 'amazonAddress' => array( - 'amazonBilling' => $checkout_session && ! is_wp_error( $checkout_session ) && ! empty( $checkout_session->billingAddress ) ? WC_Amazon_Payments_Advanced_API::format_address( $checkout_session->billingAddress ) : null, // phpcs:ignore WordPress.NamingConventions - 'amazonShipping' => $checkout_session && ! is_wp_error( $checkout_session ) && ! empty( $checkout_session->shippingAddress ) ? WC_Amazon_Payments_Advanced_API::format_address( $checkout_session->shippingAddress ) : null, // phpcs:ignore WordPress.NamingConventions - ), - ); + $wc_apa_gateway = wc_apa()->get_gateway(); + + $checkout_session = $wc_apa_gateway->get_checkout_session_id() ? $wc_apa_gateway->get_checkout_session() : null; + + return array( + 'title' => $this->settings['title'], + 'description' => $this->settings['description'], + 'hide_button_mode' => $this->settings['hide_button_mode'], + 'loggedIn' => ! is_admin() && $checkout_session && ! is_wp_error( $checkout_session ) && true === $wc_apa_gateway->is_checkout_session_still_valid( $checkout_session ), + 'supports' => $this->get_supported_features(), + 'logoutUrl' => $wc_apa_gateway->get_amazon_logout_url(), + 'logoutMessage' => apply_filters( 'woocommerce_amazon_pa_checkout_logout_message', __( 'You\'re logged in with your Amazon Account.', 'woocommerce-gateway-amazon-payments-advanced' ) ), + 'selectedPaymentMethod' => esc_html( $wc_apa_gateway->get_selected_payment_label( $checkout_session ) ), + 'hasPaymentPreferences' => $wc_apa_gateway->has_payment_preferences( $checkout_session ), + 'allOtherGateways' => $this->gateways_to_unset_on_fe(), + 'allowedCurrencies' => $this->get_allowed_currencies(), + 'amazonPayPreviewUrl' => esc_url( wc_apa()->plugin_url . '/build/images/amazon-pay-preview.png' ), + 'amazonAddress' => array( + 'amazonBilling' => $checkout_session && ! is_wp_error( $checkout_session ) && ! empty( $checkout_session->billingAddress ) ? WC_Amazon_Payments_Advanced_API::format_address( $checkout_session->billingAddress ) : null, // phpcs:ignore WordPress.NamingConventions + 'amazonShipping' => $checkout_session && ! is_wp_error( $checkout_session ) && ! empty( $checkout_session->shippingAddress ) ? WC_Amazon_Payments_Advanced_API::format_address( $checkout_session->shippingAddress ) : null, // phpcs:ignore WordPress.NamingConventions + ), + 'regionBaseCurrencies' => $this->region_base_currencies(), + ); } diff --git a/src/js/payments-methods/express/_payment-methods-express.js b/src/js/payments-methods/express/_payment-methods-express.js index 0acefd90..170c7a78 100644 --- a/src/js/payments-methods/express/_payment-methods-express.js +++ b/src/js/payments-methods/express/_payment-methods-express.js @@ -7,6 +7,7 @@ import { useEffect, useState } from '@wordpress/element'; * Internal dependencies */ import { renderAmazonButton } from '../../_renderAmazonButton'; +import { settings } from './_settings'; /** * Returns a react component and also sets an observer for the onCheckoutAfterProcessingWithSuccess event. @@ -23,6 +24,16 @@ const AmazonPayExpressBtn = ( props ) => { return
; }; + +/** + * Is estimated order amount supported. + * @param {object} currency + * @returns {boolean} True if estimated order amount is supported. + */ +const isEstimatedOrderAmountSupported = ( currency ) => { + return currency.code && settings.regionBaseCurrencies && settings.regionBaseCurrencies.includes( currency.code ); +}; + /** * Returns the estimated order amount button attribute. * @param {object} props @@ -32,6 +43,10 @@ const calculateEstimatedOrderAmount = ( props ) => { const { billing } = props; const { currency } = billing; + if ( ! isEstimatedOrderAmountSupported( currency ) ) { + return null; + } + /** * Get how many charactes are present in the cart's total value. * So if the checkout value was 23.76,