Skip to content

Commit 3ac1ded

Browse files
diegocurbeloMayisha
authored andcommitted
Settings Synchronization: Fix connect failing the first time (#4231)
* Revert dbcb9c5 changes to enable_upe/disable_upe * If we are already using the UPE gateway, update the PMC with the currently enabled payment methods * Do not update PMC payment methods when enabling Legacy checkout * Use the correct fillCreditCardDetailsShortcode helper for the new checkout * Append Apple Pay/Google Pay (payment_request === yes) to PMC enabled payment methods on connect
1 parent 748e6c1 commit 3ac1ded

File tree

6 files changed

+25
-27
lines changed

6 files changed

+25
-27
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ public function update_settings( WP_REST_Request $request ) {
296296

297297
/* Settings > Payments accepted on checkout + Express checkouts */
298298
$payment_method_ids_to_enable = $this->get_payment_method_ids_to_enable( $request );
299-
$is_upe_enabled = WC_Stripe_Feature_Flags::is_upe_checkout_enabled();
299+
$is_upe_enabled = $request->get_param( 'is_upe_enabled' );
300300
$this->update_enabled_payment_methods( $payment_method_ids_to_enable, $is_upe_enabled );
301-
if ( ! $is_upe_enabled || ! WC_Stripe_Payment_Method_Configurations::is_enabled() ) {
301+
if ( ! WC_Stripe_Feature_Flags::is_upe_checkout_enabled() || ! WC_Stripe_Payment_Method_Configurations::is_enabled() ) {
302302
// We need to update a separate setting for legacy checkout.
303303
$this->update_is_payment_request_enabled_for_legacy_checkout( $request );
304304
}

includes/connect/class-wc-stripe-connect.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ private function save_stripe_keys( $result, $type = 'connect', $mode = 'live' )
199199
return new WP_Error( 'wc_stripe_webhook_error', $e->getMessage() );
200200
}
201201

202+
// If we are already using the UPE gateway, update the PMC with the currently enabled payment methods.
203+
$gateway = WC_Stripe::get_instance()->get_main_stripe_gateway();
204+
if ( $gateway instanceof WC_Stripe_UPE_Payment_Gateway ) {
205+
// The UPE accepted payment list does not include Apple Pay/Google Pay, but PMC does, so we need to add them (if they are enabled).
206+
$enabled_payment_methods = array_merge(
207+
$options['upe_checkout_experience_accepted_payments'],
208+
$gateway->is_payment_request_enabled() ? [ WC_Stripe_Payment_Methods::APPLE_PAY, WC_Stripe_Payment_Methods::GOOGLE_PAY ] : []
209+
);
210+
$gateway->update_enabled_payment_methods( $enabled_payment_methods );
211+
}
212+
202213
return $result;
203214
}
204215

tests/e2e/tests/checkout/shortcode/pre-order-product.spec.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import config from 'config';
44
import { api, payments, products } from '../../../utils';
55
import { isPluginInstalled } from '../../../utils/plugin-utils';
66

7-
const {
8-
setupShortcodeCheckout,
9-
fillCreditCardDetailsShortcodeLegacy,
10-
} = payments;
7+
const { setupShortcodeCheckout, fillCreditCardDetailsShortcode } = payments;
118

129
let productId;
1310

@@ -44,10 +41,7 @@ test( 'customer can purchase a pre-order product @pre-orders', async ( {
4441
};
4542

4643
await setupShortcodeCheckout( page, customerData );
47-
await fillCreditCardDetailsShortcodeLegacy(
48-
page,
49-
config.get( 'cards.basic' )
50-
);
44+
await fillCreditCardDetailsShortcode( page, config.get( 'cards.basic' ) );
5145

5246
await page.locator( 'text="Place pre-order now"' ).click();
5347
await page.waitForURL( '**/checkout/order-received/**' );

tests/phpunit/test-wc-stripe-helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function test_get_legacy_enabled_payment_method_ids() {
179179

180180
$result = WC_Stripe_Helper::get_legacy_enabled_payment_method_ids();
181181
// In legacy mode (when UPE is disabled), Stripe refers to Card as payment method.
182-
$this->assertEquals( [ WC_Stripe_Payment_Methods::CARD, WC_Stripe_Payment_Methods::EPS, WC_Stripe_Payment_Methods::GIROPAY, WC_Stripe_Payment_Methods::P24 ], $result );
182+
$this->assertEquals( [ WC_Stripe_Payment_Methods::EPS, WC_Stripe_Payment_Methods::GIROPAY, WC_Stripe_Payment_Methods::P24 ], $result );
183183
}
184184

185185
public function test_get_legacy_individual_payment_method_settings() {

tests/phpunit/test-wc-stripe.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ public function test_turning_on_upe_with_no_stripe_legacy_payment_methods_enable
141141
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
142142
$this->assertEquals( 'no', $stripe_settings['enabled'] );
143143
$this->assertEquals( 'no', $stripe_settings['upe_checkout_experience_enabled'] );
144-
$this->mock_payment_method_configurations( [], [] );
145-
$this->expect_payment_method_configurations_update( [ WC_Stripe_Payment_Methods::CARD, WC_Stripe_Payment_Methods::LINK ], [] );
146144

147145
$stripe_settings['upe_checkout_experience_enabled'] = 'yes';
148146
WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings );
@@ -157,13 +155,9 @@ public function test_turning_on_upe_enables_the_correct_upe_methods_based_on_whi
157155
update_option( 'woocommerce_currency', 'EUR' );
158156
$this->upe_helper->enable_upe_feature_flag();
159157

160-
// Enable the EPS UPE method. Now when UPE is disabled, the EPS LPM should be enabled.
161-
$this->mock_payment_method_configurations( [ WC_Stripe_Payment_Methods::EPS, WC_Stripe_Payment_Methods::SEPA_DEBIT, WC_Stripe_Payment_Methods::IDEAL ] );
162-
163158
// Enable sepa and iDEAL LPM gateways.
164159
update_option( 'woocommerce_stripe_sepa_settings', [ 'enabled' => 'yes' ] );
165160
update_option( 'woocommerce_stripe_ideal_settings', [ 'enabled' => 'yes' ] );
166-
$this->expect_payment_method_configurations_update( [ WC_Stripe_Payment_Methods::SEPA_DEBIT, WC_Stripe_Payment_Methods::IDEAL ], [ WC_Stripe_Payment_Methods::CARD ] );
167161
$this->upe_helper->reload_payment_gateways();
168162

169163
// Initialize default stripe settings, turn on UPE.

woocommerce-gateway-stripe.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ protected function toggle_upe( $settings, $old_settings ) {
629629
}
630630

631631
protected function enable_upe( $settings ) {
632-
$payment_methods_to_enable = [];
632+
$settings['upe_checkout_experience_accepted_payments'] = [];
633633

634634
$payment_gateways = WC_Stripe_Helper::get_legacy_payment_methods();
635635
foreach ( WC_Stripe_UPE_Payment_Gateway::UPE_AVAILABLE_METHODS as $method_class ) {
@@ -655,24 +655,21 @@ protected function enable_upe( $settings ) {
655655
'yes'
656656
);
657657
// ENABLE UPE METHOD
658-
$payment_methods_to_enable[] = $method_class::STRIPE_ID;
658+
$settings['upe_checkout_experience_accepted_payments'][] = $method_class::STRIPE_ID;
659659
}
660660

661661
if ( 'stripe' === $lpm_gateway_id && isset( $this->stripe_gateway ) && $this->stripe_gateway->is_enabled() ) {
662-
$payment_methods_to_enable[] = 'card';
663-
$payment_methods_to_enable[] = 'link';
662+
$settings['upe_checkout_experience_accepted_payments'][] = 'card';
663+
$settings['upe_checkout_experience_accepted_payments'][] = 'link';
664664
}
665665
}
666-
if ( empty( $payment_methods_to_enable ) ) {
667-
$payment_methods_to_enable = [ 'card', 'link' ];
666+
if ( empty( $settings['upe_checkout_experience_accepted_payments'] ) ) {
667+
$settings['upe_checkout_experience_accepted_payments'] = [ 'card', 'link' ];
668668
} else {
669669
// The 'stripe' gateway must be enabled for UPE if any LPMs were enabled.
670670
$settings['enabled'] = 'yes';
671671
}
672672

673-
$upe_gateway = new WC_Stripe_UPE_Payment_Gateway();
674-
$upe_gateway->update_enabled_payment_methods( $payment_methods_to_enable );
675-
676673
return $settings;
677674
}
678675

@@ -701,7 +698,9 @@ protected function disable_upe( $settings ) {
701698
$settings['enabled'] = 'no';
702699
}
703700
// DISABLE ALL UPE METHODS
704-
$upe_gateway->update_enabled_payment_methods( [] );
701+
if ( ! isset( $settings['upe_checkout_experience_accepted_payments'] ) ) {
702+
$settings['upe_checkout_experience_accepted_payments'] = [];
703+
}
705704
return $settings;
706705
}
707706

0 commit comments

Comments
 (0)