diff --git a/changelog.txt b/changelog.txt index b3a6c454a0..958ae53bfb 100644 --- a/changelog.txt +++ b/changelog.txt @@ -40,6 +40,7 @@ * Fix - Fix issue where Legacy Checkout settings get overwritten with old value. * Add - Add WooCommerce Pre-Orders support to Bacs. * Tweak - Fix background in express checkout settings. +* Add - Add Amazon Pay payment method class. * Fix - Prevent potential duplicate renewal charges by ensuring subscription integration hooks are only attached once per Gateway ID * Update - Update Amazon Pay icon to use image from WooCommerce Design Library. diff --git a/client/blocks/upe/index.js b/client/blocks/upe/index.js index d8c66df707..d89070f486 100644 --- a/client/blocks/upe/index.js +++ b/client/blocks/upe/index.js @@ -3,6 +3,7 @@ import { registerExpressPaymentMethod, } from '@woocommerce/blocks-registry'; import { + PAYMENT_METHOD_AMAZON_PAY, PAYMENT_METHOD_CARD, PAYMENT_METHOD_GIROPAY, PAYMENT_METHOD_LINK, @@ -38,6 +39,7 @@ const paymentMethodsConfig = getBlocksConfiguration()?.paymentMethodsConfig ?? {}; const methodsToFilter = [ + PAYMENT_METHOD_AMAZON_PAY, PAYMENT_METHOD_LINK, PAYMENT_METHOD_GIROPAY, // Skip giropay as it was deprecated by Jun, 30th 2024. ]; diff --git a/client/settings/general-settings-section/payment-methods-unavailable-list.js b/client/settings/general-settings-section/payment-methods-unavailable-list.js index b9d9ce8545..0a02d05763 100644 --- a/client/settings/general-settings-section/payment-methods-unavailable-list.js +++ b/client/settings/general-settings-section/payment-methods-unavailable-list.js @@ -3,7 +3,10 @@ import React from 'react'; import { useGetAvailablePaymentMethodIds } from 'wcstripe/data'; import { useGetCapabilities } from 'wcstripe/data/account'; import methodsConfiguration from 'wcstripe/payment-methods-map'; -import { PAYMENT_METHOD_LINK } from 'wcstripe/stripe-utils/constants'; +import { + PAYMENT_METHOD_AMAZON_PAY, + PAYMENT_METHOD_LINK, +} from 'wcstripe/stripe-utils/constants'; const PaymentMethodsUnavailableList = () => { const countIconsToDisplay = 3; @@ -14,7 +17,12 @@ const PaymentMethodsUnavailableList = () => { ( methodId ) => ! capabilities.hasOwnProperty( `${ methodId }_payments` ) ) - .filter( ( id ) => id !== PAYMENT_METHOD_LINK ); + .filter( + ( id ) => + ! [ PAYMENT_METHOD_LINK, PAYMENT_METHOD_AMAZON_PAY ].includes( + id + ) + ); const unavailablePaymentMethods = unavailablePaymentMethodIds .filter( ( methodId, idx ) => idx < countIconsToDisplay ) .map( ( methodId ) => methodsConfiguration[ methodId ] ); diff --git a/includes/admin/class-wc-rest-stripe-settings-controller.php b/includes/admin/class-wc-rest-stripe-settings-controller.php index 99f3251fbd..102df6d55e 100644 --- a/includes/admin/class-wc-rest-stripe-settings-controller.php +++ b/includes/admin/class-wc-rest-stripe-settings-controller.php @@ -257,7 +257,12 @@ public function get_settings() { /* Settings > Payments accepted on checkout */ 'enabled_payment_method_ids' => array_values( array_intersect( $enabled_payment_method_ids, $available_payment_method_ids ) ), // only fetch enabled payment methods that are available. 'available_payment_method_ids' => $available_payment_method_ids, - 'ordered_payment_method_ids' => array_values( array_diff( $ordered_payment_method_ids, [ WC_Stripe_Payment_Methods::LINK ] ) ), // exclude Link from this list as it is a express methods. + 'ordered_payment_method_ids' => array_values( + array_diff( + $ordered_payment_method_ids, + [ WC_Stripe_Payment_Methods::AMAZON_PAY, WC_Stripe_Payment_Methods::LINK ] + ) + ), // exclude Amazon Pay and Link from this list as they are express methods only. 'individual_payment_method_settings' => $is_upe_enabled ? WC_Stripe_Helper::get_upe_individual_payment_method_settings( $this->gateway ) : WC_Stripe_Helper::get_legacy_individual_payment_method_settings(), /* Settings > Express checkouts */ diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php index f4f783cb27..b915daa702 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php @@ -24,6 +24,7 @@ class WC_Stripe_UPE_Payment_Gateway extends WC_Gateway_Stripe { WC_Stripe_UPE_Payment_Method_CC::class, WC_Stripe_UPE_Payment_Method_ACH::class, WC_Stripe_UPE_Payment_Method_Alipay::class, + WC_Stripe_UPE_Payment_Method_Amazon_Pay::class, WC_Stripe_UPE_Payment_Method_Giropay::class, WC_Stripe_UPE_Payment_Method_Klarna::class, WC_Stripe_UPE_Payment_Method_Affirm::class, diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method-amazon-pay.php b/includes/payment-methods/class-wc-stripe-upe-payment-method-amazon-pay.php new file mode 100644 index 0000000000..9b5cb91d77 --- /dev/null +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method-amazon-pay.php @@ -0,0 +1,38 @@ +stripe_id = self::STRIPE_ID; + $this->title = __( 'Amazon Pay', 'woocommerce-gateway-stripe' ); + $this->supported_currencies = [ WC_Stripe_Currency_Code::UNITED_STATES_DOLLAR ]; + $this->is_reusable = true; + $this->label = __( 'Amazon Pay', 'woocommerce-gateway-stripe' ); + $this->description = __( + 'Amazon Pay is a payment method that allows customers to pay with their Amazon account.', + 'woocommerce-gateway-stripe' + ); + } + + /** + * Returns whether the payment method requires automatic capture. + * + * @return bool + */ + public function requires_automatic_capture() { + // Amazon Pay supports manual capture. + return false; + } +} diff --git a/readme.txt b/readme.txt index 8d7b6846a7..1b5c888057 100644 --- a/readme.txt +++ b/readme.txt @@ -150,6 +150,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o * Fix - Fix issue where Legacy Checkout settings get overwritten with old value. * Add - Add WooCommerce Pre-Orders support to Bacs. * Tweak - Fix background in express checkout settings. +* Add - Add Amazon Pay payment method class. * Fix - Prevent potential duplicate renewal charges by ensuring subscription integration hooks are only attached once per Gateway ID * Update - Update Amazon Pay icon to use image from WooCommerce Design Library. diff --git a/tests/phpunit/admin/test-class-wc-rest-stripe-settings-controller-gb.php b/tests/phpunit/admin/test-class-wc-rest-stripe-settings-controller-gb.php index 6f4c4fe44b..35e07cdb7c 100644 --- a/tests/phpunit/admin/test-class-wc-rest-stripe-settings-controller-gb.php +++ b/tests/phpunit/admin/test-class-wc-rest-stripe-settings-controller-gb.php @@ -90,6 +90,7 @@ public function test_get_settings_returns_available_payment_method_ids_for_gb() $expected_method_ids = [ WC_Stripe_Payment_Methods::CARD, WC_Stripe_Payment_Methods::ALIPAY, + WC_Stripe_Payment_Methods::AMAZON_PAY, WC_Stripe_Payment_Methods::KLARNA, WC_Stripe_Payment_Methods::AFTERPAY_CLEARPAY, WC_Stripe_Payment_Methods::EPS, @@ -117,6 +118,7 @@ public function test_get_settings_returns_available_payment_method_ids_for_gb() } public function test_get_settings_returns_ordered_payment_method_ids_for_gb() { + // Link and Amazon Pay are excluded as they are express methods only. $expected_ordered_method_ids = [ WC_Stripe_Payment_Methods::CARD, WC_Stripe_Payment_Methods::ALIPAY, diff --git a/tests/phpunit/admin/test-class-wc-rest-stripe-settings-controller.php b/tests/phpunit/admin/test-class-wc-rest-stripe-settings-controller.php index 1b6d4fdaf5..8ec55991d1 100644 --- a/tests/phpunit/admin/test-class-wc-rest-stripe-settings-controller.php +++ b/tests/phpunit/admin/test-class-wc-rest-stripe-settings-controller.php @@ -43,6 +43,9 @@ public static function set_up_before_class() { // Enable ACH update_option( WC_Stripe_Feature_Flags::LPM_ACH_FEATURE_FLAG_NAME, 'yes' ); + // Enable Amazon Pay + update_option( WC_Stripe_Feature_Flags::AMAZON_PAY_FEATURE_FLAG_NAME, 'yes' ); + // All tests assume UPE is enabled. update_option( '_wcstripe_feature_upe', 'yes' ); $upe_helper->enable_upe(); @@ -74,6 +77,7 @@ public function tear_down() { delete_option( WC_Stripe_Feature_Flags::LPM_BACS_FEATURE_FLAG_NAME ); delete_option( WC_Stripe_Feature_Flags::LPM_ACH_FEATURE_FLAG_NAME ); + delete_option( WC_Stripe_Feature_Flags::AMAZON_PAY_FEATURE_FLAG_NAME ); } /** @@ -238,6 +242,7 @@ public function test_get_settings_returns_available_payment_method_ids() { WC_Stripe_Payment_Methods::CARD, WC_Stripe_Payment_Methods::ACH, WC_Stripe_Payment_Methods::ALIPAY, + WC_Stripe_Payment_Methods::AMAZON_PAY, WC_Stripe_Payment_Methods::KLARNA, WC_Stripe_Payment_Methods::AFFIRM, WC_Stripe_Payment_Methods::AFTERPAY_CLEARPAY, @@ -282,6 +287,7 @@ public function test_get_settings_returns_ordered_payment_method_ids() { WC_Stripe::get_instance()->account->method( 'get_account_country' )->willReturn( 'US' ); + // Link and Amazon Pay are excluded as they are express methods only. $expected_method_ids = [ WC_Stripe_Payment_Methods::CARD, WC_Stripe_Payment_Methods::ACH, @@ -297,7 +303,6 @@ public function test_get_settings_returns_ordered_payment_method_ids() { WC_Stripe_Payment_Methods::SEPA_DEBIT, WC_Stripe_Payment_Methods::P24, WC_Stripe_Payment_Methods::MULTIBANCO, - // 'link', // Link is excluded as it is a express method. WC_Stripe_Payment_Methods::WECHAT_PAY, WC_Stripe_Payment_Methods::CASHAPP_PAY, ]; diff --git a/tests/phpunit/payment-methods/test-class-wc-stripe-upe-payment-gateway-gb.php b/tests/phpunit/payment-methods/test-class-wc-stripe-upe-payment-gateway-gb.php index 6df1d24906..7b356afe37 100644 --- a/tests/phpunit/payment-methods/test-class-wc-stripe-upe-payment-gateway-gb.php +++ b/tests/phpunit/payment-methods/test-class-wc-stripe-upe-payment-gateway-gb.php @@ -11,6 +11,7 @@ public function set_up() { update_option( WC_Stripe_Feature_Flags::LPM_ACH_FEATURE_FLAG_NAME, 'yes' ); update_option( WC_Stripe_Feature_Flags::LPM_BACS_FEATURE_FLAG_NAME, 'yes' ); + update_option( WC_Stripe_Feature_Flags::AMAZON_PAY_FEATURE_FLAG_NAME, 'yes' ); // Since it will be used by the mock, we need to set this beforehand. $this->set_stripe_account_data( [ 'country' => 'GB' ] ); @@ -47,6 +48,7 @@ public function set_up() { public function tear_down() { delete_option( WC_Stripe_Feature_Flags::LPM_ACH_FEATURE_FLAG_NAME ); delete_option( WC_Stripe_Feature_Flags::LPM_BACS_FEATURE_FLAG_NAME ); + delete_option( WC_Stripe_Feature_Flags::AMAZON_PAY_FEATURE_FLAG_NAME ); parent::tear_down(); } @@ -68,6 +70,7 @@ public function get_upe_available_payment_methods_provider() { [ WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID, WC_Stripe_UPE_Payment_Method_Alipay::STRIPE_ID, + WC_Stripe_UPE_Payment_Method_Amazon_Pay::STRIPE_ID, WC_Stripe_UPE_Payment_Method_Klarna::STRIPE_ID, WC_Stripe_UPE_Payment_Method_Afterpay_Clearpay::STRIPE_ID, WC_Stripe_UPE_Payment_Method_Eps::STRIPE_ID, diff --git a/tests/phpunit/payment-methods/test-class-wc-stripe-upe-payment-gateway.php b/tests/phpunit/payment-methods/test-class-wc-stripe-upe-payment-gateway.php index 67adbe3148..d2e6c99234 100644 --- a/tests/phpunit/payment-methods/test-class-wc-stripe-upe-payment-gateway.php +++ b/tests/phpunit/payment-methods/test-class-wc-stripe-upe-payment-gateway.php @@ -120,7 +120,7 @@ public function set_up() { update_option( WC_Stripe_Feature_Flags::LPM_ACH_FEATURE_FLAG_NAME, 'yes' ); update_option( WC_Stripe_Feature_Flags::LPM_ACSS_FEATURE_FLAG_NAME, 'yes' ); update_option( WC_Stripe_Feature_Flags::LPM_BACS_FEATURE_FLAG_NAME, 'yes' ); - + update_option( WC_Stripe_Feature_Flags::AMAZON_PAY_FEATURE_FLAG_NAME, 'yes' ); $stripe_settings = WC_Stripe_Helper::get_stripe_settings(); $stripe_settings['sepa_tokens_for_other_methods'] = 'yes'; WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings ); @@ -190,6 +190,7 @@ public function tear_down() { delete_option( WC_Stripe_Feature_Flags::LPM_ACH_FEATURE_FLAG_NAME ); delete_option( WC_Stripe_Feature_Flags::LPM_ACSS_FEATURE_FLAG_NAME ); delete_option( WC_Stripe_Feature_Flags::LPM_BACS_FEATURE_FLAG_NAME ); + delete_option( WC_Stripe_Feature_Flags::AMAZON_PAY_FEATURE_FLAG_NAME ); } /** @@ -271,6 +272,7 @@ public function get_upe_available_payment_methods_provider() { WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID, WC_Stripe_UPE_Payment_Method_ACH::STRIPE_ID, WC_Stripe_UPE_Payment_Method_Alipay::STRIPE_ID, + WC_Stripe_UPE_Payment_Method_Amazon_Pay::STRIPE_ID, WC_Stripe_UPE_Payment_Method_Klarna::STRIPE_ID, WC_Stripe_UPE_Payment_Method_Affirm::STRIPE_ID, WC_Stripe_UPE_Payment_Method_Afterpay_Clearpay::STRIPE_ID, @@ -293,6 +295,7 @@ public function get_upe_available_payment_methods_provider() { [ WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID, WC_Stripe_UPE_Payment_Method_Alipay::STRIPE_ID, + WC_Stripe_UPE_Payment_Method_Amazon_Pay::STRIPE_ID, WC_Stripe_UPE_Payment_Method_Eps::STRIPE_ID, WC_Stripe_UPE_Payment_Method_Bancontact::STRIPE_ID, WC_Stripe_UPE_Payment_Method_Boleto::STRIPE_ID, diff --git a/tests/phpunit/payment-methods/test-class-wc-stripe-upe-payment-method.php b/tests/phpunit/payment-methods/test-class-wc-stripe-upe-payment-method.php index d1831a213b..460da65a1e 100644 --- a/tests/phpunit/payment-methods/test-class-wc-stripe-upe-payment-method.php +++ b/tests/phpunit/payment-methods/test-class-wc-stripe-upe-payment-method.php @@ -126,6 +126,7 @@ class WC_Stripe_UPE_Payment_Method_Test extends WP_UnitTestCase { */ const MOCK_ACTIVE_CAPABILITIES_RESPONSE = [ 'alipay_payments' => 'active', + 'amazon_pay_payments' => 'active', 'bancontact_payments' => 'active', 'card_payments' => 'active', 'eps_payments' => 'active', @@ -640,7 +641,15 @@ public function test_payment_methods_are_reusable_if_cart_contains_subscription( foreach ( $this->mock_payment_methods as $payment_method_id => $payment_method ) { $store_currency = 'EUR'; - if ( in_array( $payment_method_id, [ WC_Stripe_UPE_Payment_Method_Link::STRIPE_ID, WC_Stripe_UPE_Payment_Method_ACH::STRIPE_ID ] ) ) { + if ( in_array( + $payment_method_id, + [ + WC_Stripe_UPE_Payment_Method_Link::STRIPE_ID, + WC_Stripe_UPE_Payment_Method_ACH::STRIPE_ID, + WC_Stripe_UPE_Payment_Method_Amazon_Pay::STRIPE_ID, + ], + true + ) ) { $store_currency = WC_Stripe_Currency_Code::UNITED_STATES_DOLLAR; } elseif ( WC_Stripe_UPE_Payment_Method_Bacs_Debit::STRIPE_ID === $payment_method_id ) { $store_currency = WC_Stripe_Currency_Code::POUND_STERLING; diff --git a/woocommerce-gateway-stripe.php b/woocommerce-gateway-stripe.php index 9cb2cb40d1..f5732f56e8 100644 --- a/woocommerce-gateway-stripe.php +++ b/woocommerce-gateway-stripe.php @@ -246,6 +246,7 @@ public function init() { require_once __DIR__ . '/includes/payment-methods/class-wc-stripe-upe-payment-method-cash-app-pay.php'; require_once __DIR__ . '/includes/payment-methods/class-wc-stripe-upe-payment-method-wechat-pay.php'; require_once __DIR__ . '/includes/payment-methods/class-wc-stripe-upe-payment-method-acss.php'; + require_once __DIR__ . '/includes/payment-methods/class-wc-stripe-upe-payment-method-amazon-pay.php'; require_once __DIR__ . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'; require_once __DIR__ . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'; require_once __DIR__ . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php';