Enable server-side callback via feature flag

This commit is contained in:
Alex P. 2025-06-20 15:14:11 +03:00
parent 6691ee5a21
commit 60d4ea2208
No known key found for this signature in database
GPG key ID: 54487A734A204D71
7 changed files with 84 additions and 46 deletions

View file

@ -352,7 +352,9 @@ export const PayPalComponent = ( {
); );
const getOnShippingOptionsChange = ( fundingSource ) => { const getOnShippingOptionsChange = ( fundingSource ) => {
return null; if ( ! config.scriptData.server_side_shipping_callback.enabled ) {
return null;
}
if ( fundingSource === 'venmo' ) { if ( fundingSource === 'venmo' ) {
return null; return null;
@ -366,7 +368,9 @@ export const PayPalComponent = ( {
}; };
const getOnShippingAddressChange = ( fundingSource ) => { const getOnShippingAddressChange = ( fundingSource ) => {
return null; if ( ! config.scriptData.server_side_shipping_callback.enabled ) {
return null;
}
if ( fundingSource === 'venmo' ) { if ( fundingSource === 'venmo' ) {
return null; return null;

View file

@ -144,7 +144,10 @@ class Renderer {
}; };
// Check the condition and add the handler if needed // Check the condition and add the handler if needed
if ( this.shouldEnableShippingCallback() ) { if (
this.shouldEnableShippingCallback() &&
! this.defaultSettings.server_side_shipping_callback.enabled
) {
options.onShippingOptionsChange = ( data, actions ) => { options.onShippingOptionsChange = ( data, actions ) => {
const shippingOptionsChange = const shippingOptionsChange =
! this.isVenmoButtonClickedWhenVaultingIsEnabled( ! this.isVenmoButtonClickedWhenVaultingIsEnabled(

View file

@ -167,6 +167,7 @@ return array(
$container->get( 'api.endpoint.payment-tokens' ), $container->get( 'api.endpoint.payment-tokens' ),
$container->get( 'woocommerce.logger.woocommerce' ), $container->get( 'woocommerce.logger.woocommerce' ),
$container->get( 'button.handle-shipping-in-paypal' ), $container->get( 'button.handle-shipping-in-paypal' ),
$container->get( 'wcgateway.server-side-shipping-callback-enabled' ),
$container->get( 'button.helper.disabled-funding-sources' ), $container->get( 'button.helper.disabled-funding-sources' ),
$container->get( 'wcgateway.configuration.card-configuration' ), $container->get( 'wcgateway.configuration.card-configuration' ),
$container->get( 'api.helper.partner-attribution' ) $container->get( 'api.helper.partner-attribution' )
@ -238,6 +239,7 @@ return array(
$container->get( 'button.early-wc-checkout-validation-enabled' ), $container->get( 'button.early-wc-checkout-validation-enabled' ),
$container->get( 'button.pay-now-contexts' ), $container->get( 'button.pay-now-contexts' ),
$container->get( 'button.handle-shipping-in-paypal' ), $container->get( 'button.handle-shipping-in-paypal' ),
$container->get( 'wcgateway.server-side-shipping-callback-enabled' ),
$container->get( 'wcgateway.funding-sources-without-redirect' ), $container->get( 'wcgateway.funding-sources-without-redirect' ),
$logger $logger
); );

View file

@ -253,6 +253,11 @@ class SmartButton implements SmartButtonInterface {
*/ */
protected PartnerAttribution $partner_attribution; protected PartnerAttribution $partner_attribution;
/**
* Whether the server-side shipping callback is enabled (feature flag).
*/
private bool $server_side_shipping_callback_enabled;
/** /**
* SmartButton constructor. * SmartButton constructor.
* *
@ -279,6 +284,7 @@ class SmartButton implements SmartButtonInterface {
* @param PaymentTokensEndpoint $payment_tokens_endpoint Payment tokens endpoint. * @param PaymentTokensEndpoint $payment_tokens_endpoint Payment tokens endpoint.
* @param LoggerInterface $logger The logger. * @param LoggerInterface $logger The logger.
* @param bool $should_handle_shipping_in_paypal Whether the shipping should be handled in PayPal. * @param bool $should_handle_shipping_in_paypal Whether the shipping should be handled in PayPal.
* @param bool $server_side_shipping_callback_enabled Whether the server-side shipping callback is enabled (feature flag).
* @param DisabledFundingSources $disabled_funding_sources List of funding sources to be disabled. * @param DisabledFundingSources $disabled_funding_sources List of funding sources to be disabled.
* @param CardPaymentsConfiguration $dcc_configuration The DCC Gateway Configuration. * @param CardPaymentsConfiguration $dcc_configuration The DCC Gateway Configuration.
* @param PartnerAttribution $partner_attribution The PayPal Partner Attribution Helper. * @param PartnerAttribution $partner_attribution The PayPal Partner Attribution Helper.
@ -307,36 +313,38 @@ class SmartButton implements SmartButtonInterface {
PaymentTokensEndpoint $payment_tokens_endpoint, PaymentTokensEndpoint $payment_tokens_endpoint,
LoggerInterface $logger, LoggerInterface $logger,
bool $should_handle_shipping_in_paypal, bool $should_handle_shipping_in_paypal,
bool $server_side_shipping_callback_enabled,
DisabledFundingSources $disabled_funding_sources, DisabledFundingSources $disabled_funding_sources,
CardPaymentsConfiguration $dcc_configuration, CardPaymentsConfiguration $dcc_configuration,
PartnerAttribution $partner_attribution PartnerAttribution $partner_attribution
) { ) {
$this->module_url = $module_url; $this->module_url = $module_url;
$this->version = $version; $this->version = $version;
$this->session_handler = $session_handler; $this->session_handler = $session_handler;
$this->settings = $settings; $this->settings = $settings;
$this->payer_factory = $payer_factory; $this->payer_factory = $payer_factory;
$this->client_id = $client_id; $this->client_id = $client_id;
$this->request_data = $request_data; $this->request_data = $request_data;
$this->dcc_applies = $dcc_applies; $this->dcc_applies = $dcc_applies;
$this->subscription_helper = $subscription_helper; $this->subscription_helper = $subscription_helper;
$this->messages_apply = $messages_apply; $this->messages_apply = $messages_apply;
$this->environment = $environment; $this->environment = $environment;
$this->payment_token_repository = $payment_token_repository; $this->payment_token_repository = $payment_token_repository;
$this->settings_status = $settings_status; $this->settings_status = $settings_status;
$this->currency = $currency; $this->currency = $currency;
$this->all_funding_sources = $all_funding_sources; $this->all_funding_sources = $all_funding_sources;
$this->basic_checkout_validation_enabled = $basic_checkout_validation_enabled; $this->basic_checkout_validation_enabled = $basic_checkout_validation_enabled;
$this->early_validation_enabled = $early_validation_enabled; $this->early_validation_enabled = $early_validation_enabled;
$this->pay_now_contexts = $pay_now_contexts; $this->pay_now_contexts = $pay_now_contexts;
$this->funding_sources_without_redirect = $funding_sources_without_redirect; $this->funding_sources_without_redirect = $funding_sources_without_redirect;
$this->vault_v3_enabled = $vault_v3_enabled; $this->vault_v3_enabled = $vault_v3_enabled;
$this->logger = $logger; $this->logger = $logger;
$this->payment_tokens_endpoint = $payment_tokens_endpoint; $this->payment_tokens_endpoint = $payment_tokens_endpoint;
$this->should_handle_shipping_in_paypal = $should_handle_shipping_in_paypal; $this->should_handle_shipping_in_paypal = $should_handle_shipping_in_paypal;
$this->disabled_funding_sources = $disabled_funding_sources; $this->server_side_shipping_callback_enabled = $server_side_shipping_callback_enabled;
$this->dcc_configuration = $dcc_configuration; $this->disabled_funding_sources = $disabled_funding_sources;
$this->partner_attribution = $partner_attribution; $this->dcc_configuration = $dcc_configuration;
$this->partner_attribution = $partner_attribution;
} }
/** /**
@ -1341,6 +1349,9 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
'has_wc_card_payment_tokens' => $this->user_has_wc_card_payment_tokens( get_current_user_id() ), 'has_wc_card_payment_tokens' => $this->user_has_wc_card_payment_tokens( get_current_user_id() ),
), ),
'should_handle_shipping_in_paypal' => $this->should_handle_shipping_in_paypal && ! $this->is_checkout(), 'should_handle_shipping_in_paypal' => $this->should_handle_shipping_in_paypal && ! $this->is_checkout(),
'server_side_shipping_callback' => array(
'enabled' => $this->server_side_shipping_callback_enabled,
),
'needShipping' => $this->need_shipping(), 'needShipping' => $this->need_shipping(),
'vaultingEnabled' => $this->settings->has( 'vault_enabled' ) && $this->settings->get( 'vault_enabled' ), 'vaultingEnabled' => $this->settings->has( 'vault_enabled' ) && $this->settings->get( 'vault_enabled' ),
'productType' => null, 'productType' => null,

View file

@ -157,6 +157,11 @@ class CreateOrderEndpoint implements EndpointInterface {
*/ */
private $handle_shipping_in_paypal; private $handle_shipping_in_paypal;
/**
* Whether the server-side shipping callback is enabled (feature flag).
*/
private bool $server_side_shipping_callback_enabled;
/** /**
* The sources that do not cause issues about redirecting (on mobile, ...) and sometimes not returning back. * The sources that do not cause issues about redirecting (on mobile, ...) and sometimes not returning back.
* *
@ -195,6 +200,7 @@ class CreateOrderEndpoint implements EndpointInterface {
* @param bool $early_validation_enabled Whether to execute WC validation of the checkout form. * @param bool $early_validation_enabled Whether to execute WC validation of the checkout form.
* @param string[] $pay_now_contexts The contexts that should have the Pay Now button. * @param string[] $pay_now_contexts The contexts that should have the Pay Now button.
* @param bool $handle_shipping_in_paypal If true, the shipping methods are sent to PayPal allowing the customer to select it inside the popup. * @param bool $handle_shipping_in_paypal If true, the shipping methods are sent to PayPal allowing the customer to select it inside the popup.
* @param bool $server_side_shipping_callback_enabled Whether the server-side shipping callback is enabled (feature flag).
* @param string[] $funding_sources_without_redirect The sources that do not cause issues about redirecting (on mobile, ...) and sometimes not returning back. * @param string[] $funding_sources_without_redirect The sources that do not cause issues about redirecting (on mobile, ...) and sometimes not returning back.
* @param LoggerInterface $logger The logger. * @param LoggerInterface $logger The logger.
*/ */
@ -213,26 +219,28 @@ class CreateOrderEndpoint implements EndpointInterface {
bool $early_validation_enabled, bool $early_validation_enabled,
array $pay_now_contexts, array $pay_now_contexts,
bool $handle_shipping_in_paypal, bool $handle_shipping_in_paypal,
bool $server_side_shipping_callback_enabled,
array $funding_sources_without_redirect, array $funding_sources_without_redirect,
LoggerInterface $logger LoggerInterface $logger
) { ) {
$this->request_data = $request_data; $this->request_data = $request_data;
$this->purchase_unit_factory = $purchase_unit_factory; $this->purchase_unit_factory = $purchase_unit_factory;
$this->shipping_preference_factory = $shipping_preference_factory; $this->shipping_preference_factory = $shipping_preference_factory;
$this->experience_context_builder = $experience_context_builder; $this->experience_context_builder = $experience_context_builder;
$this->api_endpoint = $order_endpoint; $this->api_endpoint = $order_endpoint;
$this->payer_factory = $payer_factory; $this->payer_factory = $payer_factory;
$this->session_handler = $session_handler; $this->session_handler = $session_handler;
$this->settings = $settings; $this->settings = $settings;
$this->early_order_handler = $early_order_handler; $this->early_order_handler = $early_order_handler;
$this->registration_needed = $registration_needed; $this->registration_needed = $registration_needed;
$this->card_billing_data_mode = $card_billing_data_mode; $this->card_billing_data_mode = $card_billing_data_mode;
$this->early_validation_enabled = $early_validation_enabled; $this->early_validation_enabled = $early_validation_enabled;
$this->pay_now_contexts = $pay_now_contexts; $this->pay_now_contexts = $pay_now_contexts;
$this->handle_shipping_in_paypal = $handle_shipping_in_paypal; $this->handle_shipping_in_paypal = $handle_shipping_in_paypal;
$this->funding_sources_without_redirect = $funding_sources_without_redirect; $this->server_side_shipping_callback_enabled = $server_side_shipping_callback_enabled;
$this->logger = $logger; $this->funding_sources_without_redirect = $funding_sources_without_redirect;
$this->logger = $logger;
} }
/** /**
@ -447,7 +455,8 @@ class CreateOrderEndpoint implements EndpointInterface {
} }
$experience_context = $this->experience_context_builder->with_default_paypal_config( $shipping_preference, $action ); $experience_context = $this->experience_context_builder->with_default_paypal_config( $shipping_preference, $action );
if ( $shipping_preference === ExperienceContext::SHIPPING_PREFERENCE_GET_FROM_FILE ) { if ( $this->server_side_shipping_callback_enabled
&& $shipping_preference === ExperienceContext::SHIPPING_PREFERENCE_GET_FROM_FILE ) {
$experience_context = $experience_context->with_shipping_callback(); $experience_context = $experience_context->with_shipping_callback();
} }

View file

@ -2166,4 +2166,12 @@ return array(
$container->get( 'wcgateway.shipping.callback.endpoint' ) $container->get( 'wcgateway.shipping.callback.endpoint' )
); );
}, },
'wcgateway.server-side-shipping-callback-enabled' => static function( ContainerInterface $container ) : bool {
return apply_filters(
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
'woocommerce.feature-flags.woocommerce_paypal_payments.server_side_shipping_callback_enabled',
getenv( 'PCP_SERVER_SIDE_SHIPPING_CALLBACK_ENABLED' ) === '1'
);
},
); );

View file

@ -172,6 +172,7 @@ class CreateOrderEndpointTest extends TestCase
false, false,
['checkout'], ['checkout'],
false, false,
false,
['paypal'], ['paypal'],
new NullLogger() new NullLogger()
); );