fix(onboarding): preserve BCDC state during branded-only mode upgrades (5897)#4104
Open
Narek13 wants to merge 3 commits intodev/developfrom
Open
fix(onboarding): preserve BCDC state during branded-only mode upgrades (5897)#4104Narek13 wants to merge 3 commits intodev/developfrom
Narek13 wants to merge 3 commits intodev/developfrom
Conversation
When upgrading from v3.4.0 with branded-only mode enabled, BCDC was being disabled even though merchants had it enabled. This occurred because: 1. Existing merchants had ACDC enabled in settings (but hidden from UI) 2. Calling PaymentSettings methods to disable ACDC triggered WooCommerce gateway initialization for all gateways 3. This initialization had side effects that modified BCDC state 4. BCDC's enabled state was lost before we could preserve it Solution: - Add action hook on 'woocommerce_paypal_payments_toggle_payment_gateways_apms' to prevent white-label methods from being enabled during new merchant onboarding in branded-only mode - For existing merchants: read BCDC state directly from WordPress options BEFORE any PaymentSettings calls that would trigger gateway initialization - Disable ACDC, then re-enable BCDC if it was previously enabled - This preserves BCDC state across upgrades
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue Description
When upgrading from v3.4.0 with branded-only mode enabled, BCDC (PayPal-branded card button) was being disabled even though merchants had it enabled. This violated the acceptance criteria that merchants' BCDC state should be preserved during upgrades.
Root Causes
For new merchants:
During onboarding,
toggle_payment_gateways()enables ACDC, Apple Pay, and Google Pay for business sellers without checking if branded-only mode is active. These white-label methods should never be enabled in branded-only mode.For existing merchants:
Previous versions had ACDC enabled in settings but hidden from the UI in branded-only mode. When disabling ACDC during the upgrade:
is_method_enabled(CreditCardGateway::ID)triggersWC()->payment_gateways()->payment_gateways()PR Description
Changes Made
1. Prevent white-label methods during onboarding (new merchants)
Added action hook on
woocommerce_paypal_payments_toggle_payment_gateways_apmsthat runs during the onboarding flow to immediately disable ACDC, Apple Pay, and Google Pay in branded-only mode. This prevents them from being enabled even temporarily.2. Preserve BCDC state during upgrades (existing merchants)
Read BCDC's enabled state directly from WordPress options (
woocommerce_ppcp-card-button-gateway_settings) BEFORE anyPaymentSettingsmethod calls that would trigger gateway initialization.This is critical because:
is_method_enabled()andtoggle_method_state()callWC()->payment_gateways()->payment_gateways()Technical Details
Gateway Initialization Side Effects
The
PaymentSettings::get_gateway()method callsWC()->payment_gateways()->payment_gateways()which initializes all WooCommerce payment gateways, not just the requested one. This initialization:init()methodsThis is why we must read BCDC state from raw WordPress options before making any
PaymentSettingscalls - to capture its true state before the initialization cycle corrupts it.Testing
Acceptance Criteria: