From 0d3901dcc629fe0c3311dad07177b4ea9cf152dd Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Tue, 28 Mar 2023 11:50:58 +0300 Subject: [PATCH 01/16] added method to provide extra headers --- ...ss-wc-amazon-payments-advanced-api-abstract.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/includes/class-wc-amazon-payments-advanced-api-abstract.php b/includes/class-wc-amazon-payments-advanced-api-abstract.php index ac448a7d..ef708f13 100644 --- a/includes/class-wc-amazon-payments-advanced-api-abstract.php +++ b/includes/class-wc-amazon-payments-advanced-api-abstract.php @@ -531,4 +531,18 @@ public static function validate_api_keys() { return false; } + /** + * Returns extra headers to be added to requests against Amazon Pay API. + * + * @return array + */ + protected static function get_amazon_pay_platform_headers() { + $version_suffix = wc_apa()->get_gateway() instanceof WC_Gateway_Amazon_Payments_Advanced_Legacy ? '-legacy' : ''; + + return array( + 'x-amz-pay-platform-version' => WC()->version, + 'x-amz-pay-integrator-version' => wc_apa()->version . $version_suffix, + 'x-amz-pay-integrator-id' => static::AMAZON_PAY_FOR_WOOCOMMERCE_SP_ID, + ); + } } From 8cb2cf20ea1aefbb15f96fdabc9913fb18e96d4e Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Tue, 28 Mar 2023 12:27:04 +0300 Subject: [PATCH 02/16] updates V2 request headers --- .../class-wc-amazon-payments-advanced-api.php | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/includes/class-wc-amazon-payments-advanced-api.php b/includes/class-wc-amazon-payments-advanced-api.php index cb5eddd8..66f7a4cb 100644 --- a/includes/class-wc-amazon-payments-advanced-api.php +++ b/includes/class-wc-amazon-payments-advanced-api.php @@ -76,7 +76,7 @@ public static function validate_api_keys() { $payload = self::create_checkout_session_params(); $headers = array( 'x-amz-pay-Idempotency-Key' => uniqid() ); - $result = $client->createCheckoutSession( $payload, $headers ); + $result = $client->createCheckoutSession( $payload, array_merge( $headers, self::get_amazon_pay_platform_headers() ) ); if ( ! isset( $result['status'] ) || 201 !== $result['status'] ) { throw new Exception( __( 'Error: API is not responding.', 'woocommerce-gateway-amazon-payments-advanced' ) ); } @@ -99,7 +99,7 @@ public static function validate_api_keys() { * @return array */ public static function trigger_alexa_notifications( $payload ) { - return self::get_client()->deliveryTrackers( $payload ); + return self::get_client()->deliveryTrackers( $payload, self::get_amazon_pay_platform_headers() ); } /** @@ -486,7 +486,7 @@ public static function get_create_checkout_classic_session_config( $payload ) { */ public static function get_checkout_session_data( $checkout_session_id ) { $client = self::get_client(); - $result = $client->getCheckoutSession( $checkout_session_id ); + $result = $client->getCheckoutSession( $checkout_session_id, self::get_amazon_pay_platform_headers() ); if ( ! isset( $result['status'] ) || 200 !== $result['status'] ) { return new WP_Error( $result['status'], __( 'Error while getting checkout session.', 'woocommerce-gateway-amazon-payments-advanced' ) ); } @@ -543,7 +543,7 @@ public static function update_checkout_session_data( $checkout_session_id, $data ) ); - $result = $client->updateCheckoutSession( $checkout_session_id, $data, $headers ); + $result = $client->updateCheckoutSession( $checkout_session_id, $data, array_merge( $headers, self::get_amazon_pay_platform_headers() ) ); $response = json_decode( $result['response'] ); @@ -567,7 +567,7 @@ public static function update_checkout_session_data( $checkout_session_id, $data public static function complete_checkout_session( $checkout_session_id, $data = array() ) { $client = self::get_client(); wc_apa()->log( sprintf( 'Checkout Session ID %s', $checkout_session_id ), $data ); - $result = $client->completeCheckoutSession( $checkout_session_id, $data ); + $result = $client->completeCheckoutSession( $checkout_session_id, $data, self::get_amazon_pay_platform_headers() ); $response = json_decode( $result['response'] ); @@ -619,7 +619,7 @@ public static function get_languages_per_region() { */ public static function get_charge_permission( $charge_permission_id ) { $client = self::get_client(); - $result = $client->getChargePermission( $charge_permission_id ); + $result = $client->getChargePermission( $charge_permission_id, self::get_amazon_pay_platform_headers() ); $response = json_decode( $result['response'] ); @@ -638,7 +638,7 @@ public static function get_charge_permission( $charge_permission_id ) { */ public static function get_charge( $charge_id ) { $client = self::get_client(); - $result = $client->getCharge( $charge_id ); + $result = $client->getCharge( $charge_id, self::get_amazon_pay_platform_headers() ); $response = json_decode( $result['response'] ); @@ -657,7 +657,7 @@ public static function get_charge( $charge_id ) { */ public static function get_refund( $refund_id ) { $client = self::get_client(); - $result = $client->getRefund( $refund_id ); + $result = $client->getRefund( $refund_id, self::get_amazon_pay_platform_headers() ); $response = json_decode( $result['response'] ); @@ -723,7 +723,8 @@ public static function capture_charge( $charge_id, $data = array() ) { $headers, array( 'x-amz-pay-idempotency-key' => self::generate_uuid(), - ) + ), + self::get_amazon_pay_platform_headers() ) ); @@ -779,7 +780,8 @@ public static function refund_charge( $charge_id, $amount = null, $data = array( $headers, array( 'x-amz-pay-idempotency-key' => self::generate_uuid(), - ) + ), + self::get_amazon_pay_platform_headers() ) ); @@ -810,7 +812,8 @@ public static function cancel_charge( $charge_id, $reason = 'Order Cancelled' ) $charge_id, array( 'cancellationReason' => $reason, // TODO: Make dynamic. - ) + ), + self::get_amazon_pay_platform_headers() ); $response = json_decode( $result['response'] ); @@ -943,7 +946,8 @@ public static function create_charge( $charge_permission_id, $data ) { $headers, array( 'x-amz-pay-idempotency-key' => self::generate_uuid(), - ) + ), + self::get_amazon_pay_platform_headers() ) ); @@ -978,7 +982,7 @@ public static function close_charge_permission( $charge_permission_id, $reason = array( 'closureReason' => $reason, // TODO: Make dynamic. ), - $headers + array_merge( $headers, self::get_amazon_pay_platform_headers() ) ); $response = json_decode( $result['response'] ); From d067d2a387740edf10b4c2b5372c289a0810075e Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Tue, 28 Mar 2023 16:33:49 +0300 Subject: [PATCH 03/16] amended code based on CR --- .../class-wc-amazon-payments-advanced-api.php | 69 +++++++++++-------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/includes/class-wc-amazon-payments-advanced-api.php b/includes/class-wc-amazon-payments-advanced-api.php index 66f7a4cb..bc071e4a 100644 --- a/includes/class-wc-amazon-payments-advanced-api.php +++ b/includes/class-wc-amazon-payments-advanced-api.php @@ -75,8 +75,11 @@ public static function validate_api_keys() { $client = self::get_client(); $payload = self::create_checkout_session_params(); - $headers = array( 'x-amz-pay-Idempotency-Key' => uniqid() ); - $result = $client->createCheckoutSession( $payload, array_merge( $headers, self::get_amazon_pay_platform_headers() ) ); + $headers = array_merge( + array( 'x-amz-pay-Idempotency-Key' => uniqid() ), + self::get_amazon_pay_platform_headers() + ); + $result = $client->createCheckoutSession( $payload, $headers ); if ( ! isset( $result['status'] ) || 201 !== $result['status'] ) { throw new Exception( __( 'Error: API is not responding.', 'woocommerce-gateway-amazon-payments-advanced' ) ); } @@ -533,7 +536,10 @@ protected static function normalize_address( $address ) { public static function update_checkout_session_data( $checkout_session_id, $data = array() ) { $client = self::get_client(); - $headers = self::get_extra_headers( __FUNCTION__ ); + $headers = array_merge( + self::get_extra_headers( __FUNCTION__ ), + self::get_amazon_pay_platform_headers() + ); wc_apa()->log( sprintf( 'Checkout Session ID %s', $checkout_session_id ), @@ -543,7 +549,7 @@ public static function update_checkout_session_data( $checkout_session_id, $data ) ); - $result = $client->updateCheckoutSession( $checkout_session_id, $data, array_merge( $headers, self::get_amazon_pay_platform_headers() ) ); + $result = $client->updateCheckoutSession( $checkout_session_id, $data, $headers ); $response = json_decode( $result['response'] ); @@ -716,16 +722,18 @@ public static function capture_charge( $charge_id, $data = array() ) { ) ); + $headers = array_merge( + $headers, + array( + 'x-amz-pay-idempotency-key' => self::generate_uuid(), + ), + self::get_amazon_pay_platform_headers() + ); + $result = $client->captureCharge( $charge_id, $data, - array_merge( - $headers, - array( - 'x-amz-pay-idempotency-key' => self::generate_uuid(), - ), - self::get_amazon_pay_platform_headers() - ) + $headers ); $response = json_decode( $result['response'] ); @@ -774,15 +782,17 @@ public static function refund_charge( $charge_id, $amount = null, $data = array( ) ); + $headers = array_merge( + $headers, + array( + 'x-amz-pay-idempotency-key' => self::generate_uuid(), + ), + self::get_amazon_pay_platform_headers() + ); + $result = $client->createRefund( $data, - array_merge( - $headers, - array( - 'x-amz-pay-idempotency-key' => self::generate_uuid(), - ), - self::get_amazon_pay_platform_headers() - ) + $headers ); $response = json_decode( $result['response'] ); @@ -940,15 +950,17 @@ public static function create_charge( $charge_permission_id, $data ) { ) ); + $headers = array_merge( + $headers, + array( + 'x-amz-pay-idempotency-key' => self::generate_uuid(), + ), + self::get_amazon_pay_platform_headers() + ); + $result = $client->createCharge( $data, - array_merge( - $headers, - array( - 'x-amz-pay-idempotency-key' => self::generate_uuid(), - ), - self::get_amazon_pay_platform_headers() - ) + $headers ); $response = json_decode( $result['response'] ); @@ -973,7 +985,10 @@ public static function create_charge( $charge_permission_id, $data ) { public static function close_charge_permission( $charge_permission_id, $reason = 'Subscription Cancelled' ) { $client = self::get_client(); - $headers = self::get_extra_headers( __FUNCTION__ ); + $headers = array_merge( + self::get_extra_headers( __FUNCTION__ ), + self::get_amazon_pay_platform_headers() + ); wc_apa()->log( sprintf( 'Charge Permission ID %s.', $charge_permission_id ), array( 'headers' => $headers ) ); @@ -982,7 +997,7 @@ public static function close_charge_permission( $charge_permission_id, $reason = array( 'closureReason' => $reason, // TODO: Make dynamic. ), - array_merge( $headers, self::get_amazon_pay_platform_headers() ) + $headers ); $response = json_decode( $result['response'] ); From 353c7e46f2938e73711668663aca26a98969a837 Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Wed, 26 Apr 2023 12:01:19 +0300 Subject: [PATCH 04/16] Fixed logging of headers to aid QA --- .../class-wc-amazon-payments-advanced-api.php | 131 +++++++++++++++--- 1 file changed, 108 insertions(+), 23 deletions(-) diff --git a/includes/class-wc-amazon-payments-advanced-api.php b/includes/class-wc-amazon-payments-advanced-api.php index bc071e4a..62f07956 100644 --- a/includes/class-wc-amazon-payments-advanced-api.php +++ b/includes/class-wc-amazon-payments-advanced-api.php @@ -79,7 +79,16 @@ public static function validate_api_keys() { array( 'x-amz-pay-Idempotency-Key' => uniqid() ), self::get_amazon_pay_platform_headers() ); - $result = $client->createCheckoutSession( $payload, $headers ); + + wc_apa()->log( + 'Validating API keys.', + array( + 'payload' => $payload, + 'headers' => $headers, + ) + ); + + $result = $client->createCheckoutSession( $payload, $headers ); if ( ! isset( $result['status'] ) || 201 !== $result['status'] ) { throw new Exception( __( 'Error: API is not responding.', 'woocommerce-gateway-amazon-payments-advanced' ) ); } @@ -102,7 +111,17 @@ public static function validate_api_keys() { * @return array */ public static function trigger_alexa_notifications( $payload ) { - return self::get_client()->deliveryTrackers( $payload, self::get_amazon_pay_platform_headers() ); + $headers = self::get_amazon_pay_platform_headers(); + + wc_apa()->log( + 'Enabling Alexa notifications.', + array( + 'payload' => $payload, + 'headers' => $headers, + ) + ); + + return self::get_client()->deliveryTrackers( $payload, $headers ); } /** @@ -489,7 +508,17 @@ public static function get_create_checkout_classic_session_config( $payload ) { */ public static function get_checkout_session_data( $checkout_session_id ) { $client = self::get_client(); - $result = $client->getCheckoutSession( $checkout_session_id, self::get_amazon_pay_platform_headers() ); + + $headers = self::get_amazon_pay_platform_headers(); + + wc_apa()->log( + sprintf( 'Retrieving session data for session %s', $checkout_session_id ), + array( + 'headers' => $headers, + ) + ); + + $result = $client->getCheckoutSession( $checkout_session_id, $headers ); if ( ! isset( $result['status'] ) || 200 !== $result['status'] ) { return new WP_Error( $result['status'], __( 'Error while getting checkout session.', 'woocommerce-gateway-amazon-payments-advanced' ) ); } @@ -571,9 +600,18 @@ public static function update_checkout_session_data( $checkout_session_id, $data * @return object|WP_Error API Response, or WP_Error. */ public static function complete_checkout_session( $checkout_session_id, $data = array() ) { - $client = self::get_client(); - wc_apa()->log( sprintf( 'Checkout Session ID %s', $checkout_session_id ), $data ); - $result = $client->completeCheckoutSession( $checkout_session_id, $data, self::get_amazon_pay_platform_headers() ); + $client = self::get_client(); + $headers = self::get_amazon_pay_platform_headers(); + + wc_apa()->log( + sprintf( 'Completing Checkout Session ID %s', $checkout_session_id ), + array( + 'data' => $data, + 'headers' => $headers, + ) + ); + + $result = $client->completeCheckoutSession( $checkout_session_id, $data, $headers ); $response = json_decode( $result['response'] ); @@ -625,7 +663,17 @@ public static function get_languages_per_region() { */ public static function get_charge_permission( $charge_permission_id ) { $client = self::get_client(); - $result = $client->getChargePermission( $charge_permission_id, self::get_amazon_pay_platform_headers() ); + + $headers = self::get_amazon_pay_platform_headers(); + + wc_apa()->log( + sprintf( 'Retrieving Charge Permission ID %s', $charge_permission_id ), + array( + 'headers' => $headers, + ) + ); + + $result = $client->getChargePermission( $charge_permission_id, $headers ); $response = json_decode( $result['response'] ); @@ -644,7 +692,17 @@ public static function get_charge_permission( $charge_permission_id ) { */ public static function get_charge( $charge_id ) { $client = self::get_client(); - $result = $client->getCharge( $charge_id, self::get_amazon_pay_platform_headers() ); + + $headers = self::get_amazon_pay_platform_headers(); + + wc_apa()->log( + sprintf( 'Retrieving Charge ID %s', $charge_id ), + array( + 'headers' => $headers, + ) + ); + + $result = $client->getCharge( $charge_id, $headers ); $response = json_decode( $result['response'] ); @@ -663,7 +721,17 @@ public static function get_charge( $charge_id ) { */ public static function get_refund( $refund_id ) { $client = self::get_client(); - $result = $client->getRefund( $refund_id, self::get_amazon_pay_platform_headers() ); + + $headers = self::get_amazon_pay_platform_headers(); + + wc_apa()->log( + sprintf( 'Retrieving Refund ID %s', $refund_id ), + array( + 'headers' => $headers, + ) + ); + + $result = $client->getRefund( $refund_id, $headers ); $response = json_decode( $result['response'] ); @@ -712,7 +780,10 @@ public static function capture_charge( $charge_id, $data = array() ) { // TODO: Test with lower amount of captured than charge (multiple charges per capture). } - $headers = self::get_extra_headers( __FUNCTION__ ); + $headers = array_merge( + self::get_extra_headers( __FUNCTION__ ), + self::get_amazon_pay_platform_headers() + ); wc_apa()->log( sprintf( 'Charge ID %s.', $charge_id ), @@ -726,8 +797,7 @@ public static function capture_charge( $charge_id, $data = array() ) { $headers, array( 'x-amz-pay-idempotency-key' => self::generate_uuid(), - ), - self::get_amazon_pay_platform_headers() + ) ); $result = $client->captureCharge( @@ -772,7 +842,10 @@ public static function refund_charge( $charge_id, $amount = null, $data = array( $data['refundAmount']['amount'] = $amount; } - $headers = self::get_extra_headers( __FUNCTION__ ); + $headers = array_merge( + self::get_extra_headers( __FUNCTION__ ), + self::get_amazon_pay_platform_headers() + ); wc_apa()->log( sprintf( 'Charge ID %s.', $charge_id ), @@ -786,8 +859,7 @@ public static function refund_charge( $charge_id, $amount = null, $data = array( $headers, array( 'x-amz-pay-idempotency-key' => self::generate_uuid(), - ), - self::get_amazon_pay_platform_headers() + ) ); $result = $client->createRefund( @@ -816,14 +888,25 @@ public static function refund_charge( $charge_id, $amount = null, $data = array( */ public static function cancel_charge( $charge_id, $reason = 'Order Cancelled' ) { $client = self::get_client(); - wc_apa()->log( sprintf( 'Charge ID %s.', $charge_id ) ); + + $data = array( + 'cancellationReason' => $reason, // TODO: Make dynamic. + ); + + $headers = self::get_amazon_pay_platform_headers(); + + wc_apa()->log( + sprintf( 'Charge ID %s.', $charge_id ), + array( + 'data' => $data, + 'headers' => $headers, + ) + ); $result = $client->cancelCharge( $charge_id, - array( - 'cancellationReason' => $reason, // TODO: Make dynamic. - ), - self::get_amazon_pay_platform_headers() + $data, + $headers ); $response = json_decode( $result['response'] ); @@ -940,7 +1023,10 @@ public static function create_charge( $charge_permission_id, $data ) { $data['chargeAmount'] = (array) $charge_permission->limits->amountBalance; // phpcs:ignore WordPress.NamingConventions } - $headers = self::get_extra_headers( __FUNCTION__ ); + $headers = array_merge( + self::get_extra_headers( __FUNCTION__ ), + self::get_amazon_pay_platform_headers() + ); wc_apa()->log( sprintf( 'Charge Permission ID %s.', $charge_permission_id ), @@ -954,8 +1040,7 @@ public static function create_charge( $charge_permission_id, $data ) { $headers, array( 'x-amz-pay-idempotency-key' => self::generate_uuid(), - ), - self::get_amazon_pay_platform_headers() + ) ); $result = $client->createCharge( From 5134d4939a53dcc241e982b668be9394d39fb429 Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Fri, 7 Jul 2023 21:40:55 +0300 Subject: [PATCH 05/16] Update amazon pay SDK --- composer.json | 2 +- composer.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 923a5167..6fee169f 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ "yoast/phpunit-polyfills": "^1.0" }, "require": { - "amzn/amazon-pay-api-sdk-php": "2.5.2", + "amzn/amazon-pay-api-sdk-php": "2.6.2", "php": "7.*" } } diff --git a/composer.lock b/composer.lock index 0942c74c..51157383 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f8ac084417c133d5c7e6a5e2f177d2b8", + "content-hash": "2ca89bcc208c35341a0045d630cdf10c", "packages": [ { "name": "amzn/amazon-pay-api-sdk-php", - "version": "2.5.2", + "version": "2.6.2", "source": { "type": "git", "url": "https://github.com/amzn/amazon-pay-api-sdk-php.git", - "reference": "5b38287612427ecb0806d2cc626c92eb49173c6f" + "reference": "4583b7320e96e18fe32bef1830d7a968c0cebf49" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amzn/amazon-pay-api-sdk-php/zipball/5b38287612427ecb0806d2cc626c92eb49173c6f", - "reference": "5b38287612427ecb0806d2cc626c92eb49173c6f", + "url": "https://api.github.com/repos/amzn/amazon-pay-api-sdk-php/zipball/4583b7320e96e18fe32bef1830d7a968c0cebf49", + "reference": "4583b7320e96e18fe32bef1830d7a968c0cebf49", "shasum": "" }, "require": { @@ -57,9 +57,9 @@ ], "support": { "issues": "https://github.com/amzn/amazon-pay-api-sdk-php/issues", - "source": "https://github.com/amzn/amazon-pay-api-sdk-php/tree/2.5.2" + "source": "https://github.com/amzn/amazon-pay-api-sdk-php/tree/2.6.2" }, - "time": "2023-03-06T12:45:51+00:00" + "time": "2023-06-29T07:33:20+00:00" }, { "name": "paragonie/constant_time_encoding", From 22cb35a2a778fcbd2b68701992fb73e1d5f6c226 Mon Sep 17 00:00:00 2001 From: Alejandro Iglesias Date: Mon, 18 Sep 2023 11:44:06 +0200 Subject: [PATCH 06/16] 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 07/16] 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 08/16] 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 09/16] 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 10/16] 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 11/16] 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 01c4a7550b2ce442081b53a782b06526509b36db Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Mon, 25 Sep 2023 12:58:43 +0300 Subject: [PATCH 12/16] Extendable multicurrency compatibility --- ...mazon-payments-advanced-multi-currency.php | 23 +++++++++++++++++-- package-lock.json | 2 +- src/js/_renderAmazonButton.js | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/includes/compats/class-wc-amazon-payments-advanced-multi-currency.php b/includes/compats/class-wc-amazon-payments-advanced-multi-currency.php index 78d7b5a8..1e98df23 100644 --- a/includes/compats/class-wc-amazon-payments-advanced-multi-currency.php +++ b/includes/compats/class-wc-amazon-payments-advanced-multi-currency.php @@ -141,7 +141,12 @@ public static function is_currency_switched_on_checkout() { */ public static function compatible_plugin( $return_name = false ) { - foreach ( self::COMPATIBLE_PLUGINS as $definition_name => $name ) { + /** + * Filter out the compatible plugins to allow external sources to add compatibility. + * + * @since 2.5.1 + */ + foreach ( apply_filters( 'woocommerce_amazon_pa_ml_compat_plugins', self::COMPATIBLE_PLUGINS ) as $definition_name => $name ) { $match = false; if ( 0 === strpos( $definition_name, 'global' ) ) { $global_name = str_replace( 'global_', '', $definition_name ); @@ -155,7 +160,13 @@ public static function compatible_plugin( $return_name = false ) { $match = true; } } - if ( $match ) { + + /** + * Filter out whether the compatible plugin has been located in order to allow external plugins to apply their own logic. + * + * @since 2.5.1 + */ + if ( apply_filters( 'woocommerce_amazon_pa_matched_compat_plugin_' . $definition_name, $match ) ) { return ( $return_name ) ? $name : $definition_name; } } @@ -249,6 +260,14 @@ protected static function init_compatible_plugin_instance( $init = true ) { require_once 'class-wc-amazon-payments-advanced-multi-currency-wccw.php'; $found_plugin_instance = $init ? new WC_Amazon_Payments_Advanced_Multi_Currency_WCCW() : WC_Amazon_Payments_Advanced_Multi_Currency_WCCW::class; break; + default: + /** + * Allow external plugins to return their own compatible instance. + * + * @since 2.5.1 + */ + $found_plugin_instance = apply_filters( 'woocommerce_amazon_pa_compat_plugin_instance_' . $compatible_plugin, $found_plugin_instance, $init ); + break; } if ( $init ) { self::$compatible_instance = $found_plugin_instance; diff --git a/package-lock.json b/package-lock.json index 6fa1abce..29c1de76 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "woocommerce-gateway-amazon-payments-advanced", - "version": "2.4.1", + "version": "2.5.0", "hasInstallScript": true, "license": "GPL-2.0", "dependencies": { diff --git a/src/js/_renderAmazonButton.js b/src/js/_renderAmazonButton.js index 3cddadf0..5540ed08 100644 --- a/src/js/_renderAmazonButton.js +++ b/src/js/_renderAmazonButton.js @@ -18,7 +18,7 @@ const getButtonSettings = ( buttonSettingsFlag, checkoutConfig, estimatedOrderAm // customize the buyer experience placement: amazon_payments_advanced.placement, buttonColor: amazon_payments_advanced.button_color, - estimatedOrderAmount: estimatedOrderAmount, + // estimatedOrderAmount: estimatedOrderAmount, checkoutLanguage: amazon_payments_advanced.button_language !== '' ? amazon_payments_advanced.button_language.replace( '-', '_' ) From 6452d6e2b79c8f49811e7c84f9fe0e7637bcae33 Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Mon, 25 Sep 2023 15:29:50 +0300 Subject: [PATCH 13/16] revert accidental code push --- src/js/_renderAmazonButton.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/_renderAmazonButton.js b/src/js/_renderAmazonButton.js index 5540ed08..3cddadf0 100644 --- a/src/js/_renderAmazonButton.js +++ b/src/js/_renderAmazonButton.js @@ -18,7 +18,7 @@ const getButtonSettings = ( buttonSettingsFlag, checkoutConfig, estimatedOrderAm // customize the buyer experience placement: amazon_payments_advanced.placement, buttonColor: amazon_payments_advanced.button_color, - // estimatedOrderAmount: estimatedOrderAmount, + estimatedOrderAmount: estimatedOrderAmount, checkoutLanguage: amazon_payments_advanced.button_language !== '' ? amazon_payments_advanced.button_language.replace( '-', '_' ) From 2a60c426634bfbda7edf5acd8587f1e56cc23ed1 Mon Sep 17 00:00:00 2001 From: Alejandro Iglesias Date: Wed, 27 Sep 2023 16:50:38 +0200 Subject: [PATCH 14/16] 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, From c2557a40df9007a8239f8b4fd2a4e4f8932779d7 Mon Sep 17 00:00:00 2001 From: Alejandro Iglesias Date: Mon, 9 Oct 2023 15:49:37 +0200 Subject: [PATCH 15/16] bump versions to 2.5.1 --- changelog.txt | 6 ++++++ package-lock.json | 4 ++-- package.json | 2 +- readme.txt | 8 +++++++- woocommerce-gateway-amazon-payments-advanced.php | 4 ++-- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/changelog.txt b/changelog.txt index 1070dd13..2dc659ea 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,11 @@ *** Amazon Pay Changelog *** += 2.5.1 - 2023-10-09 = + +* Add - Improve multi-currency compatibility support. +* Fix - Issue with estimatedOrderAmount and multi-currency. +* Update - Amazon Pay SDK. + = 2.5.0 - 2023-07-20 = * Add - Plugin review Prompt. diff --git a/package-lock.json b/package-lock.json index 29c1de76..07aa06c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "woocommerce-gateway-amazon-payments-advanced", - "version": "2.5.0", + "version": "2.5.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "woocommerce-gateway-amazon-payments-advanced", - "version": "2.5.0", + "version": "2.5.1", "hasInstallScript": true, "license": "GPL-2.0", "dependencies": { diff --git a/package.json b/package.json index 44ee71e6..68a014d4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "woocommerce-gateway-amazon-payments-advanced", "description": "Amazon Pay Gateway for WooCommerce", - "version": "2.5.0", + "version": "2.5.1", "title": "WooCommerce Gateway Amazon Pay", "repository": { "type": "git", diff --git a/readme.txt b/readme.txt index 97e75b65..0e7d38b2 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: woocommerce, automattic, woothemes, akeda, jeffstieler, mikejolley Tags: woocommerce, amazon, checkout, payments, e-commerce, ecommerce Requires at least: 5.5 Tested up to: 6.2 -Stable tag: 2.5.0 +Stable tag: 2.5.1 License: GPLv3 License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -80,6 +80,12 @@ Automatic updates should work like a charm; as always though, ensure you backup == Changelog == += 2.5.1 - 2023-10-09 = + +* Add - Improve multi-currency compatibility support. +* Fix - Issue with estimatedOrderAmount and multi-currency. +* Update - Amazon Pay SDK. + = 2.5.0 - 2023-07-20 = * Add - Plugin review Prompt. diff --git a/woocommerce-gateway-amazon-payments-advanced.php b/woocommerce-gateway-amazon-payments-advanced.php index bcb7403c..31e9b63f 100644 --- a/woocommerce-gateway-amazon-payments-advanced.php +++ b/woocommerce-gateway-amazon-payments-advanced.php @@ -3,7 +3,7 @@ * Plugin Name: WooCommerce Amazon Pay * Plugin URI: https://woocommerce.com/products/pay-with-amazon/ * Description: Amazon Pay is embedded directly into your existing web site, and all the buyer interactions with Amazon Pay and Login with Amazon take place in embedded widgets so that the buyer never leaves your site. Buyers can log in using their Amazon account, select a shipping address and payment method, and then confirm their order. Requires an Amazon Pay seller account and supports USA, UK, Germany, France, Italy, Spain, Luxembourg, the Netherlands, Sweden, Portugal, Hungary, Denmark, and Japan. - * Version: 2.5.0 + * Version: 2.5.1 * Author: WooCommerce * Author URI: https://woocommerce.com * Text Domain: woocommerce-gateway-amazon-payments-advanced @@ -19,7 +19,7 @@ * @package WC_Gateway_Amazon_Pay */ -define( 'WC_AMAZON_PAY_VERSION', '2.5.0' ); // WRCS: DEFINED_VERSION. +define( 'WC_AMAZON_PAY_VERSION', '2.5.1' ); // WRCS: DEFINED_VERSION. define( 'WC_AMAZON_PAY_VERSION_CV1', '1.13.1' ); // Declare HPOS compatibility. From 6a85006387158ee2912f6f037d1a4be164ddf454 Mon Sep 17 00:00:00 2001 From: Alejandro Iglesias Date: Tue, 10 Oct 2023 18:43:00 +0200 Subject: [PATCH 16/16] Revert "Merge branch 'fix/issue-270-estimated-order-amount-multicurrency' into release/2.6.0" This reverts commit f23a8ef2bbed1e8acf9e6eece45271f893b68a57, reversing changes made to 20c0f21ad00553745c1ea4e5138339e1f1eaa101. --- ...-amazon-payments-advanced-api-abstract.php | 8 +--- ...ss-wc-gateway-amazon-payments-advanced.php | 8 +--- ...ayments-advanced-block-compat-abstract.php | 27 ----------- ...payments-advanced-block-compat-classic.php | 13 +++--- ...payments-advanced-block-compat-express.php | 45 +++++++++---------- src/js/_renderAmazonButton.js | 5 +-- src/js/non-block/amazon-wc-checkout.js | 4 +- .../express/_payment-methods-express.js | 15 ------- ...st-wc-gateway-amazon-payments-advanced.php | 39 +++------------- ...wc-mocker-amazon-payments-advanced-api.php | 22 --------- ...ocker-gateway-amazon-payments-advanced.php | 14 +----- 11 files changed, 41 insertions(+), 159 deletions(-) diff --git a/includes/class-wc-amazon-payments-advanced-api-abstract.php b/includes/class-wc-amazon-payments-advanced-api-abstract.php index c8af4d3d..ef708f13 100644 --- a/includes/class-wc-amazon-payments-advanced-api-abstract.php +++ b/includes/class-wc-amazon-payments-advanced-api-abstract.php @@ -213,16 +213,12 @@ 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( $currency = false ) { + public static function is_region_supports_shop_currency() { $region = self::get_region(); // Take into consideration external multi-currency plugins when not supported multicurrency region. - if ( ! $currency ) { - $currency = apply_filters( 'woocommerce_amazon_pa_active_currency', get_option( 'woocommerce_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 1148827c..bf1d69e7 100644 --- a/includes/class-wc-gateway-amazon-payments-advanced.php +++ b/includes/class-wc-gateway-amazon-payments-advanced.php @@ -3030,16 +3030,10 @@ 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' => $active_currency, + 'currencyCode' => get_woocommerce_currency(), ) ); } 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 24deb69a..4a61c3de 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,31 +118,4 @@ 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 f8134110..6e3d1dd4 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,13 +44,12 @@ 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(), - 'regionBaseCurrencies' => $this->region_base_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(), ); } 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 627381a0..dd561731 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,29 +42,28 @@ 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 - ), - 'regionBaseCurrencies' => $this->region_base_currencies(), - ); + $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 + ), + ); } diff --git a/src/js/_renderAmazonButton.js b/src/js/_renderAmazonButton.js index 44f09937..3cddadf0 100644 --- a/src/js/_renderAmazonButton.js +++ b/src/js/_renderAmazonButton.js @@ -18,16 +18,13 @@ 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 54ff6bb4..f60fdca8 100644 --- a/src/js/non-block/amazon-wc-checkout.js +++ b/src/js/non-block/amazon-wc-checkout.js @@ -280,9 +280,7 @@ } } else { obj.createCheckoutSessionConfig = amazon_payments_advanced.create_checkout_session_config; - if ( amazon_payments_advanced.estimated_order_amount ) { - obj.estimatedOrderAmount = amazon_payments_advanced.estimated_order_amount; - } + obj.estimatedOrderAmount = amazon_payments_advanced.estimated_order_amount; } return obj; } diff --git a/src/js/payments-methods/express/_payment-methods-express.js b/src/js/payments-methods/express/_payment-methods-express.js index 170c7a78..0acefd90 100644 --- a/src/js/payments-methods/express/_payment-methods-express.js +++ b/src/js/payments-methods/express/_payment-methods-express.js @@ -7,7 +7,6 @@ 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. @@ -24,16 +23,6 @@ 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 @@ -43,10 +32,6 @@ 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, 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 033f061f..1110f7ac 100644 --- a/tests/phpunit/includes/test-wc-gateway-amazon-payments-advanced.php +++ b/tests/phpunit/includes/test-wc-gateway-amazon-payments-advanced.php @@ -113,44 +113,17 @@ 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' => $mock_gateway::get_estimated_order_amount(), + 'amazonEstimatedOrderAmount' => wp_json_encode( + array( + 'amount' => $order_total, + 'currencyCode' => get_woocommerce_currency(), + ) + ), ), $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 e8f15012..673d1741 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,26 +51,4 @@ public static function get_create_checkout_classic_session_config( array $payloa 'signature' => $signature, ); } - - 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(); - } - - 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 75b66f9b..608a7bf2 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,21 +77,11 @@ protected function get_create_checkout_classic_session_config( $payload ) : arra * * @return 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( $active_currency ) ) { - return ''; - } - + protected static function get_estimated_order_amount() : string { return wp_json_encode( array( 'amount' => self::$order_total, - 'currencyCode' => $active_currency, + 'currencyCode' => get_woocommerce_currency(), ) ); }