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

Improving the handling of express method titles #3844

Open
wants to merge 25 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5964a5c
Hiding actions for pending Amazon Pay orders
wjrosa Feb 5, 2025
d087e0b
Improving the handling of express method titles
wjrosa Feb 5, 2025
7dd9b52
Checking for order received page
wjrosa Feb 6, 2025
15c0fdf
Adding specific unit tests
wjrosa Feb 6, 2025
8bf1210
Readme and changelog entries
wjrosa Feb 6, 2025
2b0870c
Adding specific unit tests
wjrosa Feb 6, 2025
ecef98d
Adding specific unit tests
wjrosa Feb 6, 2025
cbddf33
Changelog and readme entries
wjrosa Feb 6, 2025
30ae66d
Revert automatic PHPCS fix
wjrosa Feb 6, 2025
d5a3bb1
Merge branch 'tweak/hiding-actions-for-pending-amazon-pay-orders' int…
wjrosa Feb 6, 2025
908a8df
Merge branch 'develop' into dev/improving-handling-of-ece-method-titles
wjrosa Feb 13, 2025
f342132
Merge branch 'develop' into dev/improving-handling-of-ece-method-titles
wjrosa Feb 13, 2025
f404e83
Merge branch 'develop' into dev/improving-handling-of-ece-method-titles
diegocurbelo Feb 17, 2025
9761184
Merge branch 'develop' into dev/improving-handling-of-ece-method-titles
wjrosa Feb 18, 2025
59bad51
Merge branch 'develop' into dev/improving-handling-of-ece-method-titles
wjrosa Feb 20, 2025
7cdf96e
Merge branch 'develop' into dev/improving-handling-of-ece-method-titles
wjrosa Feb 20, 2025
3f9b85f
Merge branch 'develop' into dev/improving-handling-of-ece-method-titles
wjrosa Feb 25, 2025
27eb069
Merge branch 'dev/improving-handling-of-ece-method-titles' of https:/…
wjrosa Feb 25, 2025
bc554a2
Fix changelog and readme entries
wjrosa Feb 25, 2025
f523739
Improving handling of BACS debit payment method title
wjrosa Feb 25, 2025
28cd97a
Merge branch 'develop' into dev/improving-handling-of-ece-method-titles
wjrosa Feb 26, 2025
49851d3
Refactor implementation removing constant class following review comm…
wjrosa Feb 26, 2025
e7d8eec
Minor refactoring
wjrosa Feb 26, 2025
c6c0890
Fix tests + updating missing occurrences
wjrosa Feb 26, 2025
12561e4
Minor refactor
wjrosa Feb 26, 2025
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
@@ -1,6 +1,7 @@
*** Changelog ***

