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/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", 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, + ); + } } diff --git a/includes/class-wc-amazon-payments-advanced-api.php b/includes/class-wc-amazon-payments-advanced-api.php index cb5eddd8..62f07956 100644 --- a/includes/class-wc-amazon-payments-advanced-api.php +++ b/includes/class-wc-amazon-payments-advanced-api.php @@ -75,8 +75,20 @@ 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, $headers ); + $headers = array_merge( + array( 'x-amz-pay-Idempotency-Key' => uniqid() ), + self::get_amazon_pay_platform_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' ) ); } @@ -99,7 +111,17 @@ public static function validate_api_keys() { * @return array */ public static function trigger_alexa_notifications( $payload ) { - return self::get_client()->deliveryTrackers( $payload ); + $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 ); } /** @@ -486,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 ); + + $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' ) ); } @@ -533,7 +565,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 ), @@ -565,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 ); + $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'] ); @@ -619,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 ); + + $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'] ); @@ -638,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 ); + + $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'] ); @@ -657,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 ); + + $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'] ); @@ -706,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 ), @@ -716,15 +793,17 @@ public static function capture_charge( $charge_id, $data = array() ) { ) ); + $headers = array_merge( + $headers, + array( + 'x-amz-pay-idempotency-key' => self::generate_uuid(), + ) + ); + $result = $client->captureCharge( $charge_id, $data, - array_merge( - $headers, - array( - 'x-amz-pay-idempotency-key' => self::generate_uuid(), - ) - ) + $headers ); $response = json_decode( $result['response'] ); @@ -763,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 ), @@ -773,14 +855,16 @@ public static function refund_charge( $charge_id, $amount = null, $data = array( ) ); + $headers = array_merge( + $headers, + array( + 'x-amz-pay-idempotency-key' => self::generate_uuid(), + ) + ); + $result = $client->createRefund( $data, - array_merge( - $headers, - array( - 'x-amz-pay-idempotency-key' => self::generate_uuid(), - ) - ) + $headers ); $response = json_decode( $result['response'] ); @@ -804,15 +888,27 @@ 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 ) ); - $result = $client->cancelCharge( - $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( - 'cancellationReason' => $reason, // TODO: Make dynamic. + 'data' => $data, + 'headers' => $headers, ) ); + $result = $client->cancelCharge( + $charge_id, + $data, + $headers + ); + $response = json_decode( $result['response'] ); if ( ! isset( $result['status'] ) || ! in_array( $result['status'], array( 200, 201 ), true ) ) { @@ -927,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 ), @@ -937,14 +1036,16 @@ public static function create_charge( $charge_permission_id, $data ) { ) ); + $headers = array_merge( + $headers, + array( + 'x-amz-pay-idempotency-key' => self::generate_uuid(), + ) + ); + $result = $client->createCharge( $data, - array_merge( - $headers, - array( - 'x-amz-pay-idempotency-key' => self::generate_uuid(), - ) - ) + $headers ); $response = json_decode( $result['response'] ); @@ -969,7 +1070,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 ) ); 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..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.4.1", + "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.