Skip to content

Commit 3a1a105

Browse files
wjrosaannemirasol
andauthored
Fix payment method title when using the shortcode checkout with OC enabled (#4304)
* Revert "Implementing the order wrapper class in the new checkout (#4111)" This reverts commit 154f4df. * Revert "Implementing the order wrapper class in the root files (#4112)" This reverts commit f6cb1de. * Revert "Implementing the order wrapper class in compatibility classes (#4109)" This reverts commit 91167e3. * Revert "Implementing the order wrapper class in abstract classes and webhook handler (#4106)" This reverts commit 6e3fa25. * Revert "Implementing the order wrapper class in legacy checkout methods (#4107)" This reverts commit 7b74182. * Revert "Implementing the order wrapper class in express payment methods (#4110)" This reverts commit 893842d. * Revert "Implementing the order wrapper class in admin classes (#4108)" This reverts commit 3eda8c6. * Revert "Fix fatal error in subscription payment method switch in legacy checkout (#4222)" This reverts commit 0e90669. * Revert "Implementing the Stripe order class in unit tests (#4086)" This reverts commit 391719d. * Revert "Fix fatal error in subscription payment method switch (#4205)" This reverts commit 6aa4c89. * Remove remaining calls to to_instance * Fix payment method title when using the shortcode checkout with OC enabled * Simplyfing title logic + specific unit test * Fix pay for order page * Update comment * Changelog and readme entries * Fix tests * Removing unnecessary check * Fix wallet payment method titles * Fix pay for order confirmation title * Fix title for 3DS cards * Fix changelog and readme entries --------- Co-authored-by: Anne Mirasol <[email protected]>
1 parent cde63b1 commit 3a1a105

File tree

6 files changed

+94
-33
lines changed

6 files changed

+94
-33
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Changelog ***
22

33
= 9.6.0 - xxxx-xx-xx =
4+
* Fix - Fixes the payment method title when using the classic checkout with the Optimized Checkout enabled.
45
* Fix - Fix fatal error when checking for a payment method availability using a specific order ID.
56
* Fix - Stop checking for detached subscriptions for admin users, as it was slowing down wp-admin
67
* Update - Remove BACS from the unsupported 'change payment method for subscription' page.

client/classic/upe/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,16 @@ jQuery( function ( $ ) {
311311
removeCashAppLimitNotice();
312312
}
313313

314+
// Change the payment method container title when the Optimized Checkout is enabled
315+
if (
316+
getStripeServerData()?.isOCEnabled &&
317+
$( 'input#payment_method_stripe' ).is( ':checked' )
318+
) {
319+
$( 'label[for=payment_method_stripe]' ).text(
320+
getStripeServerData()?.OCTitle
321+
);
322+
}
323+
314324
maybeClearBlikCodeValidation();
315325
} );
316326

