From da0a15c7233f4f9c76885ae44726335f8c5d242f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 22 Apr 2024 10:04:56 +0000 Subject: [PATCH 1/3] Update version and add changelog entries for release 7.5.2 --- changelog.txt | 2 ++ package-lock.json | 4 ++-- package.json | 2 +- readme.txt | 5 ++++- woocommerce-payments.php | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/changelog.txt b/changelog.txt index 9adaa798fc6..e6996419213 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,7 @@ *** WooPayments Changelog *** += 7.5.2 - 2024-04-22 = + = 7.5.1 - 2024-04-18 = * Fix - Avoid updating billing details for legacy card objects. * Fix - fix: BNPL announcement link. diff --git a/package-lock.json b/package-lock.json index ed9bbc6f32b..e2dc9270947 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "woocommerce-payments", - "version": "7.5.1", + "version": "7.5.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "woocommerce-payments", - "version": "7.5.1", + "version": "7.5.2", "hasInstallScript": true, "license": "GPL-3.0-or-later", "dependencies": { diff --git a/package.json b/package.json index 9a9b04c3508..12b65b334dc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "woocommerce-payments", - "version": "7.5.1", + "version": "7.5.2", "main": "webpack.config.js", "author": "Automattic", "license": "GPL-3.0-or-later", diff --git a/readme.txt b/readme.txt index 7733a9ab4f4..3533df1a030 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: woocommerce payments, apple pay, credit card, google pay, payment, payment Requires at least: 6.0 Tested up to: 6.4 Requires PHP: 7.3 -Stable tag: 7.5.1 +Stable tag: 7.5.2 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -94,6 +94,9 @@ Please note that our support for the checkout block is still experimental and th == Changelog == += 7.5.2 - 2024-04-22 = + + = 7.5.1 - 2024-04-18 = * Fix - Avoid updating billing details for legacy card objects. * Fix - fix: BNPL announcement link. diff --git a/woocommerce-payments.php b/woocommerce-payments.php index d99091bde94..4ae2a12a489 100644 --- a/woocommerce-payments.php +++ b/woocommerce-payments.php @@ -11,7 +11,7 @@ * WC tested up to: 8.7.0 * Requires at least: 6.0 * Requires PHP: 7.3 - * Version: 7.5.1 + * Version: 7.5.2 * Requires Plugins: woocommerce * * @package WooCommerce\Payments From 174ea295312176319960b457278873d2ff52c6c6 Mon Sep 17 00:00:00 2001 From: Radoslav Georgiev Date: Mon, 22 Apr 2024 14:45:05 +0300 Subject: [PATCH 2/3] Patch: Fix subscription renewals exceptions (#8683) Co-authored-by: Timur Karimov Co-authored-by: Timur Karimov Co-authored-by: Daniel Mallory Co-authored-by: Daniel Mallory --- .../fix-8678-use-legacy-approach-off-session | 4 ++ ...-deprecated-param-from-asset-data-registry | 4 ++ includes/class-wc-payment-gateway-wcpay.php | 2 +- includes/class-wc-payments-utils.php | 23 +++++++++- includes/multi-currency/Analytics.php | 8 +++- ...class-wc-payments-customer-service-api.php | 6 +-- .../multi-currency/test-class-analytics.php | 44 +++---------------- ...est-class-wc-payments-customer-service.php | 21 ++++----- 8 files changed, 54 insertions(+), 58 deletions(-) create mode 100644 changelog/fix-8678-use-legacy-approach-off-session create mode 100644 changelog/remove-deprecated-param-from-asset-data-registry diff --git a/changelog/fix-8678-use-legacy-approach-off-session b/changelog/fix-8678-use-legacy-approach-off-session new file mode 100644 index 00000000000..1de8751d094 --- /dev/null +++ b/changelog/fix-8678-use-legacy-approach-off-session @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Bugfix for failing subscription renewal payments. diff --git a/changelog/remove-deprecated-param-from-asset-data-registry b/changelog/remove-deprecated-param-from-asset-data-registry new file mode 100644 index 00000000000..a18738ea4b8 --- /dev/null +++ b/changelog/remove-deprecated-param-from-asset-data-registry @@ -0,0 +1,4 @@ +Significance: minor +Type: dev + +Remove deprecated param from asset data registry interface. diff --git a/includes/class-wc-payment-gateway-wcpay.php b/includes/class-wc-payment-gateway-wcpay.php index 0c728fb0ff9..d65b0ba70f5 100644 --- a/includes/class-wc-payment-gateway-wcpay.php +++ b/includes/class-wc-payment-gateway-wcpay.php @@ -1512,7 +1512,7 @@ public function process_payment_for_order( $cart, $payment_information, $schedul $request->set_cvc_confirmation( $payment_information->get_cvc_confirmation() ); $request->set_hook_args( $payment_information ); if ( $payment_information->is_using_saved_payment_method() ) { - $billing_details = WC_Payments_Utils::get_billing_details_from_order( $order ); + $billing_details = WC_Payments_Utils::get_billing_details_from_order( $order, $payment_information->is_merchant_initiated() ); $is_legacy_card_object = strpos( $payment_information->get_payment_method() ?? '', 'card_' ) === 0; diff --git a/includes/class-wc-payments-utils.php b/includes/class-wc-payments-utils.php index 62efd5ecfc9..30507c07816 100644 --- a/includes/class-wc-payments-utils.php +++ b/includes/class-wc-payments-utils.php @@ -342,10 +342,31 @@ public static function map_search_orders_to_charge_ids( $search ) { * It only returns the fields that are present in the billing section of the checkout. * * @param WC_Order $order Order to extract the billing details from. + * @param bool $legacy Whether to use the legacy way of loading straight from the order. + * @todo The $legacy flag is just a patch for the current approach, fixing the linked issue. + * @see https://github.com/Automattic/woocommerce-payments/issues/8678 * * @return array */ - public static function get_billing_details_from_order( $order ) { + public static function get_billing_details_from_order( $order, $legacy = true ) { + if ( $legacy ) { + $billing_details = [ + 'address' => [ + 'city' => $order->get_billing_city(), + 'country' => $order->get_billing_country(), + 'line1' => $order->get_billing_address_1(), + 'line2' => $order->get_billing_address_2(), + 'postal_code' => $order->get_billing_postcode(), + 'state' => $order->get_billing_state(), + ], + 'email' => $order->get_billing_email(), + 'name' => trim( $order->get_formatted_billing_full_name() ), + 'phone' => $order->get_billing_phone(), + ]; + + return array_filter( $billing_details ); + } + $billing_fields = array_keys( WC()->checkout()->get_checkout_fields( 'billing' ) ); $address_field_to_key = [ 'billing_city' => 'city', diff --git a/includes/multi-currency/Analytics.php b/includes/multi-currency/Analytics.php index d2c05dbd2df..ef3f5b17a5a 100644 --- a/includes/multi-currency/Analytics.php +++ b/includes/multi-currency/Analytics.php @@ -114,6 +114,11 @@ public function register_admin_scripts() { * @return void */ public function register_customer_currencies() { + $data_registry = Package::container()->get( AssetDataRegistry::class ); + if ( $data_registry->exists( 'customerCurrencies' ) ) { + return; + } + $currencies = $this->multi_currency->get_all_customer_currencies(); $available_currencies = $this->multi_currency->get_available_currencies(); $currency_options = []; @@ -137,8 +142,7 @@ public function register_customer_currencies() { ]; } - $data_registry = Package::container()->get( AssetDataRegistry::class ); - $data_registry->add( 'customerCurrencies', $currency_options, true ); + $data_registry->add( 'customerCurrencies', $currency_options ); } /** diff --git a/tests/unit/core/service/test-class-wc-payments-customer-service-api.php b/tests/unit/core/service/test-class-wc-payments-customer-service-api.php index b2f3a12a44b..4128eeabe78 100644 --- a/tests/unit/core/service/test-class-wc-payments-customer-service-api.php +++ b/tests/unit/core/service/test-class-wc-payments-customer-service-api.php @@ -339,16 +339,16 @@ function ( $data ): bool { 'test_mode' => false, 'billing_details' => [ 'address' => [ + 'city' => $order->get_billing_city(), 'country' => $order->get_billing_country(), 'line1' => $order->get_billing_address_1(), 'line2' => $order->get_billing_address_2(), - 'city' => $order->get_billing_city(), - 'state' => $order->get_billing_state(), 'postal_code' => $order->get_billing_postcode(), + 'state' => $order->get_billing_state(), ], - 'phone' => $order->get_billing_phone(), 'email' => $order->get_billing_email(), 'name' => $order->get_billing_first_name() . ' ' . $order->get_billing_last_name(), + 'phone' => $order->get_billing_phone(), ], ] ), diff --git a/tests/unit/multi-currency/test-class-analytics.php b/tests/unit/multi-currency/test-class-analytics.php index 75da9abafac..15fa5fd3f3a 100644 --- a/tests/unit/multi-currency/test-class-analytics.php +++ b/tests/unit/multi-currency/test-class-analytics.php @@ -109,28 +109,18 @@ public function woocommerce_filter_provider() { ]; } + /** + * Test for the register_customer_currencies method. Note that this function is called in the constructor, + * and the customerCurrencies data key cannot be re-registered, so this test is only to ensure that it exists. + */ public function test_register_customer_currencies() { - $this->mock_multi_currency->expects( $this->once() ) - ->method( 'get_all_customer_currencies' ) - ->willReturn( $this->mock_customer_currencies ); - - $this->mock_multi_currency->expects( $this->once() ) - ->method( 'get_available_currencies' ) - ->willReturn( $this->get_mock_available_currencies() ); - - $this->mock_multi_currency->expects( $this->once() ) - ->method( 'get_default_currency' ) - ->willReturn( new Currency( 'USD', 1.0 ) ); - - $this->analytics->register_customer_currencies(); - $data_registry = Package::container()->get( AssetDataRegistry::class ); - $this->assertTrue( $data_registry->exists( 'customerCurrencies' ) ); } + public function test_has_multi_currency_orders() { // Use reflection to make the private method has_multi_currency_orders accessible. @@ -143,30 +133,6 @@ public function test_has_multi_currency_orders() { $this->assertTrue( $result ); } - public function test_register_customer_currencies_for_empty_customer_currencies() { - delete_option( MultiCurrency::CUSTOMER_CURRENCIES_KEY ); - - $this->mock_multi_currency->expects( $this->once() ) - ->method( 'get_all_customer_currencies' ) - ->willReturn( [] ); - - $this->mock_multi_currency->expects( $this->once() ) - ->method( 'get_available_currencies' ) - ->willReturn( $this->get_mock_available_currencies() ); - - $this->mock_multi_currency->expects( $this->once() ) - ->method( 'get_default_currency' ) - ->willReturn( new Currency( 'USD', 1.0 ) ); - - $this->analytics->register_customer_currencies(); - - $data_registry = Package::container()->get( - AssetDataRegistry::class - ); - - $this->assertTrue( $data_registry->exists( 'customerCurrencies' ) ); - } - public function test_update_order_stats_data_with_non_multi_currency_order() { $args = $this->order_args_provider( 123, 0, 1, 15.50, 1.50, 0, 14.00 ); $order = wc_create_order(); diff --git a/tests/unit/test-class-wc-payments-customer-service.php b/tests/unit/test-class-wc-payments-customer-service.php index 1a478800cc0..29f19b47425 100644 --- a/tests/unit/test-class-wc-payments-customer-service.php +++ b/tests/unit/test-class-wc-payments-customer-service.php @@ -484,16 +484,16 @@ public function test_update_payment_method_with_billing_details_from_order() { [ 'billing_details' => [ 'address' => [ - 'city' => 'WooCity', 'country' => Country_Code::UNITED_STATES, 'line1' => 'WooAddress', 'line2' => '', - 'postal_code' => '12345', + 'city' => 'WooCity', 'state' => 'NY', + 'postal_code' => '12345', ], + 'phone' => '555-32123', 'email' => 'admin@example.org', 'name' => 'Jeroen Sormani', - 'phone' => '555-32123', ], ] ); @@ -504,15 +504,6 @@ public function test_update_payment_method_with_billing_details_from_order() { } public function test_update_payment_method_with_billing_details_from_checkout_fields() { - $fields = wc()->checkout()->checkout_fields; - unset( $fields['billing']['billing_company'] ); - unset( $fields['billing']['billing_country'] ); - unset( $fields['billing']['billing_address_1'] ); - unset( $fields['billing']['billing_address_2'] ); - unset( $fields['billing']['billing_city'] ); - unset( $fields['billing']['billing_state'] ); - unset( $fields['billing']['billing_phone'] ); - wc()->checkout()->checkout_fields = $fields; $this->mock_api_client ->expects( $this->once() ) ->method( 'update_payment_method' ) @@ -522,9 +513,15 @@ public function test_update_payment_method_with_billing_details_from_checkout_fi 'billing_details' => [ 'address' => [ 'postal_code' => '12345', + 'city' => 'WooCity', + 'country' => 'US', + 'line1' => 'WooAddress', + 'line2' => '', + 'state' => 'NY', ], 'email' => 'admin@example.org', 'name' => 'Jeroen Sormani', + 'phone' => '555-32123', ], ] ); From d7ee4fc4e7aff430b557b3eed150ce1bc98cdd73 Mon Sep 17 00:00:00 2001 From: botwoo Date: Mon, 22 Apr 2024 11:49:32 +0000 Subject: [PATCH 3/3] Amend changelog entries for release 7.5.2 --- changelog.txt | 2 ++ changelog/fix-8678-use-legacy-approach-off-session | 4 ---- changelog/remove-deprecated-param-from-asset-data-registry | 4 ---- readme.txt | 2 ++ 4 files changed, 4 insertions(+), 8 deletions(-) delete mode 100644 changelog/fix-8678-use-legacy-approach-off-session delete mode 100644 changelog/remove-deprecated-param-from-asset-data-registry diff --git a/changelog.txt b/changelog.txt index e6996419213..d616ef6443a 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,8 @@ *** WooPayments Changelog *** = 7.5.2 - 2024-04-22 = +* Fix - Bugfix for failing subscription renewal payments. +* Dev - Remove deprecated param from asset data registry interface. = 7.5.1 - 2024-04-18 = * Fix - Avoid updating billing details for legacy card objects. diff --git a/changelog/fix-8678-use-legacy-approach-off-session b/changelog/fix-8678-use-legacy-approach-off-session deleted file mode 100644 index 1de8751d094..00000000000 --- a/changelog/fix-8678-use-legacy-approach-off-session +++ /dev/null @@ -1,4 +0,0 @@ -Significance: patch -Type: fix - -Bugfix for failing subscription renewal payments. diff --git a/changelog/remove-deprecated-param-from-asset-data-registry b/changelog/remove-deprecated-param-from-asset-data-registry deleted file mode 100644 index a18738ea4b8..00000000000 --- a/changelog/remove-deprecated-param-from-asset-data-registry +++ /dev/null @@ -1,4 +0,0 @@ -Significance: minor -Type: dev - -Remove deprecated param from asset data registry interface. diff --git a/readme.txt b/readme.txt index 3533df1a030..aca266977d7 100644 --- a/readme.txt +++ b/readme.txt @@ -95,6 +95,8 @@ Please note that our support for the checkout block is still experimental and th == Changelog == = 7.5.2 - 2024-04-22 = +* Fix - Bugfix for failing subscription renewal payments. +* Dev - Remove deprecated param from asset data registry interface. = 7.5.1 - 2024-04-18 =