Skip to content

Commit d276e3a

Browse files
committed
Merge trunk v5.5.1 into develop
2 parents 2539993 + c63c58a commit d276e3a

10 files changed

+102
-8
lines changed

changelog.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
*** WooCommerce Payments Changelog ***
22

3+
= 5.5.1 - 2023-03-01 =
4+
* Add - When enabling WooPay, if legacy UPE is enabled, upgrades feature flag to split UPE instead.
5+
* Fix - Avoid rendering save cards checkbox for logged out users
6+
* Fix - Fix get woopay available countries return type
7+
* Fix - Fix handling saved tokens for payment gateways while using shortcode checkout
8+
* Fix - Fix subscription renewal creating multiple charges with UPE.
9+
* Fix - Fix WooPay settings notice visibility
10+
311
= 5.5.0 - 2023-02-22 =
412
* Add - Added learn more link to deposits page
513
* Add - Added tracking for the split UPE feature flag.

includes/class-wc-payments-checkout.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ public function payment_fields() {
210210
<?php
211211
if ( $this->gateway->is_saved_cards_enabled() ) {
212212
$force_save_payment = ( $display_tokenization && ! apply_filters( 'wc_payments_display_save_payment_method_checkbox', $display_tokenization ) ) || is_add_payment_method_page();
213-
$this->gateway->save_payment_method_checkbox( $force_save_payment );
213+
if ( is_user_logged_in() || $force_save_payment ) {
214+
$this->gateway->save_payment_method_checkbox( $force_save_payment );
215+
}
214216
}
215217
?>
216218

includes/compat/subscriptions/trait-wc-payment-gateway-wcpay-subscriptions.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ abstract protected function prepare_payment_information( $order );
8585
*/
8686
private static $payment_method_meta_key = 'token';
8787

88+
/**
89+
* Stores a flag to indicate if the subscription integration hooks have been attached.
90+
*
91+
* The callbacks attached as part of maybe_init_subscriptions() only need to be attached once to avoid duplication.
92+
*
93+
* @var bool False by default, true once the callbacks have been attached.
94+
*/
95+
private static $has_attached_integration_hooks = false;
96+
8897
/**
8998
* Initialize subscription support and hooks.
9099
*/
@@ -95,7 +104,7 @@ public function maybe_init_subscriptions() {
95104

96105
/*
97106
* Base set of subscription features to add.
98-
* The WCPay payment gateway supports these feautres
107+
* The WCPay payment gateway supports these features
99108
* for both WCPay Subscriptions and WooCommerce Subscriptions.
100109
*/
101110
$payment_gateway_features = [
@@ -131,6 +140,19 @@ public function maybe_init_subscriptions() {
131140

132141
$this->supports = array_merge( $this->supports, $payment_gateway_features );
133142

143+
/**
144+
* The following callbacks are only attached once to avoid duplication.
145+
* The callbacks are also only intended to be attached for the WCPay core payment gateway ($this->id = 'woocommerce_payments').
146+
*
147+
* If new payment method IDs (eg 'sepa_debit') are added to this condition in the future, care should be taken to ensure duplication,
148+
* including double renewal charging, isn't introduced.
149+
*/
150+
if ( self::$has_attached_integration_hooks || 'woocommerce_payments' !== $this->id ) {
151+
return;
152+
}
153+
154+
self::$has_attached_integration_hooks = true;
155+
134156
add_filter( 'woocommerce_email_classes', [ $this, 'add_emails' ], 20 );
135157
add_filter( 'woocommerce_available_payment_gateways', [ $this, 'prepare_order_pay_page' ] );
136158

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "woocommerce-payments",
3-
"version": "5.5.0",
3+
"version": "5.5.1",
44
"main": "webpack.config.js",
55
"author": "Automattic",
66
"license": "GPL-3.0-or-later",

readme.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: payment gateway, payment, apple pay, credit card, google pay
44
Requires at least: 5.9
55
Tested up to: 6.1
66
Requires PHP: 7.0
7-
Stable tag: 5.5.0
7+
Stable tag: 5.5.1
88
License: GPLv2 or later
99
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -98,6 +98,14 @@ Please note that our support for the checkout block is still experimental and th
9898

9999
== Changelog ==
100100

101+
= 5.5.1 - 2023-03-01 =
102+
* Add - When enabling WooPay, if legacy UPE is enabled, upgrades feature flag to split UPE instead.
103+
* Fix - Avoid rendering save cards checkbox for logged out users
104+
* Fix - Fix get woopay available countries return type
105+
* Fix - Fix handling saved tokens for payment gateways while using shortcode checkout
106+
* Fix - Fix subscription renewal creating multiple charges with UPE.
107+
* Fix - Fix WooPay settings notice visibility
108+
101109
= 5.5.0 - 2023-02-22 =
102110
* Add - Added learn more link to deposits page
103111
* Add - Added tracking for the split UPE feature flag.

tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-payment-method-order-note.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ class WC_Payment_Gateway_WCPay_Subscriptions_Payment_Method_Order_Note_Test exte
7575
*/
7676
private $mock_wcpay_account;
7777

78+
public function tear_down() {
79+
parent::tear_down();
80+
81+
// So that the gateway hooks are re-attached for the next test, we need to reset the flag that prevents the integration hooks from being attached.
82+
$reflection = new \ReflectionClass( $this->wcpay_gateway );
83+
$property = $reflection->getProperty( 'has_attached_integration_hooks' );
84+
$property->setAccessible( true );
85+
$property->setValue( $this->wcpay_gateway, false );
86+
}
87+
7888
public function set_up() {
7989
parent::set_up();
8090

tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,8 @@ public function test_adds_custom_payment_meta_input_fallback_until_subs_3_0_7()
782782
remove_all_actions( 'woocommerce_admin_order_data_after_billing_address' );
783783

784784
WC_Subscriptions::$version = '3.0.7';
785-
new \WC_Payment_Gateway_WCPay(
785+
786+
$payment_gateway = new \WC_Payment_Gateway_WCPay(
786787
$this->mock_api_client,
787788
$this->mock_wcpay_account,
788789
$this->mock_customer_service,
@@ -792,6 +793,13 @@ public function test_adds_custom_payment_meta_input_fallback_until_subs_3_0_7()
792793
$this->order_service
793794
);
794795

796+
// Ensure the has_attached_integration_hooks property is set to false so callbacks can be attached in maybe_init_subscriptions().
797+
$ref = new ReflectionProperty( $payment_gateway, 'has_attached_integration_hooks' );
798+
$ref->setAccessible( true );
799+
$ref->setValue( null, false );
800+
801+
$payment_gateway->maybe_init_subscriptions();
802+
795803
$this->assertTrue( has_action( 'woocommerce_admin_order_data_after_billing_address' ) );
796804
}
797805

tests/unit/test-class-wc-payment-gateway-wcpay.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,42 @@ function ( $output ) {
324324
$this->wcpay_gateway->payment_fields();
325325
}
326326

327+
public function test_save_card_checkbox_not_displayed_for_non_logged_in_users() {
328+
$this->wcpay_gateway->update_option( 'saved_cards', 'yes' );
329+
wp_set_current_user( 0 );
330+
331+
$this->refresh_payments_checkout();
332+
333+
// Use a callback to get and test the output (also suppresses the output buffering being printed to the CLI).
334+
$this->setOutputCallback(
335+
function ( $output ) {
336+
$result = preg_match_all( '/.*<input.*id="wc-woocommerce_payments-new-payment-method".*\/>.*/', $output );
337+
338+
$this->assertSame( 0, $result );
339+
}
340+
);
341+
342+
$this->wcpay_gateway->payment_fields();
343+
}
344+
345+
public function test_save_card_checkbox_displayed_for_logged_in_users() {
346+
$this->wcpay_gateway->update_option( 'saved_cards', 'yes' );
347+
wp_set_current_user( 1 );
348+
349+
$this->refresh_payments_checkout();
350+
351+
// Use a callback to get and test the output (also suppresses the output buffering being printed to the CLI).
352+
$this->setOutputCallback(
353+
function ( $output ) {
354+
$result = preg_match_all( '/.*<input.*id="wc-woocommerce_payments-new-payment-method".*\/>.*/', $output );
355+
356+
$this->assertSame( 1, $result );
357+
}
358+
);
359+
360+
$this->wcpay_gateway->payment_fields();
361+
}
362+
327363
public function test_fraud_prevention_token_added_when_enabled() {
328364
$token_value = 'test-token';
329365
$fraud_prevention_service_mock = $this->get_fraud_prevention_service_mock();

woocommerce-payments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* WC tested up to: 7.3.0
1313
* Requires at least: 5.9
1414
* Requires PHP: 7.0
15-
* Version: 5.5.0
15+
* Version: 5.5.1
1616
*
1717
* @package WooCommerce\Payments
1818
*/

0 commit comments

Comments
 (0)