Skip to content

Commit f246621

Browse files
committed
Fix initial payment method list migration to PMC (#4351)
* Add param to force the migration * Force PMC migration for new installs, and on re-auth if pmc is not already enabled
1 parent 514ea97 commit f246621

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Update - Remove feature that flags 401s and proactively blocks subsequent API calls until the store has reauthenticated.
66
* Fix - Disable payment settings sync when we receive unsupported payment method configurations.
77
* Fix - Ensure that we use current Stripe API keys after settings updates
8+
* Fix - Fix initial enabled payment methods migration to the Stripe Payment Methods Configuration API
89

910
= 9.5.1 - 2025-05-17 =
1011
* Fix - Add a fetch cooldown to the payment method configuration retrieval endpoint to prevent excessive requests.

includes/class-wc-stripe-payment-method-configurations.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,19 @@ public static function is_enabled() {
348348

349349
/**
350350
* Migrates the payment methods from the DB option to PMC if needed.
351+
*
352+
* @param bool $force_migration Whether to force the migration.
351353
*/
352-
public static function maybe_migrate_payment_methods_from_db_to_pmc() {
354+
public static function maybe_migrate_payment_methods_from_db_to_pmc( $force_migration = false ) {
353355
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
354356

355-
// Skip if PMC is not enabled or migration already done (pmc_enabled is set).
356-
if ( ! self::is_enabled() || ! empty( $stripe_settings['pmc_enabled'] ) ) {
357+
// Skip if PMC is not enabled.
358+
if ( ! self::is_enabled() ) {
359+
return;
360+
}
361+
362+
// Skip if migration already done (pmc_enabled is set) and we are not forcing the migration.
363+
if ( ! empty( $stripe_settings['pmc_enabled'] ) && ! $force_migration ) {
357364
return;
358365
}
359366

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private function save_stripe_keys( $result, $type = 'connect', $mode = 'live' )
163163
$options[ $prefix . 'publishable_key' ] = $publishable_key;
164164
$options[ $prefix . 'secret_key' ] = $secret_key;
165165
$options[ $prefix . 'connection_type' ] = $type;
166-
$options['pmc_enabled'] = 'connect' === $type ? '' : 'no'; // When not connected via oauth, the PMC is disabled. Otherwise, set to empty string which will be set to 'yes' after the migration in 'maybe_migrate_payment_methods_from_db_to_pmc'.
166+
$options['pmc_enabled'] = 'connect' === $type ? 'yes' : 'no'; // When not connected via Connect OAuth, the PMC is disabled.
167167
if ( 'app' === $type ) {
168168
$options[ $prefix . 'refresh_token' ] = $result->refreshToken; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
169169
}
@@ -199,15 +199,15 @@ 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.
202+
// For new installs the legacy gateway gets instantiated because there is no settings in the DB yet,
203+
// so we need to instantiate the UPE gateway just for the PMC migration.
203204
$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 );
205+
if ( ! $gateway instanceof WC_Stripe_UPE_Payment_Gateway ) {
206+
$gateway = new WC_Stripe_UPE_Payment_Gateway();
207+
}
208+
// If pmc_enabled is not set (aka new install) or is not 'yes' (aka migration already done) we need to migrate the payment methods from the DB option to Stripe PMC API.
209+
if ( empty( $current_options ) || ! isset( $current_options['pmc_enabled'] ) || 'yes' !== $current_options['pmc_enabled'] ) {
210+
WC_Stripe_Payment_Method_Configurations::maybe_migrate_payment_methods_from_db_to_pmc( true );
211211
}
212212

213213
return $result;

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
115115
* Update - Remove feature that flags 401s and proactively blocks subsequent API calls until the store has reauthenticated.
116116
* Fix - Disable payment settings sync when we receive unsupported payment method configurations.
117117
* Fix - Ensure that we use current Stripe API keys after settings updates
118+
* Fix - Fix initial enabled payment methods migration to the Stripe Payment Methods Configuration API
118119

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

0 commit comments

Comments
 (0)