Skip to content

Commit 03da4d7

Browse files
wjrosadaledupreez
andauthored
Simplifying instructions logic for OC (#4626)
* Simplifying instructions logic for OC * Readme and changelog entries * Doc block update * Remove deprecated method call in shortcode checkout * Deprecating parameter instead of removing it * Update includes/payment-methods/class-wc-stripe-upe-payment-method-blik.php Co-authored-by: daledupreez <[email protected]> * Making the check for the deprecated parameter more strict * Getting testing instructions only for enabled payment methods * Fix tests --------- Co-authored-by: daledupreez <[email protected]>
1 parent 2fcee3b commit 03da4d7

9 files changed

+70
-39
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.9.0 - xxxx-xx-xx =
4+
* Dev - Simplifies the way test payment instructions are built when the Optimized Checkout is enabled
45
* Dev - Upgrades the ESLint packages and their related libraries
56
* Dev - Upgrade the Prettier package and related libraries, and apply updated formatting rules
67
* Dev - Extracts Optimized Checkout logic from card payment method into new WC_Stripe_UPE_Payment_Method_OC class

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

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -295,33 +295,16 @@ public static function get_payment_method_instance( $payment_method ) {
295295
return new $payment_method_class();
296296
}
297297

298-
/**
299-
* Returns the HTML for the bundled payment instructions when Smart Checkout is enabled.
300-
*
301-
* @return string
302-
*
303-
* @deprecated 9.5.0 Use `get_testing_instructions_for_optimized_checkout()` instead.
304-
*/
305-
public static function get_testing_instructions_for_smart_checkout() {
306-
return static::get_testing_instructions_for_optimized_checkout();
307-
}
308-
309298
/**
310299
* Returns the HTML for the bundled payment instructions when Optimized Checkout (previously known as Smart Checkout and SPE) is enabled.
311300
*
312301
* @return string
302+
*
303+
* @deprecated 9.9.0 Use `WC_Stripe_UPE_Payment_Method_OC::get_testing_instructions()` instead.
313304
*/
314305
public static function get_testing_instructions_for_optimized_checkout() {
315-
$instructions = '';
316-
$base_instruction_html = '<div id="wc-stripe-payment-method-instructions-%s" class="wc-stripe-payment-method-instruction" style="display: none;">%s</div>';
317-
foreach ( self::UPE_AVAILABLE_METHODS as $payment_method_class ) {
318-
$payment_method_instructions = ( new $payment_method_class() )->get_testing_instructions( true );
319-
if ( $payment_method_instructions ) {
320-
$instructions .= sprintf( $base_instruction_html, $payment_method_class::STRIPE_ID, $payment_method_instructions );
321-
}
322-
}
323-
324-
return $instructions;
306+
$payment_method = new WC_Stripe_UPE_Payment_Method_OC();
307+
return $payment_method->get_testing_instructions();
325308
}
326309

327310
/**
@@ -795,7 +778,7 @@ public function payment_fields() {
795778
if ( $this->testmode ) :
796779
if ( $this->oc_enabled ) :
797780
echo wp_kses(
798-
self::get_testing_instructions_for_optimized_checkout(),
781+
( new WC_Stripe_UPE_Payment_Method_OC() )->get_testing_instructions(),
799782
[
800783
'div' => [
801784
'id' => [],

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,16 @@ public function get_retrievable_type() {
5353
/**
5454
* Returns testing instructions to be printed at checkout in test mode.
5555
*
56-
* @param bool $show_optimized_checkout_instruction Whether this is being called through the Optimized Checkout instructions method. Used to avoid an infinite loop call.
5756
* @return string
5857
*/
5958
public function get_testing_instructions( $show_optimized_checkout_instruction = false ) {
59+
if ( false !== $show_optimized_checkout_instruction ) {
60+
_deprecated_argument(
61+
__FUNCTION__,
62+
'9.9.0'
63+
);
64+
}
65+
6066
return sprintf(
6167
/* translators: 1) HTML strong open tag 2) HTML strong closing tag */
6268
esc_html__( '%1$sTest mode:%2$s use any 6-digit number to authorize payment.', 'woocommerce-gateway-stripe' ),

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,16 @@ public function requires_automatic_capture() {
108108
/**
109109
* Returns testing credentials to be printed at checkout in test mode.
110110
*
111-
* @param bool $show_optimized_checkout_instruction Whether this is being called through the Optimized Checkout instructions method. Used to avoid an infinite loop call.
112111
* @return string
113112
*/
114113
public function get_testing_instructions( $show_optimized_checkout_instruction = false ) {
114+
if ( false !== $show_optimized_checkout_instruction ) {
115+
_deprecated_argument(
116+
__FUNCTION__,
117+
'9.9.0'
118+
);
119+
}
120+
115121
return sprintf(
116122
/* translators: 1) HTML strong open tag 2) HTML strong closing tag 3) HTML anchor open tag 2) HTML anchor closing tag */
117123
esc_html__( '%1$sTest mode:%2$s use the test VISA card 4242424242424242 with any expiry date and CVC. Other payment methods may redirect to a Stripe test page to authorize payment. More test card numbers are listed %3$shere%4$s.', 'woocommerce-gateway-stripe' ),

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,30 @@ public function requires_automatic_capture() {
103103
/**
104104
* Returns testing credentials to be printed at checkout in test mode.
105105
*
106-
* @param bool $show_optimized_checkout_instruction Whether this is being called through the Optimized Checkout instructions method. Used to avoid an infinite loop call.
107106
* @return string
108107
*/
109108
public function get_testing_instructions( $show_optimized_checkout_instruction = false ) {
110-
if ( ! $show_optimized_checkout_instruction ) {
111-
return WC_Stripe_UPE_Payment_Gateway::get_testing_instructions_for_optimized_checkout();
109+
if ( false !== $show_optimized_checkout_instruction ) {
110+
_deprecated_argument(
111+
__FUNCTION__,
112+
'9.9.0'
113+
);
112114
}
113115

114-
return sprintf(
115-
/* translators: 1) HTML strong open tag 2) HTML strong closing tag 3) HTML anchor open tag 2) HTML anchor closing tag */
116-
esc_html__( '%1$sTest mode:%2$s use the test VISA card 4242424242424242 with any expiry date and CVC. Other payment methods may redirect to a Stripe test page to authorize payment. More test card numbers are listed %3$shere%4$s.', 'woocommerce-gateway-stripe' ),
117-
'<strong>',
118-
'</strong>',
119-
'<a href="https://docs.stripe.com/testing" target="_blank">',
120-
'</a>'
121-
);
116+
$instructions = '';
117+
$base_instruction_html = '<div id="wc-stripe-payment-method-instructions-%s" class="wc-stripe-payment-method-instruction" style="display: none;">%s</div>';
118+
foreach ( $this->get_upe_enabled_payment_method_ids() as $payment_method_id ) {
119+
$payment_method = WC_Stripe_UPE_Payment_Gateway::get_payment_method_instance( $payment_method_id );
120+
if ( ! $payment_method ) {
121+
continue;
122+
}
123+
124+
$payment_method_instructions = $payment_method->get_testing_instructions();
125+
if ( $payment_method_instructions ) {
126+
$instructions .= sprintf( $base_instruction_html, $payment_method::STRIPE_ID, $payment_method_instructions );
127+
}
128+
}
129+
130+
return $instructions;
122131
}
123132
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,16 @@ public function get_retrievable_type() {
4949
/**
5050
* Returns testing credentials to be printed at checkout in test mode.
5151
*
52-
* @param bool $show_optimized_checkout_instruction Whether this is being called through the Optimized Checkout instructions method. Used to avoid an infinite loop call.
5352
* @return string
5453
*/
5554
public function get_testing_instructions( $show_optimized_checkout_instruction = false ) {
55+
if ( false !== $show_optimized_checkout_instruction ) {
56+
_deprecated_argument(
57+
__FUNCTION__,
58+
'9.9.0'
59+
);
60+
}
61+
5662
return sprintf(
5763
/* translators: 1) HTML strong open tag 2) HTML strong closing tag 3) HTML anchor open tag 2) HTML anchor closing tag */
5864
esc_html__( '%1$sTest mode:%2$s use the test account number AT611904300234573201. Other payment methods may redirect to a Stripe test page to authorize payment. More test card numbers are listed %3$shere%4$s.', 'woocommerce-gateway-stripe' ),

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,10 +513,16 @@ public function can_refund_via_stripe() {
513513
/**
514514
* Returns testing credentials to be printed at checkout in test mode.
515515
*
516-
* @param bool $show_optimized_checkout_instruction Whether this is being called through the Optimized Checkout instructions method. Used to avoid an infinite loop call.
517516
* @return string
518517
*/
519518
public function get_testing_instructions( bool $show_optimized_checkout_instruction = false ) {
519+
if ( $show_optimized_checkout_instruction ) {
520+
_deprecated_argument(
521+
__FUNCTION__,
522+
'9.9.0'
523+
);
524+
}
525+
520526
return '';
521527
}
522528

readme.txt

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

113113
= 9.9.0 - xxxx-xx-xx =
114+
* Dev - Simplifies the way test payment instructions are built when the Optimized Checkout is enabled
114115
* Dev - Upgrades the ESLint packages and their related libraries
115116
* Dev - Upgrade the Prettier package and related libraries, and apply updated formatting rules
116117
* Dev - Extracts Optimized Checkout logic from card payment method into new WC_Stripe_UPE_Payment_Method_OC class

tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Method_OC_Test.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,21 @@ public function test_feature_methods() {
9595
public function test_get_testing_instructions() {
9696
$expected = '<div id="wc-stripe-payment-method-instructions-card" class="wc-stripe-payment-method-instruction" style="display: none;"><strong>Test mode:</strong> use the test VISA card 4242424242424242 with any expiry date and CVC. Other payment methods may redirect to a Stripe test page to authorize payment. More test card numbers are listed <a href="https://docs.stripe.com/testing" target="_blank">here</a>.</div><div id="wc-stripe-payment-method-instructions-blik" class="wc-stripe-payment-method-instruction" style="display: none;"><strong>Test mode:</strong> use any 6-digit number to authorize payment.</div><div id="wc-stripe-payment-method-instructions-sepa_debit" class="wc-stripe-payment-method-instruction" style="display: none;"><strong>Test mode:</strong> use the test account number AT611904300234573201. Other payment methods may redirect to a Stripe test page to authorize payment. More test card numbers are listed <a href="https://docs.stripe.com/testing?payment-method=sepa-direct-debit#non-card-payments" target="_blank">here</a>.</div>';
9797

98-
$payment_method = new WC_Stripe_UPE_Payment_Method_OC();
99-
$actual = $payment_method->get_testing_instructions();
98+
$payment_method = $this->getMockBuilder( WC_Stripe_UPE_Payment_Method_OC::class )
99+
->onlyMethods( [ 'get_upe_enabled_payment_method_ids' ] )
100+
->getMock();
101+
102+
$payment_method->expects( $this->once() )
103+
->method( 'get_upe_enabled_payment_method_ids' )
104+
->willReturn(
105+
[
106+
WC_Stripe_Payment_Methods::CARD,
107+
WC_Stripe_Payment_Methods::BLIK,
108+
WC_Stripe_Payment_Methods::SEPA_DEBIT,
109+
]
110+
);
111+
112+
$actual = $payment_method->get_testing_instructions();
100113

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

0 commit comments

Comments
 (0)