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

View file

@ -144,7 +144,10 @@ class Renderer {
};
// 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 ) => {
const shippingOptionsChange =
! this.isVenmoButtonClickedWhenVaultingIsEnabled(

View file

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

View file

@ -253,6 +253,11 @@ class SmartButton implements SmartButtonInterface {
*/
protected PartnerAttribution $partner_attribution;
/**
* Whether the server-side shipping callback is enabled (feature flag).
*/
private bool $server_side_shipping_callback_enabled;
/**
* SmartButton constructor.
*
@ -279,6 +284,7 @@ class SmartButton implements SmartButtonInterface {
* @param PaymentTokensEndpoint $payment_tokens_endpoint Payment tokens endpoint.
* @param LoggerInterface $logger The logger.
* @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 CardPaymentsConfiguration $dcc_configuration The DCC Gateway Configuration.
* @param PartnerAttribution $partner_attribution The PayPal Partner Attribution Helper.
@ -307,6 +313,7 @@ class SmartButton implements SmartButtonInterface {
PaymentTokensEndpoint $payment_tokens_endpoint,
LoggerInterface $logger,
bool $should_handle_shipping_in_paypal,
bool $server_side_shipping_callback_enabled,
DisabledFundingSources $disabled_funding_sources,
CardPaymentsConfiguration $dcc_configuration,
PartnerAttribution $partner_attribution
@ -334,6 +341,7 @@ class SmartButton implements SmartButtonInterface {
$this->logger = $logger;
$this->payment_tokens_endpoint = $payment_tokens_endpoint;
$this->should_handle_shipping_in_paypal = $should_handle_shipping_in_paypal;
$this->server_side_shipping_callback_enabled = $server_side_shipping_callback_enabled;
$this->disabled_funding_sources = $disabled_funding_sources;
$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() ),
),
'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(),
'vaultingEnabled' => $this->settings->has( 'vault_enabled' ) && $this->settings->get( 'vault_enabled' ),
'productType' => null,

View file

@ -157,6 +157,11 @@ class CreateOrderEndpoint implements EndpointInterface {
*/
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.
*
@ -195,6 +200,7 @@ class CreateOrderEndpoint implements EndpointInterface {
* @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 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 LoggerInterface $logger The logger.
*/
@ -213,6 +219,7 @@ class CreateOrderEndpoint implements EndpointInterface {
bool $early_validation_enabled,
array $pay_now_contexts,
bool $handle_shipping_in_paypal,
bool $server_side_shipping_callback_enabled,
array $funding_sources_without_redirect,
LoggerInterface $logger
) {
@ -231,6 +238,7 @@ class CreateOrderEndpoint implements EndpointInterface {
$this->early_validation_enabled = $early_validation_enabled;
$this->pay_now_contexts = $pay_now_contexts;
$this->handle_shipping_in_paypal = $handle_shipping_in_paypal;
$this->server_side_shipping_callback_enabled = $server_side_shipping_callback_enabled;
$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 );
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();
}

View file

@ -2166,4 +2166,12 @@ return array(
$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,
['checkout'],
false,
false,
['paypal'],
new NullLogger()
);