includes/payment-methods/class-wc-stripe-upe-payment-gateway.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ public function javascript_params() {
543543

544544
// Optimized Checkout feature flag + setting.
545545
$stripe_params['isOCEnabled'] = $this->oc_enabled;
546+
$stripe_params['OCTitle'] = $this->get_option( 'optimized_checkout_element_title' );
546547

547548
// Single Payment Element payment method parent configuration ID
548549
$stripe_params['paymentMethodConfigurationParentId'] = WC_Stripe_Payment_Method_Configurations::get_parent_configuration_id();

includes/payment-methods/class-wc-stripe-upe-payment-method-cc.php

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,18 @@ public function __construct() {
4141
* @return string
4242
*/
4343
public function get_title( $payment_details = false ) {
44+
// Wallet type
4445
$wallet_type = $payment_details->card->wallet->type ?? null;
45-
if ( $payment_details ) {
46-
if ( $wallet_type ) {
47-
return $this->get_card_wallet_type_title( $wallet_type );
48-
}
49-
50-
// Setting title for the order details page / thank you page (classic checkout) when OC is enabled.
51-
if ( $this->oc_enabled ) {
52-
$payment_method = WC_Stripe_UPE_Payment_Gateway::get_payment_method_instance( $payment_details->type );
53-
return $payment_method->get_title();
54-
}
46+
if ( $wallet_type ) {
47+
return $this->get_card_wallet_type_title( $wallet_type );
5548
}
5649

50+
// Optimized checkout
5751
if ( $this->oc_enabled ) {
58-
if ( $payment_details ) { // Setting title for the order details page / thank you page.
59-
$payment_method = WC_Stripe_UPE_Payment_Gateway::get_payment_method_instance( $payment_details->type );
60-
return $payment_method->get_title();
61-
}
62-
63-
// Classic checkout page
64-
return $this->oc_title;
52+
return $this->get_optimized_checkout_title( $payment_details );
6553
}
6654

55+
// Default
6756
return parent::get_title();
6857
}
6958

@@ -158,4 +147,26 @@ private function get_card_wallet_type_title( $express_payment_type ) {
158147

159148
return $payment_method_title . WC_Stripe_Express_Checkout_Helper::get_payment_method_title_suffix();
160149
}
150+
151+
/**
152+
* Returns the title for the optimized checkout.
153+
*
154+
* @param stdClass|array|bool $payment_details Optional payment details from charge object.
155+
* @return string
156+
*/
157+
private function get_optimized_checkout_title( $payment_details = false ) {
158+
if ( $payment_details ) { // Setting title for the order details page / thank you page.
159+
$payment_method = WC_Stripe_UPE_Payment_Gateway::get_payment_method_instance( $payment_details->type );
160+
161+
// Avoid potential recursion by checking instance type. This fixes the title on pay for order confirmation page.
162+
return $payment_method instanceof self ? parent::get_title() : $payment_method->get_title();
163+
}
164+
165+
// Block checkout and pay for order (checkout) page.
166+
if ( ( has_block( 'woocommerce/checkout' ) || ! empty( $_GET['pay_for_order'] ) ) && ! is_wc_endpoint_url( 'order-received' ) ) { // phpcs:ignore WordPress.Security.NonceVerification
167+
return $this->oc_title;
168+
}
169+
170+
return parent::get_title();
171+
}
161172
}

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
112112

113113
= 9.6.0 - xxxx-xx-xx =
114114

115+
* Fix - Fixes the payment method title when using the classic checkout with the Optimized Checkout enabled.
115116
* Fix - Fix fatal error when checking for a payment method availability using a specific order ID.
116117
* Fix - Stop checking for detached subscriptions for admin users, as it was slowing down wp-admin
117118
* Update - Remove BACS from the unsupported 'change payment method for subscription' page.

tests/phpunit/payment-methods/test-class-wc-stripe-upe-payment-method-cc.php

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,32 @@ class WC_Stripe_UPE_Payment_Method_CC_Test extends WP_UnitTestCase {
77
/**
88
* Tests for `get_title`.
99
*
10-
* @param array $settings Settings.
11-
* @param array|bool $payment_details Payment details.
12-
* @param string $expected Expected title.
10+
* @param array $settings Settings.
11+
* @param array|bool $payment_details Payment details.
12+
* @param bool $optimized_checkout_flag Optimized Checkout flag.
13+
* @param array $query_params Query parameters.
14+
* @param string $expected Expected title.
1315
* @return void
16+
*
1417
* @dataProvider provide_test_get_title
1518
*/
16-
public function test_get_title( $settings, $payment_details, $expected ) {
19+
public function test_get_title( $settings, $payment_details, $optimized_checkout_flag, $query_params, $expected ) {
20+
update_option( WC_Stripe_Feature_Flags::OC_FEATURE_FLAG_NAME, $optimized_checkout_flag ? 'yes' : 'no' );
21+
22+
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
23+
$stripe_settings['optimized_checkout_element'] = $optimized_checkout_flag ? 'yes' : 'no';
24+
WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings );
25+
1726
if ( is_array( $payment_details ) ) {
1827
$payment_details = json_decode( wp_json_encode( $payment_details ) );
1928
}
2029
if ( ! empty( $settings['key'] ) ) {
2130
update_option( $settings['key'], $settings['value'] );
2231
}
32+
if ( ! empty( $query_params ) ) {
33+
$_GET = array_merge( $_GET, $query_params );
34+
}
35+
2336
$payment_method = new WC_Stripe_UPE_Payment_Method_CC();
2437

2538
$this->assertEquals( $expected, $payment_method->get_title( $payment_details ) );
@@ -32,31 +45,55 @@ public function test_get_title( $settings, $payment_details, $expected ) {
3245
*/
3346
public function provide_test_get_title() {
3447
return [
35-
'Google Pay' => [
36-
'settings' => [],
37-
'payment details' => [
48+
'optimized checkout, with payment details' => [
49+
'settings' => [],
50+
'payment details' => [
51+
'type' => WC_Stripe_Payment_Methods::ALIPAY,
52+
],
53+
'optimized checkout flag' => true,
54+
'query params' => [],
55+
'expected' => 'Alipay',
56+
],
57+
'optimized checkout, block checkout page / pay for order' => [
58+
'settings' => [],
59+
'payment details' => false,
60+
'optimized checkout flag' => true,
61+
'query params' => [
62+
'pay_for_order' => 'true',
63+
],
64+
'expected' => 'Stripe',
65+
],
66+
'Google Pay' => [
67+
'settings' => [],
68+
'payment details' => [
3869
'card' => [
3970
'wallet' => [
4071
'type' => WC_Stripe_Payment_Methods::GOOGLE_PAY,
4172
],
4273
],
4374
],
44-
'expected' => 'Google Pay (Stripe)',
75+
'optimized checkout flag' => false,
76+
'query params' => [],
77+
'expected' => 'Google Pay (Stripe)',
4578
],
46-
'default, from settings' => [
47-
'settings' => [
79+
'default, from settings' => [
80+
'settings' => [
4881
'key' => 'woocommerce_stripe_card_settings',
4982
'value' => [
5083
'title' => 'Card Custom Title',
5184
],
5285
],
53-
'payment details' => false,
54-
'expected' => 'Card Custom Title',
86+
'payment details' => false,
87+
'optimized checkout flag' => false,
88+
'query params' => [],
89+
'expected' => 'Card Custom Title',
5590
],
56-
'default, hardcoded' => [
57-
'settings' => [],
58-
'payment details' => false,
59-
'expected' => 'Credit / Debit Card',
91+
'default, hardcoded' => [
92+
'settings' => [],
93+
'payment details' => false,
94+
'optimized checkout flag' => false,
95+
'query params' => [],
96+
'expected' => 'Credit / Debit Card',
6097
],
6198
];
6299
}

0 commit comments

Comments
 (0)