= 9.3.0 - xxxx-xx-xx =
* Dev - Improves how we handle express payment method titles by introducing new constants and methods to replace duplicate code.
* Fix - Fixes a fatal error that might happen when a payment method ID cannot be retrieved during the processing of an order (new checkout experience).
* Dev - Generates a code coverage report for PHP Unit tests as a comment on PRs.
* Add - Adds Stripe specific information to the System Status Report data.
Expand Down
24 changes: 16 additions & 8 deletions includes/class-wc-stripe-blocks-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,14 +515,22 @@ public function add_stripe_intents( PaymentContext $context, PaymentResult &$res
* @param string $payment_request_type The payment request type used for payment.
*/
private function add_order_meta( \WC_Order $order, $payment_request_type ) {
if ( 'apple_pay' === $payment_request_type ) {
$order->set_payment_method_title( 'Apple Pay (Stripe)' );
$order->save();
} elseif ( 'google_pay' === $payment_request_type ) {
$order->set_payment_method_title( 'Google Pay (Stripe)' );
$order->save();
} elseif ( 'payment_request_api' === $payment_request_type ) {
$order->set_payment_method_title( 'Payment Request (Stripe)' );
$payment_method_title = '';
Copy link
Contributor Author

@wjrosa wjrosa Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just making it easier to read. And fixing the suffix part (it is dynamic).

switch ( $payment_request_type ) {
case 'apple_pay':
$payment_method_title = WC_Stripe_Payment_Methods::APPLE_PAY_LABEL;
break;
case 'google_pay':
$payment_method_title = WC_Stripe_Payment_Methods::GOOGLE_PAY_LABEL;
break;
case 'payment_request_api':
$payment_method_title = 'Payment Request';
break;
}

if ( $payment_method_title ) {
$payment_method_suffix = WC_Stripe_Express_Checkout_Helper::get_payment_method_title_suffix();
$order->set_payment_method_title( $payment_method_title . $payment_method_suffix );
$order->save();
}
}
Expand Down
14 changes: 9 additions & 5 deletions includes/constants/class-wc-stripe-payment-methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ class WC_Stripe_Payment_Methods {
const WECHAT_PAY = 'wechat_pay';

// Payment method labels
const AMAZON_PAY_LABEL = 'Amazon Pay (Stripe)';
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';
const LINK_LABEL = 'Link';

/**
* Payment methods that are considered as voucher payment methods.
Expand Down Expand Up @@ -67,10 +70,11 @@ class WC_Stripe_Payment_Methods {
];

/**
* Payment methods we need to hide the action buttons from the order page.
* List of express payment methods labels (excluding Link).
*/
const PAYMENT_METHODS_WITH_DELAYED_VERIFICATION = [
self::AMAZON_PAY_LABEL,
self::BACS_DEBIT_LABEL,
const EXPRESS_METHODS_LABELS = [
self::AMAZON_PAY => self::AMAZON_PAY_LABEL,
'google_pay' => self::GOOGLE_PAY_LABEL,
'apple_pay' => self::APPLE_PAY_LABEL,
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,16 @@ public function add_order_meta( $order_id, $posted_data ) {
$order = wc_get_order( $order_id );

$express_checkout_type = wc_clean( wp_unslash( $_POST['express_checkout_type'] ) );

$payment_method_title = '';
if ( 'apple_pay' === $express_checkout_type ) {
$order->set_payment_method_title( 'Apple Pay (Stripe)' );
$order->save();
$payment_method_title = WC_Stripe_Payment_Methods::APPLE_PAY_LABEL;
} elseif ( 'google_pay' === $express_checkout_type ) {
$order->set_payment_method_title( 'Google Pay (Stripe)' );
$payment_method_title = WC_Stripe_Payment_Methods::GOOGLE_PAY_LABEL;
}

if ( $payment_method_title ) {
$payment_method_suffix = WC_Stripe_Express_Checkout_Helper::get_payment_method_title_suffix();
$order->set_payment_method_title( $payment_method_title . $payment_method_suffix );
$order->save();
}

Expand All @@ -408,6 +412,9 @@ public function add_order_meta( $order_id, $posted_data ) {

/**
* Filters the gateway title to reflect express checkout type
*
* @param string $title The gateway title.
* @param string $id The gateway ID.
*/
public function filter_gateway_title( $title, $id ) {
global $theorder;
Expand All @@ -424,7 +431,15 @@ public function filter_gateway_title( $title, $id ) {
$method_title = $theorder->get_payment_method_title();

if ( 'stripe' === $id && ! empty( $method_title ) ) {
if ( in_array( $method_title, [ 'Apple Pay (Stripe)', 'Google Pay (Stripe)', 'Amazon Pay (Stripe)' ], true ) ) {
$express_method_titles = WC_Stripe_Payment_Methods::EXPRESS_METHODS_LABELS;
$suffix = WC_Stripe_Express_Checkout_Helper::get_payment_method_title_suffix();
array_walk(
$express_method_titles,
function( &$value, $key ) use ( $suffix ) {
$value .= $suffix;
}
);
if ( in_array( $method_title, $express_method_titles, true ) ) {
return $method_title;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,19 @@ public function __construct() {
$this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : '';

$this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' );
}

/**
* Returns the suffix set for the express payment method titles.
*
* @return mixed
*/
public static function get_payment_method_title_suffix() {
$suffix = apply_filters( 'wc_stripe_payment_request_payment_method_title_suffix', 'Stripe' );
if ( ! empty( $suffix ) ) {
$suffix = " ($suffix)";
}
return $suffix;
}

/**
Expand Down
11 changes: 8 additions & 3 deletions includes/payment-methods/class-wc-stripe-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -2917,14 +2917,18 @@ public function clear_appearance_transients() {
}

/**
* Hide "Pay" and "Cancel" action buttons for pending Amazon Pay orders (as they take a while to be confirmed).
* Hide "Pay" and "Cancel" action buttons for pending Amazon Pay or BACS Debit orders (as 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 ) {
if ( is_order_received_page() && in_array( $order->get_payment_method_title(), WC_Stripe_Payment_Methods::PAYMENT_METHODS_WITH_DELAYED_VERIFICATION ) && $order->has_status( 'pending' ) ) {
$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;
Expand All @@ -2938,7 +2942,8 @@ public function filter_my_account_my_orders_actions( $actions, $order ) {
* @return string
*/
public function filter_thankyou_order_received_text( $text, $order ) {
if ( $order->get_payment_method_title() === 'Amazon Pay (Stripe)' && $order->has_status( 'pending' ) ) {
$amazon_pay_title = WC_Stripe_Payment_Methods::AMAZON_PAY_LABEL . WC_Stripe_Express_Checkout_Helper::get_payment_method_title_suffix();
if ( $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>';
Expand Down
23 changes: 8 additions & 15 deletions includes/payment-methods/class-wc-stripe-upe-payment-method-cc.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ public function __construct() {
* @return string
*/
public function get_title( $payment_details = false ) {
$wallet_type = WC_Stripe_Payment_Methods::AMAZON_PAY === ( $payment_details->type ?? null ) ? WC_Stripe_Payment_Methods::AMAZON_PAY : ( $payment_details->card->wallet->type ?? null );
if ( WC_Stripe_Payment_Methods::AMAZON_PAY === ( $payment_details->type ?? null ) ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just making it easier to read.

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 Expand Up @@ -126,24 +130,13 @@ public function get_testing_instructions() {
* @return string The title for the card wallet type.
*/
private function get_card_wallet_type_title( $express_payment_type ) {
$express_payment_titles = [
'apple_pay' => 'Apple Pay',
'google_pay' => 'Google Pay',
WC_Stripe_Payment_Methods::AMAZON_PAY => 'Amazon Pay',
];

$payment_method_title = $express_payment_titles[ $express_payment_type ] ?? false;
$express_payment_titles = WC_Stripe_Payment_Methods::EXPRESS_METHODS_LABELS;
$payment_method_title = $express_payment_titles[ $express_payment_type ] ?? false;

if ( ! $payment_method_title ) {
return parent::get_title();
}

$suffix = apply_filters( 'wc_stripe_payment_request_payment_method_title_suffix', 'Stripe' );

if ( ! empty( $suffix ) ) {
$suffix = " ($suffix)";
}

return $payment_method_title . $suffix;
return $payment_method_title . WC_Stripe_Express_Checkout_Helper::get_payment_method_title_suffix();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public function requires_automatic_capture() {

/**
* Filters the gateway title to reflect Link as the payment method.
*
* @param string $title The gateway title.
* @param string $id The gateway ID.
*/
public function filter_gateway_title( $title, $id ) {
global $theorder;
Expand All @@ -130,7 +133,7 @@ public function filter_gateway_title( $title, $id ) {
$method_title = $theorder->get_payment_method_title();

if ( 'stripe' === $id && ! empty( $method_title ) ) {
if ( 'Link' === $method_title ) {
if ( WC_Stripe_Payment_Methods::LINK_LABEL === $method_title ) {
return $method_title;
}
}
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
= 9.3.0 - xxxx-xx-xx =
* Fix - Fixes a fatal error that might happen when a payment method ID cannot be retrieved during the processing of an order (new checkout experience).
* Dev - Generates a code coverage report for PHP Unit tests as a comment on PRs.
* Dev - Improves how we handle express payment method titles by introducing new constants and methods to replace duplicate code.
* Add - Adds Stripe specific information to the System Status Report data.
* Fix - Fixes a fatal error that might happen during extension install due to missing Amazon Pay default settings data, when registering the settings route.
* Dev - Adds the payment method constants to the payment methods map file (frontend side).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2827,7 +2827,7 @@ function() {
*/
public function payment_method_titles_provider() {
return [
'Amazon' => [ WC_Stripe_Payment_Methods::AMAZON_PAY_LABEL ],
'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 ],
];
}
Expand All @@ -2838,9 +2838,11 @@ public function payment_method_titles_provider() {
* @return void
*/
public function test_filter_thankyou_order_received_text() {
$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( 'Amazon Pay (Stripe)' );
$order->set_payment_method_title( WC_Stripe_Payment_Methods::AMAZON_PAY_LABEL . $payment_method_suffix );

$default_text = 'Thank you. Your order has been received.';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,16 @@ public function provide_test_get_normalized_postal_code() {
],
];
}

/**
* Test for `get_payment_method_title_suffix`
*
* @return void
*/
public function test_get_payment_method_title_suffix() {
$wc_stripe_ece_helper = new WC_Stripe_Express_Checkout_Helper();
$actual = $wc_stripe_ece_helper->get_payment_method_title_suffix();

$this->assertEquals( ' (Stripe)', $actual );
}
}
Loading