diff --git a/changelog/add-global-theme-support-flag b/changelog/add-global-theme-support-flag new file mode 100644 index 00000000000..6ec350a4c63 --- /dev/null +++ b/changelog/add-global-theme-support-flag @@ -0,0 +1,4 @@ +Significance: patch +Type: add + +Add WooPay global theme support flag diff --git a/client/checkout/api/index.js b/client/checkout/api/index.js index 485223aee74..c9b87c69f8d 100644 --- a/client/checkout/api/index.js +++ b/client/checkout/api/index.js @@ -465,7 +465,9 @@ export default class WCPayAPI { return this.request( buildAjaxURL( wcAjaxUrl, 'init_woopay' ), { _wpnonce: nonce, - appearance: getAppearance( appearanceType ), + appearance: getConfig( 'isWooPayGlobalThemeSupportEnabled' ) + ? getAppearance( appearanceType ) + : null, email: userEmail, user_session: woopayUserSession, order_id: getConfig( 'order_id' ), diff --git a/client/checkout/api/test/index.test.js b/client/checkout/api/test/index.test.js index c96f6679238..dd291f4f8a7 100644 --- a/client/checkout/api/test/index.test.js +++ b/client/checkout/api/test/index.test.js @@ -78,10 +78,10 @@ describe( 'WCPayAPI', () => { getConfig.mockImplementation( ( key ) => { const mockProperties = { initWooPayNonce: 'foo', - appearance: mockAppearance, order_id: 1, key: 'testkey', billing_email: 'test@example.com', + isWooPayGlobalThemeSupportEnabled: true, }; return mockProperties[ key ]; } ); @@ -114,4 +114,25 @@ describe( 'WCPayAPI', () => { foo: 'bar', } ); } ); + + test( 'WooPay should not support global theme styles', async () => { + buildAjaxURL.mockReturnValue( 'https://example.org/' ); + getConfig.mockImplementation( ( key ) => { + const mockProperties = { + initWooPayNonce: 'foo', + isWooPayGlobalThemeSupportEnabled: false, + }; + return mockProperties[ key ]; + } ); + + const api = new WCPayAPI( {}, request ); + await api.initWooPay( 'foo@bar.com', 'qwerty123' ); + + expect( request ).toHaveBeenLastCalledWith( 'https://example.org/', { + _wpnonce: 'foo', + appearance: null, + email: 'foo@bar.com', + user_session: 'qwerty123', + } ); + } ); } ); diff --git a/client/checkout/woopay/express-button/express-checkout-iframe.js b/client/checkout/woopay/express-button/express-checkout-iframe.js index 34d85396cdd..1abe335763a 100644 --- a/client/checkout/woopay/express-button/express-checkout-iframe.js +++ b/client/checkout/woopay/express-button/express-checkout-iframe.js @@ -109,7 +109,9 @@ export const expressCheckoutIframe = async ( api, context, emailSelector ) => { order_id: getConfig( 'order_id' ), key: getConfig( 'key' ), billing_email: getConfig( 'billing_email' ), - appearance: getAppearance( appearanceType ), + appearance: getConfig( 'isWooPayGlobalThemeSupportEnabled' ) + ? getAppearance( appearanceType ) + : null, } ).then( ( response ) => { if ( response?.data?.session ) { diff --git a/client/checkout/woopay/express-button/woopay-express-checkout-button.js b/client/checkout/woopay/express-button/woopay-express-checkout-button.js index 3c1a085d2f9..2b2e7931a9b 100644 --- a/client/checkout/woopay/express-button/woopay-express-checkout-button.js +++ b/client/checkout/woopay/express-button/woopay-express-checkout-button.js @@ -229,7 +229,11 @@ export const WoopayExpressCheckoutButton = ( { } WooPayFirstPartyAuth.getWooPaySessionFromMerchant( { _ajax_nonce: getConfig( 'woopaySessionNonce' ), - appearance: getAppearance( appearanceType ), + appearance: getConfig( + 'isWooPayGlobalThemeSupportEnabled' + ) + ? getAppearance( appearanceType ) + : null, } ) .then( async ( response ) => { if ( @@ -273,7 +277,9 @@ export const WoopayExpressCheckoutButton = ( { order_id: getConfig( 'order_id' ), key: getConfig( 'key' ), billing_email: getConfig( 'billing_email' ), - appearance: getAppearance( appearanceType ), + appearance: getConfig( 'isWooPayGlobalThemeSupportEnabled' ) + ? getAppearance( appearanceType ) + : null, } ) .then( async ( response ) => { if ( response?.blog_id && response?.data?.session ) { diff --git a/client/data/settings/actions.js b/client/data/settings/actions.js index 38928efff38..6a2e315657c 100644 --- a/client/data/settings/actions.js +++ b/client/data/settings/actions.js @@ -258,6 +258,12 @@ export function updateIsWooPayEnabled( isEnabled ) { return updateSettingsValues( { is_woopay_enabled: isEnabled } ); } +export function updateIsWooPayGlobalThemeSupportEnabled( isEnabled ) { + return updateSettingsValues( { + is_woopay_global_theme_support_enabled: isEnabled, + } ); +} + export function updateWooPayCustomMessage( message ) { return updateSettingsValues( { woopay_custom_message: message, diff --git a/client/data/settings/hooks.js b/client/data/settings/hooks.js index aef3408fbcd..8dca41224e6 100644 --- a/client/data/settings/hooks.js +++ b/client/data/settings/hooks.js @@ -418,6 +418,21 @@ export const useWooPayEnabledSettings = () => { return [ isWooPayEnabled, updateIsWooPayEnabled ]; }; +export const useWooPayGlobalThemeSupportEnabledSettings = () => { + const { updateIsWooPayGlobalThemeSupportEnabled } = useDispatch( + STORE_NAME + ); + + const isWooPayGlobalThemeSupportEnabled = useSelect( ( select ) => + select( STORE_NAME ).getIsWooPayGlobalThemeSupportEnabled() + ); + + return [ + isWooPayGlobalThemeSupportEnabled, + updateIsWooPayGlobalThemeSupportEnabled, + ]; +}; + export const useWooPayCustomMessage = () => { const { updateWooPayCustomMessage } = useDispatch( STORE_NAME ); diff --git a/client/data/settings/selectors.js b/client/data/settings/selectors.js index 5de61c53123..912f67606d6 100644 --- a/client/data/settings/selectors.js +++ b/client/data/settings/selectors.js @@ -223,6 +223,10 @@ export const getIsWooPayEnabled = ( state ) => { return getSettings( state ).is_woopay_enabled || false; }; +export const getIsWooPayGlobalThemeSupportEnabled = ( state ) => { + return getSettings( state ).is_woopay_global_theme_support_enabled || false; +}; + export const getWooPayCustomMessage = ( state ) => { return getSettings( state ).woopay_custom_message || ''; }; diff --git a/client/settings/express-checkout-settings/general-payment-request-button-settings.js b/client/settings/express-checkout-settings/general-payment-request-button-settings.js index 296a09b08b0..9154cf7fcde 100644 --- a/client/settings/express-checkout-settings/general-payment-request-button-settings.js +++ b/client/settings/express-checkout-settings/general-payment-request-button-settings.js @@ -7,6 +7,7 @@ import { __, sprintf } from '@wordpress/i18n'; import { // eslint-disable-next-line @wordpress/no-unsafe-wp-apis __experimentalNumberControl as NumberControl, + CheckboxControl, SelectControl, RadioControl, RangeControl, @@ -31,6 +32,7 @@ import { usePaymentRequestButtonBorderRadius, usePaymentRequestEnabledSettings, useWooPayEnabledSettings, + useWooPayGlobalThemeSupportEnabledSettings, } from 'wcpay/data'; const makeButtonSizeText = ( string ) => @@ -165,6 +167,11 @@ const GeneralPaymentRequestButtonSettings = ( { type } ) => { isPaymentRequestEnabled && isWooPayFeatureFlagEnabled; + const [ + isWooPayGlobalThemeSupportEnabled, + updateIsWooPayGlobalThemeSupportEnabled, + ] = useWooPayGlobalThemeSupportEnabledSettings(); + return ( { showWarning && ( @@ -260,6 +267,30 @@ const GeneralPaymentRequestButtonSettings = ( { type } ) => {

) } + { wcpaySettings.isWooPayGlobalThemeSupportEligible && + type === 'woopay' && ( + <> +

+ { __( + 'WooPay Global Theme Support', + 'woocommerce-payments' + ) } +

+
+ +
+ + ) }

{ __( 'Preview', 'woocommerce-payments' ) }

{ __( diff --git a/client/settings/express-checkout-settings/test/index.js b/client/settings/express-checkout-settings/test/index.js index 78a8101a5b7..84a71acda60 100644 --- a/client/settings/express-checkout-settings/test/index.js +++ b/client/settings/express-checkout-settings/test/index.js @@ -27,6 +27,9 @@ jest.mock( '../../../data', () => ( { usePaymentRequestButtonSize: jest.fn().mockReturnValue( [ 'small' ] ), usePaymentRequestButtonTheme: jest.fn().mockReturnValue( [ 'dark' ] ), usePaymentRequestButtonBorderRadius: jest.fn().mockReturnValue( [ 4 ] ), + useWooPayGlobalThemeSupportEnabledSettings: jest + .fn() + .mockReturnValue( [ false, jest.fn() ] ), useWooPayLocations: jest .fn() .mockReturnValue( [ [ true, true, true ], jest.fn() ] ), diff --git a/client/settings/express-checkout-settings/test/payment-request-settings.test.js b/client/settings/express-checkout-settings/test/payment-request-settings.test.js index 95c7efd1792..b3746b1964c 100644 --- a/client/settings/express-checkout-settings/test/payment-request-settings.test.js +++ b/client/settings/express-checkout-settings/test/payment-request-settings.test.js @@ -31,6 +31,9 @@ jest.mock( '../../../data', () => ( { useWooPayEnabledSettings: jest.fn(), useExpressCheckoutShowIncompatibilityNotice: jest.fn(), useWooPayShowIncompatibilityNotice: jest.fn().mockReturnValue( false ), + useWooPayGlobalThemeSupportEnabledSettings: jest + .fn() + .mockReturnValue( [ false, jest.fn() ] ), } ) ); jest.mock( '../payment-request-button-preview' ); diff --git a/includes/admin/class-wc-payments-admin.php b/includes/admin/class-wc-payments-admin.php index c213c03bd42..018b5d6e1d8 100644 --- a/includes/admin/class-wc-payments-admin.php +++ b/includes/admin/class-wc-payments-admin.php @@ -898,6 +898,7 @@ private function get_js_settings(): array { 'trackingInfo' => $this->account->get_tracking_info(), 'lifetimeTPV' => $this->account->get_lifetime_total_payment_volume(), 'defaultExpressCheckoutBorderRadius' => WC_Payments_Express_Checkout_Button_Handler::DEFAULT_BORDER_RADIUS_IN_PX, + 'isWooPayGlobalThemeSupportEligible' => WC_Payments_Features::is_woopay_global_theme_support_eligible(), ]; return apply_filters( 'wcpay_js_settings', $this->wcpay_js_settings ); diff --git a/includes/admin/class-wc-rest-payments-settings-controller.php b/includes/admin/class-wc-rest-payments-settings-controller.php index 7d96afbeaf5..314faad586f 100644 --- a/includes/admin/class-wc-rest-payments-settings-controller.php +++ b/includes/admin/class-wc-rest-payments-settings-controller.php @@ -474,61 +474,62 @@ public function get_settings(): WP_REST_Response { return new WP_REST_Response( [ - 'enabled_payment_method_ids' => $enabled_payment_methods, - 'available_payment_method_ids' => $available_upe_payment_methods, - 'payment_method_statuses' => $this->wcpay_gateway->get_upe_enabled_payment_method_statuses(), - 'duplicated_payment_method_ids' => $this->wcpay_gateway->find_duplicates(), - 'is_wcpay_enabled' => $this->wcpay_gateway->is_enabled(), - 'is_manual_capture_enabled' => 'yes' === $this->wcpay_gateway->get_option( 'manual_capture' ), - 'is_test_mode_enabled' => WC_Payments::mode()->is_test(), - 'is_dev_mode_enabled' => WC_Payments::mode()->is_dev(), - 'is_multi_currency_enabled' => WC_Payments_Features::is_customer_multi_currency_enabled(), - 'is_wcpay_subscriptions_enabled' => WC_Payments_Features::is_wcpay_subscriptions_enabled(), - 'is_stripe_billing_enabled' => WC_Payments_Features::is_stripe_billing_enabled(), - 'is_wcpay_subscriptions_eligible' => WC_Payments_Features::is_wcpay_subscriptions_eligible(), - 'is_subscriptions_plugin_active' => $this->wcpay_gateway->is_subscriptions_plugin_active(), - 'account_country' => $this->wcpay_gateway->get_option( 'account_country' ), - 'account_statement_descriptor' => $this->wcpay_gateway->get_option( 'account_statement_descriptor' ), - 'account_statement_descriptor_kanji' => $this->wcpay_gateway->get_option( 'account_statement_descriptor_kanji' ), - 'account_statement_descriptor_kana' => $this->wcpay_gateway->get_option( 'account_statement_descriptor_kana' ), - 'account_business_name' => $this->wcpay_gateway->get_option( 'account_business_name' ), - 'account_business_url' => $this->wcpay_gateway->get_option( 'account_business_url' ), - 'account_business_support_address' => $this->wcpay_gateway->get_option( 'account_business_support_address' ), - 'account_business_support_email' => $this->wcpay_gateway->get_option( 'account_business_support_email' ), - 'account_business_support_phone' => $this->wcpay_gateway->get_option( 'account_business_support_phone' ), - 'account_branding_logo' => $this->wcpay_gateway->get_option( 'account_branding_logo' ), - 'account_branding_icon' => $this->wcpay_gateway->get_option( 'account_branding_icon' ), - 'account_branding_primary_color' => $this->wcpay_gateway->get_option( 'account_branding_primary_color' ), - 'account_branding_secondary_color' => $this->wcpay_gateway->get_option( 'account_branding_secondary_color' ), - 'account_domestic_currency' => $this->wcpay_gateway->get_option( 'account_domestic_currency' ), - 'is_payment_request_enabled' => 'yes' === $this->wcpay_gateway->get_option( 'payment_request' ), - 'is_debug_log_enabled' => 'yes' === $this->wcpay_gateway->get_option( 'enable_logging' ), - 'payment_request_enabled_locations' => $this->wcpay_gateway->get_option( 'payment_request_button_locations' ), - 'payment_request_button_size' => $this->wcpay_gateway->get_option( 'payment_request_button_size' ), - 'payment_request_button_type' => $this->wcpay_gateway->get_option( 'payment_request_button_type' ), - 'payment_request_button_theme' => $this->wcpay_gateway->get_option( 'payment_request_button_theme' ), - 'payment_request_button_border_radius' => WC_Payments_Features::is_stripe_ece_enabled() ? $this->wcpay_gateway->get_option( 'payment_request_button_border_radius', WC_Payments_Express_Checkout_Button_Handler::DEFAULT_BORDER_RADIUS_IN_PX ) : WC_Payments_Express_Checkout_Button_Handler::DEFAULT_BORDER_RADIUS_IN_PX, - 'is_saved_cards_enabled' => $this->wcpay_gateway->is_saved_cards_enabled(), - 'is_card_present_eligible' => $this->wcpay_gateway->is_card_present_eligible() && isset( WC()->payment_gateways()->get_available_payment_gateways()['cod'] ), - 'is_woopay_enabled' => 'yes' === $this->wcpay_gateway->get_option( 'platform_checkout' ), - 'show_woopay_incompatibility_notice' => get_option( 'woopay_invalid_extension_found', false ), + 'enabled_payment_method_ids' => $enabled_payment_methods, + 'available_payment_method_ids' => $available_upe_payment_methods, + 'payment_method_statuses' => $this->wcpay_gateway->get_upe_enabled_payment_method_statuses(), + 'duplicated_payment_method_ids' => $this->wcpay_gateway->find_duplicates(), + 'is_wcpay_enabled' => $this->wcpay_gateway->is_enabled(), + 'is_manual_capture_enabled' => 'yes' === $this->wcpay_gateway->get_option( 'manual_capture' ), + 'is_test_mode_enabled' => WC_Payments::mode()->is_test(), + 'is_dev_mode_enabled' => WC_Payments::mode()->is_dev(), + 'is_multi_currency_enabled' => WC_Payments_Features::is_customer_multi_currency_enabled(), + 'is_wcpay_subscriptions_enabled' => WC_Payments_Features::is_wcpay_subscriptions_enabled(), + 'is_stripe_billing_enabled' => WC_Payments_Features::is_stripe_billing_enabled(), + 'is_wcpay_subscriptions_eligible' => WC_Payments_Features::is_wcpay_subscriptions_eligible(), + 'is_subscriptions_plugin_active' => $this->wcpay_gateway->is_subscriptions_plugin_active(), + 'is_woopay_global_theme_support_enabled' => $this->wcpay_gateway->is_woopay_global_theme_support_enabled(), + 'account_country' => $this->wcpay_gateway->get_option( 'account_country' ), + 'account_statement_descriptor' => $this->wcpay_gateway->get_option( 'account_statement_descriptor' ), + 'account_statement_descriptor_kanji' => $this->wcpay_gateway->get_option( 'account_statement_descriptor_kanji' ), + 'account_statement_descriptor_kana' => $this->wcpay_gateway->get_option( 'account_statement_descriptor_kana' ), + 'account_business_name' => $this->wcpay_gateway->get_option( 'account_business_name' ), + 'account_business_url' => $this->wcpay_gateway->get_option( 'account_business_url' ), + 'account_business_support_address' => $this->wcpay_gateway->get_option( 'account_business_support_address' ), + 'account_business_support_email' => $this->wcpay_gateway->get_option( 'account_business_support_email' ), + 'account_business_support_phone' => $this->wcpay_gateway->get_option( 'account_business_support_phone' ), + 'account_branding_logo' => $this->wcpay_gateway->get_option( 'account_branding_logo' ), + 'account_branding_icon' => $this->wcpay_gateway->get_option( 'account_branding_icon' ), + 'account_branding_primary_color' => $this->wcpay_gateway->get_option( 'account_branding_primary_color' ), + 'account_branding_secondary_color' => $this->wcpay_gateway->get_option( 'account_branding_secondary_color' ), + 'account_domestic_currency' => $this->wcpay_gateway->get_option( 'account_domestic_currency' ), + 'is_payment_request_enabled' => 'yes' === $this->wcpay_gateway->get_option( 'payment_request' ), + 'is_debug_log_enabled' => 'yes' === $this->wcpay_gateway->get_option( 'enable_logging' ), + 'payment_request_enabled_locations' => $this->wcpay_gateway->get_option( 'payment_request_button_locations' ), + 'payment_request_button_size' => $this->wcpay_gateway->get_option( 'payment_request_button_size' ), + 'payment_request_button_type' => $this->wcpay_gateway->get_option( 'payment_request_button_type' ), + 'payment_request_button_theme' => $this->wcpay_gateway->get_option( 'payment_request_button_theme' ), + 'payment_request_button_border_radius' => WC_Payments_Features::is_stripe_ece_enabled() ? $this->wcpay_gateway->get_option( 'payment_request_button_border_radius', WC_Payments_Express_Checkout_Button_Handler::DEFAULT_BORDER_RADIUS_IN_PX ) : WC_Payments_Express_Checkout_Button_Handler::DEFAULT_BORDER_RADIUS_IN_PX, + 'is_saved_cards_enabled' => $this->wcpay_gateway->is_saved_cards_enabled(), + 'is_card_present_eligible' => $this->wcpay_gateway->is_card_present_eligible() && isset( WC()->payment_gateways()->get_available_payment_gateways()['cod'] ), + 'is_woopay_enabled' => 'yes' === $this->wcpay_gateway->get_option( 'platform_checkout' ), + 'show_woopay_incompatibility_notice' => get_option( 'woopay_invalid_extension_found', false ), 'show_express_checkout_incompatibility_notice' => $this->should_show_express_checkout_incompatibility_notice(), - 'woopay_custom_message' => $this->wcpay_gateway->get_option( 'platform_checkout_custom_message' ), - 'woopay_store_logo' => $this->wcpay_gateway->get_option( 'platform_checkout_store_logo' ), - 'woopay_enabled_locations' => $this->wcpay_gateway->get_option( 'platform_checkout_button_locations', array_keys( $wcpay_form_fields['payment_request_button_locations']['options'] ) ), - 'deposit_schedule_interval' => $this->wcpay_gateway->get_option( 'deposit_schedule_interval' ), - 'deposit_schedule_monthly_anchor' => $this->wcpay_gateway->get_option( 'deposit_schedule_monthly_anchor' ), - 'deposit_schedule_weekly_anchor' => $this->wcpay_gateway->get_option( 'deposit_schedule_weekly_anchor' ), - 'deposit_delay_days' => $this->wcpay_gateway->get_option( 'deposit_delay_days' ), - 'deposit_status' => $this->wcpay_gateway->get_option( 'deposit_status' ), - 'deposit_restrictions' => $this->wcpay_gateway->get_option( 'deposit_restrictions' ), - 'deposit_completed_waiting_period' => $this->wcpay_gateway->get_option( 'deposit_completed_waiting_period' ), - 'reporting_export_language' => $this->wcpay_gateway->get_option( 'reporting_export_language' ), - 'current_protection_level' => $this->wcpay_gateway->get_option( 'current_protection_level' ), - 'advanced_fraud_protection_settings' => $this->wcpay_gateway->get_option( 'advanced_fraud_protection_settings' ), - 'is_migrating_stripe_billing' => $is_migrating_stripe_billing ?? false, - 'stripe_billing_subscription_count' => $stripe_billing_subscription_count ?? 0, - 'stripe_billing_migrated_count' => $stripe_billing_migrated_count ?? 0, + 'woopay_custom_message' => $this->wcpay_gateway->get_option( 'platform_checkout_custom_message' ), + 'woopay_store_logo' => $this->wcpay_gateway->get_option( 'platform_checkout_store_logo' ), + 'woopay_enabled_locations' => $this->wcpay_gateway->get_option( 'platform_checkout_button_locations', array_keys( $wcpay_form_fields['payment_request_button_locations']['options'] ) ), + 'deposit_schedule_interval' => $this->wcpay_gateway->get_option( 'deposit_schedule_interval' ), + 'deposit_schedule_monthly_anchor' => $this->wcpay_gateway->get_option( 'deposit_schedule_monthly_anchor' ), + 'deposit_schedule_weekly_anchor' => $this->wcpay_gateway->get_option( 'deposit_schedule_weekly_anchor' ), + 'deposit_delay_days' => $this->wcpay_gateway->get_option( 'deposit_delay_days' ), + 'deposit_status' => $this->wcpay_gateway->get_option( 'deposit_status' ), + 'deposit_restrictions' => $this->wcpay_gateway->get_option( 'deposit_restrictions' ), + 'deposit_completed_waiting_period' => $this->wcpay_gateway->get_option( 'deposit_completed_waiting_period' ), + 'reporting_export_language' => $this->wcpay_gateway->get_option( 'reporting_export_language' ), + 'current_protection_level' => $this->wcpay_gateway->get_option( 'current_protection_level' ), + 'advanced_fraud_protection_settings' => $this->wcpay_gateway->get_option( 'advanced_fraud_protection_settings' ), + 'is_migrating_stripe_billing' => $is_migrating_stripe_billing ?? false, + 'stripe_billing_subscription_count' => $stripe_billing_subscription_count ?? 0, + 'stripe_billing_migrated_count' => $stripe_billing_migrated_count ?? 0, ] ); } @@ -551,6 +552,7 @@ public function update_settings( WP_REST_Request $request ) { $this->update_payment_request_appearance( $request ); $this->update_is_saved_cards_enabled( $request ); $this->update_is_woopay_enabled( $request ); + $this->update_is_woopay_global_theme_support_enabled( $request ); $this->update_reporting_export_language( $request ); $this->update_woopay_store_logo( $request ); $this->update_woopay_custom_message( $request ); @@ -873,6 +875,21 @@ private function update_is_woopay_enabled( WP_REST_Request $request ) { $this->wcpay_gateway->update_is_woopay_enabled( $is_woopay_enabled ); } + /** + * Updates the WooPay Global Theme Support enable/disable settings. + * + * @param WP_REST_Request $request Request object. + */ + private function update_is_woopay_global_theme_support_enabled( WP_REST_Request $request ) { + if ( ! $request->has_param( 'is_woopay_global_theme_support_enabled' ) ) { + return; + } + + $value = $request->get_param( 'is_woopay_global_theme_support_enabled' ); + + $this->wcpay_gateway->update_is_woopay_global_theme_support_enabled( $value ); + } + /** * Updates the custom message that will appear for woopay customers. * diff --git a/includes/class-wc-payment-gateway-wcpay.php b/includes/class-wc-payment-gateway-wcpay.php index 41c4f101719..c46a9b70e62 100644 --- a/includes/class-wc-payment-gateway-wcpay.php +++ b/includes/class-wc-payment-gateway-wcpay.php @@ -2546,6 +2546,34 @@ public function update_is_woopay_enabled( $is_woopay_enabled ) { } } + /** + * Updates whether woopay global theme support is enabled or disabled. + * + * @param bool $value Whether woopay global theme support should be enabled. + */ + public function update_is_woopay_global_theme_support_enabled( $value ) { + $current_value = 'yes' === $this->get_option( 'is_woopay_global_theme_support_enabled', 'no' ); + + if ( $value !== $current_value ) { + WC_Payments::woopay_tracker()->maybe_record_admin_event( + $value ? 'woopay_global_theme_support_enabled' : 'woopay_global_theme_support_disabled', + [ 'test_mode' => WC_Payments::mode()->is_test() ? 1 : 0 ] + ); + + $this->update_option( 'is_woopay_global_theme_support_enabled', $value ? 'yes' : 'no' ); + } + } + + + /** + * Checks whether the WooPay global theme support is enabled. + * + * @return bool The result. + */ + public function is_woopay_global_theme_support_enabled() { + return WC_Payments_Features::is_woopay_global_theme_support_eligible() && 'yes' === $this->get_option( 'is_woopay_global_theme_support_enabled' ); + } + /** * Init settings for gateways. */ diff --git a/includes/class-wc-payments-checkout.php b/includes/class-wc-payments-checkout.php index 5f86d639727..f2fcbcf5a23 100644 --- a/includes/class-wc-payments-checkout.php +++ b/includes/class-wc-payments-checkout.php @@ -177,37 +177,38 @@ public function get_payment_fields_js_config() { $gateway = WC_Payments::get_gateway() ?? $this->gateway; $js_config = [ - 'publishableKey' => $this->account->get_publishable_key( WC_Payments::mode()->is_test() ), - 'testMode' => WC_Payments::mode()->is_test(), - 'accountId' => $this->account->get_stripe_account_id(), - 'ajaxUrl' => admin_url( 'admin-ajax.php' ), - 'wcAjaxUrl' => WC_AJAX::get_endpoint( '%%endpoint%%' ), - 'createSetupIntentNonce' => wp_create_nonce( 'wcpay_create_setup_intent_nonce' ), - 'initWooPayNonce' => wp_create_nonce( 'wcpay_init_woopay_nonce' ), - 'saveUPEAppearanceNonce' => wp_create_nonce( 'wcpay_save_upe_appearance_nonce' ), - 'genericErrorMessage' => __( 'There was a problem processing the payment. Please check your email inbox and refresh the page to try again.', 'woocommerce-payments' ), - 'fraudServices' => $this->fraud_service->get_fraud_services_config(), - 'features' => $this->gateway->supports, - 'forceNetworkSavedCards' => WC_Payments::is_network_saved_cards_enabled() || $gateway->should_use_stripe_platform_on_checkout_page(), - 'locale' => WC_Payments_Utils::convert_to_stripe_locale( get_locale() ), - 'isPreview' => is_preview(), - 'isSavedCardsEnabled' => $this->gateway->is_saved_cards_enabled(), - 'isExpressCheckoutElementEnabled' => WC_Payments_Features::is_stripe_ece_enabled(), - 'isTokenizedCartPrbEnabled' => WC_Payments_Features::is_tokenized_cart_prb_enabled(), - 'isWooPayEnabled' => $this->woopay_util->should_enable_woopay( $this->gateway ) && $this->woopay_util->should_enable_woopay_on_cart_or_checkout(), - 'isWoopayExpressCheckoutEnabled' => $this->woopay_util->is_woopay_express_checkout_enabled(), - 'isWoopayFirstPartyAuthEnabled' => $this->woopay_util->is_woopay_first_party_auth_enabled(), - 'isWooPayEmailInputEnabled' => $this->woopay_util->is_woopay_email_input_enabled(), - 'isWooPayDirectCheckoutEnabled' => WC_Payments_Features::is_woopay_direct_checkout_enabled(), - 'woopayHost' => WooPay_Utilities::get_woopay_url(), - 'platformTrackerNonce' => wp_create_nonce( 'platform_tracks_nonce' ), - 'accountIdForIntentConfirmation' => apply_filters( 'wc_payments_account_id_for_intent_confirmation', '' ), - 'wcpayVersionNumber' => WCPAY_VERSION_NUMBER, - 'woopaySignatureNonce' => wp_create_nonce( 'woopay_signature_nonce' ), - 'woopaySessionNonce' => wp_create_nonce( 'woopay_session_nonce' ), - 'woopayMerchantId' => Jetpack_Options::get_option( 'id' ), - 'icon' => $this->gateway->get_icon_url(), - 'woopayMinimumSessionData' => WooPay_Session::get_woopay_minimum_session_data(), + 'publishableKey' => $this->account->get_publishable_key( WC_Payments::mode()->is_test() ), + 'testMode' => WC_Payments::mode()->is_test(), + 'accountId' => $this->account->get_stripe_account_id(), + 'ajaxUrl' => admin_url( 'admin-ajax.php' ), + 'wcAjaxUrl' => WC_AJAX::get_endpoint( '%%endpoint%%' ), + 'createSetupIntentNonce' => wp_create_nonce( 'wcpay_create_setup_intent_nonce' ), + 'initWooPayNonce' => wp_create_nonce( 'wcpay_init_woopay_nonce' ), + 'saveUPEAppearanceNonce' => wp_create_nonce( 'wcpay_save_upe_appearance_nonce' ), + 'genericErrorMessage' => __( 'There was a problem processing the payment. Please check your email inbox and refresh the page to try again.', 'woocommerce-payments' ), + 'fraudServices' => $this->fraud_service->get_fraud_services_config(), + 'features' => $this->gateway->supports, + 'forceNetworkSavedCards' => WC_Payments::is_network_saved_cards_enabled() || $gateway->should_use_stripe_platform_on_checkout_page(), + 'locale' => WC_Payments_Utils::convert_to_stripe_locale( get_locale() ), + 'isPreview' => is_preview(), + 'isSavedCardsEnabled' => $this->gateway->is_saved_cards_enabled(), + 'isExpressCheckoutElementEnabled' => WC_Payments_Features::is_stripe_ece_enabled(), + 'isTokenizedCartPrbEnabled' => WC_Payments_Features::is_tokenized_cart_prb_enabled(), + 'isWooPayEnabled' => $this->woopay_util->should_enable_woopay( $this->gateway ) && $this->woopay_util->should_enable_woopay_on_cart_or_checkout(), + 'isWoopayExpressCheckoutEnabled' => $this->woopay_util->is_woopay_express_checkout_enabled(), + 'isWoopayFirstPartyAuthEnabled' => $this->woopay_util->is_woopay_first_party_auth_enabled(), + 'isWooPayEmailInputEnabled' => $this->woopay_util->is_woopay_email_input_enabled(), + 'isWooPayDirectCheckoutEnabled' => WC_Payments_Features::is_woopay_direct_checkout_enabled(), + 'isWooPayGlobalThemeSupportEnabled' => $this->gateway->is_woopay_global_theme_support_enabled(), + 'woopayHost' => WooPay_Utilities::get_woopay_url(), + 'platformTrackerNonce' => wp_create_nonce( 'platform_tracks_nonce' ), + 'accountIdForIntentConfirmation' => apply_filters( 'wc_payments_account_id_for_intent_confirmation', '' ), + 'wcpayVersionNumber' => WCPAY_VERSION_NUMBER, + 'woopaySignatureNonce' => wp_create_nonce( 'woopay_signature_nonce' ), + 'woopaySessionNonce' => wp_create_nonce( 'woopay_session_nonce' ), + 'woopayMerchantId' => Jetpack_Options::get_option( 'id' ), + 'icon' => $this->gateway->get_icon_url(), + 'woopayMinimumSessionData' => WooPay_Session::get_woopay_minimum_session_data(), ]; /** diff --git a/includes/class-wc-payments-features.php b/includes/class-wc-payments-features.php index 9a8ecb59b4c..97edcf32615 100644 --- a/includes/class-wc-payments-features.php +++ b/includes/class-wc-payments-features.php @@ -21,16 +21,17 @@ class WC_Payments_Features { * - The next version of WooPayments. * - The flag to be deleted. */ - const WCPAY_SUBSCRIPTIONS_FLAG_NAME = '_wcpay_feature_subscriptions'; - const STRIPE_BILLING_FLAG_NAME = '_wcpay_feature_stripe_billing'; - const STRIPE_ECE_FLAG_NAME = '_wcpay_feature_stripe_ece'; - const WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME = '_wcpay_feature_woopay_express_checkout'; - const WOOPAY_FIRST_PARTY_AUTH_FLAG_NAME = '_wcpay_feature_woopay_first_party_auth'; - const WOOPAY_DIRECT_CHECKOUT_FLAG_NAME = '_wcpay_feature_woopay_direct_checkout'; - const AUTH_AND_CAPTURE_FLAG_NAME = '_wcpay_feature_auth_and_capture'; - const DISPUTE_ISSUER_EVIDENCE = '_wcpay_feature_dispute_issuer_evidence'; - const TOKENIZED_CART_PRB_FLAG_NAME = '_wcpay_feature_tokenized_cart_prb'; - const PAYMENT_OVERVIEW_WIDGET_FLAG_NAME = '_wcpay_feature_payment_overview_widget'; + const WCPAY_SUBSCRIPTIONS_FLAG_NAME = '_wcpay_feature_subscriptions'; + const STRIPE_BILLING_FLAG_NAME = '_wcpay_feature_stripe_billing'; + const STRIPE_ECE_FLAG_NAME = '_wcpay_feature_stripe_ece'; + const WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME = '_wcpay_feature_woopay_express_checkout'; + const WOOPAY_FIRST_PARTY_AUTH_FLAG_NAME = '_wcpay_feature_woopay_first_party_auth'; + const WOOPAY_DIRECT_CHECKOUT_FLAG_NAME = '_wcpay_feature_woopay_direct_checkout'; + const AUTH_AND_CAPTURE_FLAG_NAME = '_wcpay_feature_auth_and_capture'; + const DISPUTE_ISSUER_EVIDENCE = '_wcpay_feature_dispute_issuer_evidence'; + const TOKENIZED_CART_PRB_FLAG_NAME = '_wcpay_feature_tokenized_cart_prb'; + const PAYMENT_OVERVIEW_WIDGET_FLAG_NAME = '_wcpay_feature_payment_overview_widget'; + const WOOPAY_GLOBAL_THEME_SUPPORT_FLAG_NAME = '_wcpay_feature_woopay_global_theme_support'; /** * Indicates whether card payments are enabled for this (Stripe) account. @@ -260,6 +261,16 @@ public static function is_woopay_direct_checkout_enabled() { return $is_direct_checkout_eligible && $is_direct_checkout_flag_enabled && self::is_woopayments_gateway_enabled() && self::is_woopay_enabled(); } + /** + * Checks whether WooPay global theme support is eligible. + * + * @return bool + */ + public static function is_woopay_global_theme_support_eligible() { + $account_cache = WC_Payments::get_database_cache()->get( WCPay\Database_Cache::ACCOUNT_KEY, true ); + return is_array( $account_cache ) && $account_cache['platform_global_theme_support_enabled'] ?? false; + } + /** * Checks whether Auth & Capture (uncaptured transactions tab, capture from payment details page) is enabled. *