Skip to content

Commit 19b7d19

Browse files
annemirasolwjrosa
andauthored
Fix 'Invalid Configuration' error when disabling card (#4531)
* PMC: required card to be enabled before adding Apple Pay and Google Pay * Add unit tests * Add readme and changelog entries * Add comments --------- Co-authored-by: Wesley Rosa <[email protected]>
1 parent 154da40 commit 19b7d19

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* Fix - Prevent Stripe API calls after several consecutive 401 (Unauthorized) responses
2121
* Fix - 3DS authentication modal not shown when using Google Pay
2222
* Update - Improve Stripe API connector logging to include request/response context
23+
* Fix - Require credit cards to be enabled before Apple Pay and Google Pay can be enabled in PMC
2324

2425
= 9.7.0 - 2025-07-21 =
2526
* Update - Removes BNPL payment methods (Klarna and Affirm) when other official plugins are active

includes/admin/class-wc-rest-stripe-settings-controller.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,11 @@ private function get_payment_method_ids_to_enable( WP_REST_Request $request ) {
300300
$is_upe_enabled = $request->get_param( 'is_upe_enabled' );
301301
$is_payment_request_enabled = $request->get_param( 'is_payment_request_enabled' );
302302

303-
if ( $is_upe_enabled && $is_payment_request_enabled ) {
303+
// Card is required for Apple Pay and Google Pay.
304+
if ( $is_upe_enabled &&
305+
$is_payment_request_enabled &&
306+
in_array( WC_Stripe_Payment_Methods::CARD, $payment_method_ids_to_enable, true )
307+
) {
304308
$payment_method_ids_to_enable = array_merge(
305309
$payment_method_ids_to_enable,
306310
[ WC_Stripe_Payment_Methods::APPLE_PAY, WC_Stripe_Payment_Methods::GOOGLE_PAY ]

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
129129
* Fix - Prevent Stripe API calls after several consecutive 401 (Unauthorized) responses
130130
* Fix - 3DS authentication modal not shown when using Google Pay
131131
* Update - Improve Stripe API connector logging to include request/response context
132+
* Fix - Require credit cards to be enabled before Apple Pay and Google Pay can be enabled in PMC
132133

133134
[See changelog for full details across versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

tests/phpunit/Admin/WC_REST_Stripe_Settings_Controller_Test.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,61 @@ public function test_update_settings_fails_if_user_cannot_manage_woocommerce() {
376376
remove_filter( 'user_has_cap', $cb );
377377
}
378378

379+
/**
380+
* Tests that Apple Pay and Google Pay can be enabled in the PMC
381+
* when payment request is enabled, and card is enabled.
382+
*/
383+
public function test_update_settings_enables_apple_pay_google_pay() {
384+
// Before the update: card and CashApp are enabled, Apple Pay and Google Pay are disabled
385+
$this->mock_payment_method_configurations(
386+
[ WC_Stripe_Payment_Methods::CARD, WC_Stripe_Payment_Methods::CASHAPP_PAY ],
387+
[ WC_Stripe_Payment_Methods::APPLE_PAY, WC_Stripe_Payment_Methods::GOOGLE_PAY ]
388+
);
389+
390+
// After the update: card, Apple Pay, and Google Pay are enabled, CashApp is disabled
391+
$this->expect_payment_method_configurations_update(
392+
[ WC_Stripe_Payment_Methods::CARD, WC_Stripe_Payment_Methods::APPLE_PAY, WC_Stripe_Payment_Methods::GOOGLE_PAY ],
393+
[ WC_Stripe_Payment_Methods::CASHAPP_PAY ]
394+
);
395+
$request = new WP_REST_Request( 'POST', self::SETTINGS_ROUTE );
396+
// Disable CashApp, keep card enabled.
397+
$request->set_param( 'enabled_payment_method_ids', [ WC_Stripe_Payment_Methods::CARD ] );
398+
$request->set_param( 'is_upe_enabled', true );
399+
// Enable Apple Pay and Google Pay.
400+
$request->set_param( 'is_payment_request_enabled', true );
401+
402+
$response = $this->controller->update_settings( $request );
403+
$this->assertEquals( 200, $response->get_status() );
404+
}
405+
406+
/**
407+
* Tests that Apple Pay and Google Pay can only be enabled in the PMC
408+
* when payment request is enabled, and card is enabled.
409+
*/
410+
public function test_update_settings_enforces_apple_pay_google_pay_requires_card() {
411+
// Before the update: card, Apple Pay, and Google Pay are enabled, CashApp is disabled
412+
$this->mock_payment_method_configurations(
413+
[ WC_Stripe_Payment_Methods::CARD, WC_Stripe_Payment_Methods::APPLE_PAY, WC_Stripe_Payment_Methods::GOOGLE_PAY ],
414+
[ WC_Stripe_Payment_Methods::CASHAPP_PAY ]
415+
);
416+
417+
// After the update: CashApp is enabled, card, Apple Pay, and Google Pay are disabled
418+
$this->expect_payment_method_configurations_update(
419+
[ WC_Stripe_Payment_Methods::CASHAPP_PAY ],
420+
[ WC_Stripe_Payment_Methods::CARD, WC_Stripe_Payment_Methods::APPLE_PAY, WC_Stripe_Payment_Methods::GOOGLE_PAY ]
421+
);
422+
423+
$request = new WP_REST_Request( 'POST', self::SETTINGS_ROUTE );
424+
// Disable card, enable CashApp.
425+
$request->set_param( 'enabled_payment_method_ids', [ WC_Stripe_Payment_Methods::CASHAPP_PAY ] );
426+
$request->set_param( 'is_upe_enabled', true );
427+
// Enable Apple Pay and Google Pay -- this will be ignored because card is disabled
428+
$request->set_param( 'is_payment_request_enabled', true );
429+
430+
$response = $this->controller->update_settings( $request );
431+
$this->assertEquals( 200, $response->get_status() );
432+
}
433+
379434
/**
380435
* Tests for the dismiss notice endpoint.
381436
*

0 commit comments

Comments
 (0)