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: update selected payment method #4082

Merged
merged 6 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -9,6 +9,7 @@
* Tweak - Updates the Single Payment Element setting copy. Now it is labeled "Smart Checkout".
* Update - Enable/disable Amazon Pay by adding/removing it from the enabled payment methods list.
* Add - Add ACSS payment tokenization.
* Update - Update payment method type for Amazon Pay orders.

= 9.3.1 - 2025-03-14 =
* Fix - Temporarily disables the subscriptions detached notice feature due to long loading times on stores with many subscriptions.
Expand Down
12 changes: 11 additions & 1 deletion includes/class-wc-stripe-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,17 @@ public static function get_european_economic_area_countries() {
* @return bool Whether the payment method allows manual capture.
*/
public static function payment_method_allows_manual_capture( string $payment_method_id ) {
return in_array( $payment_method_id, [ 'stripe', 'stripe_affirm', 'stripe_klarna', 'stripe_afterpay_clearpay' ], true );
return in_array(
$payment_method_id,
[
'stripe',
'stripe_affirm',
'stripe_klarna',
'stripe_afterpay_clearpay',
'stripe_amazon_pay',
],
true
);
}

/**
Expand Down
9 changes: 4 additions & 5 deletions includes/constants/class-wc-stripe-payment-methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class WC_Stripe_Payment_Methods {
const WECHAT_PAY = 'wechat_pay';

// Payment method labels
const AMAZON_PAY_LABEL = 'Amazon Pay';
const BACS_DEBIT_LABEL = 'Bacs Direct Debit';
const GOOGLE_PAY_LABEL = 'Google Pay';
const APPLE_PAY_LABEL = 'Apple Pay';
Expand Down Expand Up @@ -71,11 +70,11 @@ class WC_Stripe_Payment_Methods {
];

/**
* List of express payment methods labels (excluding Link).
* List of express payment methods labels. Amazon Pay and Link are not included,
* as they have their own payment method classes.
*/
const EXPRESS_METHODS_LABELS = [
self::AMAZON_PAY => self::AMAZON_PAY_LABEL,
'google_pay' => self::GOOGLE_PAY_LABEL,
'apple_pay' => self::APPLE_PAY_LABEL,
'google_pay' => self::GOOGLE_PAY_LABEL,
'apple_pay' => self::APPLE_PAY_LABEL,
];
}
33 changes: 12 additions & 21 deletions includes/payment-methods/class-wc-stripe-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,8 @@ public function __construct() {
add_action( 'customize_save_after', [ $this, 'clear_appearance_transients' ] );
add_action( 'save_post', [ $this, 'clear_appearance_transients_block_theme' ], 10, 2 );

// Hide action buttons for pending Amazon Pay orders (as they take a while to be confirmed).
// Hide action buttons for pending orders if they take a while to be confirmed.
add_filter( 'woocommerce_my_account_my_orders_actions', [ $this, 'filter_my_account_my_orders_actions' ], 10, 2 );
add_filter( 'woocommerce_thankyou_order_received_text', [ $this, 'filter_thankyou_order_received_text' ], 10, 2 );
}

/**
Expand Down Expand Up @@ -2418,6 +2417,16 @@ private function get_selected_payment_method_type_from_request() {
return '';
}

// Amazon Pay is available as an express checkout method only, for now.
// To prevent WooCommerce from rendering it as a standard payment method in checkout, we make
// WC_Stripe_UPE_Payment_Method_Amazon_Pay::is_available() return false.
// We set the payment method to 'amazon_pay' here, instead of earlier (i.e. passing
// 'stripe_amazon_pay' in the POST request) to avoid WooCommerce rejecting the order for
// having an "unavailable" payment method type.
if ( WC_Stripe_Payment_Methods::AMAZON_PAY === $this->get_express_payment_type_from_request() ) {
return WC_Stripe_Payment_Methods::AMAZON_PAY;
}

return substr( $payment_method_type, 0, 7 ) === 'stripe_' ? substr( $payment_method_type, 7 ) : 'card';
}

Expand Down Expand Up @@ -2940,37 +2949,19 @@ public function clear_appearance_transients() {
}

/**
* Hide "Pay" and "Cancel" action buttons for pending Amazon Pay or BACS Debit orders (as they take a while to be confirmed).
* Hide "Pay" and "Cancel" action buttons for pending orders if they take a while to be confirmed.
*
* @param $actions array An array with the default actions.
* @param $order WC_Order The order.
* @return array
*/
public function filter_my_account_my_orders_actions( $actions, $order ) {
$methods_with_delayed_confirmation = [
WC_Stripe_Payment_Methods::AMAZON_PAY_LABEL . WC_Stripe_Express_Checkout_Helper::get_payment_method_title_suffix(),
WC_Stripe_Payment_Methods::BACS_DEBIT_LABEL,
];
if ( is_order_received_page() && in_array( $order->get_payment_method_title(), $methods_with_delayed_confirmation, true ) && $order->has_status( 'pending' ) ) {
unset( $actions['pay'], $actions['cancel'] );
}
return $actions;
}

