Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amazon Pay ECE: add payment method class #4015

Merged
merged 6 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,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.

= 9.2.0 - 2025-02-13 =
* Fix - Fix missing product_id parameter for the express checkout add-to-cart operation.
Expand Down
2 changes: 2 additions & 0 deletions client/blocks/upe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
registerExpressPaymentMethod,
} from '@woocommerce/blocks-registry';
import {
PAYMENT_METHOD_AMAZON_PAY,
PAYMENT_METHOD_GIROPAY,
PAYMENT_METHOD_LINK,
} from '../../stripe-utils/constants';
Expand Down Expand Up @@ -37,6 +38,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.
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 ] );
Expand Down
7 changes: 6 additions & 1 deletion includes/admin/class-wc-rest-stripe-settings-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* Amazon Pay Payment Method class extending UPE base class
*/
class WC_Stripe_UPE_Payment_Method_Amazon_Pay extends WC_Stripe_UPE_Payment_Method {

const STRIPE_ID = WC_Stripe_Payment_Methods::AMAZON_PAY;

/**
* Constructor for Amazon Pay payment method
*/
public function __construct() {
parent::__construct();
$this->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;
}
}
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,6 @@ 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.

[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 );
}

/**
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' ] );
Expand Down Expand Up @@ -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();
}
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
}

/**
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions woocommerce-gateway-stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Loading