Skip to content

Commit 174ea29

Browse files
RadoslavGeorgievtimur27Timur KarimovDaniel Mallorydmallory42
authored
Patch: Fix subscription renewals exceptions (#8683)
Co-authored-by: Timur Karimov <[email protected]> Co-authored-by: Timur Karimov <[email protected]> Co-authored-by: Daniel Mallory <[email protected]> Co-authored-by: Daniel Mallory <[email protected]>
1 parent da0a15c commit 174ea29

8 files changed

+54
-58
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fix
3+
4+
Bugfix for failing subscription renewal payments.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: dev
3+
4+
Remove deprecated param from asset data registry interface.

includes/class-wc-payment-gateway-wcpay.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ public function process_payment_for_order( $cart, $payment_information, $schedul
15121512
$request->set_cvc_confirmation( $payment_information->get_cvc_confirmation() );
15131513
$request->set_hook_args( $payment_information );
15141514
if ( $payment_information->is_using_saved_payment_method() ) {
1515-
$billing_details = WC_Payments_Utils::get_billing_details_from_order( $order );
1515+
$billing_details = WC_Payments_Utils::get_billing_details_from_order( $order, $payment_information->is_merchant_initiated() );
15161516

15171517
$is_legacy_card_object = strpos( $payment_information->get_payment_method() ?? '', 'card_' ) === 0;
15181518

includes/class-wc-payments-utils.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,31 @@ public static function map_search_orders_to_charge_ids( $search ) {
342342
* It only returns the fields that are present in the billing section of the checkout.
343343
*
344344
* @param WC_Order $order Order to extract the billing details from.
345+
* @param bool $legacy Whether to use the legacy way of loading straight from the order.
346+
* @todo The $legacy flag is just a patch for the current approach, fixing the linked issue.
347+
* @see https://github.com/Automattic/woocommerce-payments/issues/8678
345348
*
346349
* @return array
347350
*/
348-
public static function get_billing_details_from_order( $order ) {
351+
public static function get_billing_details_from_order( $order, $legacy = true ) {
352+
if ( $legacy ) {
353+
$billing_details = [
354+
'address' => [
355+
'city' => $order->get_billing_city(),
356+
'country' => $order->get_billing_country(),
357+
'line1' => $order->get_billing_address_1(),
358+
'line2' => $order->get_billing_address_2(),
359+
'postal_code' => $order->get_billing_postcode(),
360+
'state' => $order->get_billing_state(),
361+
],
362+
'email' => $order->get_billing_email(),
363+
'name' => trim( $order->get_formatted_billing_full_name() ),
364+
'phone' => $order->get_billing_phone(),
365+
];
366+
367+
return array_filter( $billing_details );
368+
}
369+
349370
$billing_fields = array_keys( WC()->checkout()->get_checkout_fields( 'billing' ) );
350371
$address_field_to_key = [
351372
'billing_city' => 'city',

includes/multi-currency/Analytics.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ public function register_admin_scripts() {
114114
* @return void
115115
*/
116116
public function register_customer_currencies() {
117+
$data_registry = Package::container()->get( AssetDataRegistry::class );
118+
if ( $data_registry->exists( 'customerCurrencies' ) ) {
119+
return;
120+
}
121+
117122
$currencies = $this->multi_currency->get_all_customer_currencies();
118123
$available_currencies = $this->multi_currency->get_available_currencies();
119124
$currency_options = [];
@@ -137,8 +142,7 @@ public function register_customer_currencies() {
137142
];
138143
}
139144

140-
$data_registry = Package::container()->get( AssetDataRegistry::class );
141-
$data_registry->add( 'customerCurrencies', $currency_options, true );
145+
$data_registry->add( 'customerCurrencies', $currency_options );
142146
}
143147

144148
/**

tests/unit/core/service/test-class-wc-payments-customer-service-api.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,16 +339,16 @@ function ( $data ): bool {
339339
'test_mode' => false,
340340
'billing_details' => [
341341
'address' => [
342+
'city' => $order->get_billing_city(),
342343
'country' => $order->get_billing_country(),
343344
'line1' => $order->get_billing_address_1(),
344345
'line2' => $order->get_billing_address_2(),
345-
'city' => $order->get_billing_city(),
346-
'state' => $order->get_billing_state(),
347346
'postal_code' => $order->get_billing_postcode(),
347+
'state' => $order->get_billing_state(),
348348
],
349-
'phone' => $order->get_billing_phone(),
350349
'email' => $order->get_billing_email(),
351350
'name' => $order->get_billing_first_name() . ' ' . $order->get_billing_last_name(),
351+
'phone' => $order->get_billing_phone(),
352352
],
353353
]
354354
),

tests/unit/multi-currency/test-class-analytics.php

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -109,28 +109,18 @@ public function woocommerce_filter_provider() {
109109
];
110110
}
111111

112+
/**
113+
* Test for the register_customer_currencies method. Note that this function is called in the constructor,
114+
* and the customerCurrencies data key cannot be re-registered, so this test is only to ensure that it exists.
115+
*/
112116
public function test_register_customer_currencies() {
113-
$this->mock_multi_currency->expects( $this->once() )
114-
->method( 'get_all_customer_currencies' )
115-
->willReturn( $this->mock_customer_currencies );
116-
117-
$this->mock_multi_currency->expects( $this->once() )
118-
->method( 'get_available_currencies' )
119-
->willReturn( $this->get_mock_available_currencies() );
120-
121-
$this->mock_multi_currency->expects( $this->once() )
122-
->method( 'get_default_currency' )
123-
->willReturn( new Currency( 'USD', 1.0 ) );
124-
125-
$this->analytics->register_customer_currencies();
126-
127117
$data_registry = Package::container()->get(
128118
AssetDataRegistry::class
129119
);
130-
131120
$this->assertTrue( $data_registry->exists( 'customerCurrencies' ) );
132121
}
133122

123+
134124
public function test_has_multi_currency_orders() {
135125

136126
// Use reflection to make the private method has_multi_currency_orders accessible.
@@ -143,30 +133,6 @@ public function test_has_multi_currency_orders() {
143133
$this->assertTrue( $result );
144134
}
145135

146-
public function test_register_customer_currencies_for_empty_customer_currencies() {
147-
delete_option( MultiCurrency::CUSTOMER_CURRENCIES_KEY );
148-
149-
$this->mock_multi_currency->expects( $this->once() )
150-
->method( 'get_all_customer_currencies' )
151-
->willReturn( [] );
152-
153-
$this->mock_multi_currency->expects( $this->once() )
154-
->method( 'get_available_currencies' )
155-
->willReturn( $this->get_mock_available_currencies() );
156-
157-
$this->mock_multi_currency->expects( $this->once() )
158-
->method( 'get_default_currency' )
159-
->willReturn( new Currency( 'USD', 1.0 ) );
160-
161-
$this->analytics->register_customer_currencies();
162-
163-
$data_registry = Package::container()->get(
164-
AssetDataRegistry::class
165-
);
166-
167-
$this->assertTrue( $data_registry->exists( 'customerCurrencies' ) );
168-
}
169-
170136
public function test_update_order_stats_data_with_non_multi_currency_order() {
171137
$args = $this->order_args_provider( 123, 0, 1, 15.50, 1.50, 0, 14.00 );
172138
$order = wc_create_order();

tests/unit/test-class-wc-payments-customer-service.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -484,16 +484,16 @@ public function test_update_payment_method_with_billing_details_from_order() {
484484
[
485485
'billing_details' => [
486486
'address' => [
487-
'city' => 'WooCity',
488487
'country' => Country_Code::UNITED_STATES,
489488
'line1' => 'WooAddress',
490489
'line2' => '',
491-
'postal_code' => '12345',
490+
'city' => 'WooCity',
492491
'state' => 'NY',
492+
'postal_code' => '12345',
493493
],
494+
'phone' => '555-32123',
494495
'email' => '[email protected]',
495496
'name' => 'Jeroen Sormani',
496-
'phone' => '555-32123',
497497
],
498498
]
499499
);
@@ -504,15 +504,6 @@ public function test_update_payment_method_with_billing_details_from_order() {
504504
}
505505

506506
public function test_update_payment_method_with_billing_details_from_checkout_fields() {
507-
$fields = wc()->checkout()->checkout_fields;
508-
unset( $fields['billing']['billing_company'] );
509-
unset( $fields['billing']['billing_country'] );
510-
unset( $fields['billing']['billing_address_1'] );
511-
unset( $fields['billing']['billing_address_2'] );
512-
unset( $fields['billing']['billing_city'] );
513-
unset( $fields['billing']['billing_state'] );
514-
unset( $fields['billing']['billing_phone'] );
515-
wc()->checkout()->checkout_fields = $fields;
516507
$this->mock_api_client
517508
->expects( $this->once() )
518509
->method( 'update_payment_method' )
@@ -522,9 +513,15 @@ public function test_update_payment_method_with_billing_details_from_checkout_fi
522513
'billing_details' => [
523514
'address' => [
524515
'postal_code' => '12345',
516+
'city' => 'WooCity',
517+
'country' => 'US',
518+
'line1' => 'WooAddress',
519+
'line2' => '',
520+
'state' => 'NY',
525521
],
526522
'email' => '[email protected]',
527523
'name' => 'Jeroen Sormani',
524+
'phone' => '555-32123',
528525
],
529526
]
530527
);

0 commit comments

Comments
 (0)