/**
* Filter the order received text for Amazon Pay orders, including the delayed confirmation information.
*
* @param string $text Default text.
* @param WC_Order|bool $order Order data.
* @return string
*/
public function filter_thankyou_order_received_text( $text, $order ) {
$amazon_pay_title = WC_Stripe_Payment_Methods::AMAZON_PAY_LABEL . WC_Stripe_Express_Checkout_Helper::get_payment_method_title_suffix();
if ( is_a( $order, 'WC_Order' ) && $order->get_payment_method_title() === $amazon_pay_title && $order->has_status( 'pending' ) ) {
$text .= '<p class="woocommerce-info">';
$text .= esc_html( 'The payment is being processed and it might take a few minutes before it\'s confirmed.' );
$text .= '</p>';
}
return $text;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ public function __construct() {
* @return string
*/
public function get_title( $payment_details = false ) {
if ( WC_Stripe_Payment_Methods::AMAZON_PAY === ( $payment_details->type ?? null ) ) {
return $this->get_card_wallet_type_title( WC_Stripe_Payment_Methods::AMAZON_PAY );
}

$wallet_type = $payment_details->card->wallet->type ?? null;
if ( $payment_details && $wallet_type ) {
return $this->get_card_wallet_type_title( $wallet_type );
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
* Tweak - Updates the Single Payment Element setting copy. Now it is labeled "Smart Checkout".
* Update - Enable/disable Amazon Pay by adding/removing it from the enabled payment methods list.
* Add - Add ACSS payment tokenization.
* Update - Update payment method type for Amazon Pay orders.

[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 @@ -2826,37 +2826,10 @@ function() {
*/
public function payment_method_titles_provider() {
return [
'Amazon' => [ WC_Stripe_Payment_Methods::AMAZON_PAY_LABEL . WC_Stripe_Express_Checkout_Helper::get_payment_method_title_suffix() ],
'Bacs' => [ WC_Stripe_Payment_Methods::BACS_DEBIT_LABEL ],
'Bacs' => [ WC_Stripe_Payment_Methods::BACS_DEBIT_LABEL ],
];
}

/**
* Test for `filter_thankyou_order_received_text`.
*
* @return void
*/
public function test_filter_thankyou_order_received_text() {
$default_text = 'Thank you. Your order has been received.';

// Order is invalid.
$actual = $this->mock_gateway->filter_thankyou_order_received_text( $default_text, false );
$expected = $default_text;

$this->assertEquals( $expected, $actual );

// Order exists.
$payment_method_suffix = WC_Stripe_Express_Checkout_Helper::get_payment_method_title_suffix();
$order = WC_Helper_Order::create_order();
$order->set_status( 'pending' );
$order->set_payment_method_title( WC_Stripe_Payment_Methods::AMAZON_PAY_LABEL . $payment_method_suffix );

$actual = $this->mock_gateway->filter_thankyou_order_received_text( $default_text, $order );
$expected = $default_text . '<p class="woocommerce-info">The payment is being processed and it might take a few minutes before it&#039;s confirmed.</p>';

$this->assertEquals( $expected, $actual );
}

/**
* Test that a failed payment intent is not reused and a new one is created instead.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ public function test_get_title( $settings, $payment_details, $expected ) {
*/
public function provide_test_get_title() {
return [
'Amazon Pay' => [
'settings' => [],
'payment details' => [
'type' => WC_Stripe_Payment_Methods::AMAZON_PAY,
],
'expected' => 'Amazon Pay (Stripe)',
],
'Google Pay' => [
'settings' => [],
'payment details' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ public function provide_test_filter_gateway_title() {
'title' => 'test',
'expected' => 'test',
],
'Amazon Pay' => [
'title' => 'Amazon Pay (Stripe)',
'expected' => 'Amazon Pay (Stripe)',
'Google Pay' => [
'title' => 'Google Pay (Stripe)',
'expected' => 'Google Pay (Stripe)',
],
];
}
Expand Down
4 changes: 4 additions & 0 deletions tests/phpunit/test-wc-stripe-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ public function provide_payment_method_allows_manual_capture(): array {
'payment_method' => 'stripe_eps',
'expected' => false,
],
'AmazonPay' => [
'payment_method' => 'stripe_amazon_pay',
'expected' => true,
],
];
}

Expand Down
Loading