mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
Enable server-side callback via feature flag
This commit is contained in:
parent
6691ee5a21
commit
60d4ea2208
7 changed files with 84 additions and 46 deletions
|
@ -352,7 +352,9 @@ export const PayPalComponent = ( {
|
|||
);
|
||||
|
||||
const getOnShippingOptionsChange = ( fundingSource ) => {
|
||||
return null;
|
||||
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 ) => {
|
||||
return null;
|
||||
if ( ! config.scriptData.server_side_shipping_callback.enabled ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( fundingSource === 'venmo' ) {
|
||||
return null;
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
);
|
||||
|
|
|
@ -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,36 +313,38 @@ 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
|
||||
) {
|
||||
$this->module_url = $module_url;
|
||||
$this->version = $version;
|
||||
$this->session_handler = $session_handler;
|
||||
$this->settings = $settings;
|
||||
$this->payer_factory = $payer_factory;
|
||||
$this->client_id = $client_id;
|
||||
$this->request_data = $request_data;
|
||||
$this->dcc_applies = $dcc_applies;
|
||||
$this->subscription_helper = $subscription_helper;
|
||||
$this->messages_apply = $messages_apply;
|
||||
$this->environment = $environment;
|
||||
$this->payment_token_repository = $payment_token_repository;
|
||||
$this->settings_status = $settings_status;
|
||||
$this->currency = $currency;
|
||||
$this->all_funding_sources = $all_funding_sources;
|
||||
$this->basic_checkout_validation_enabled = $basic_checkout_validation_enabled;
|
||||
$this->early_validation_enabled = $early_validation_enabled;
|
||||
$this->pay_now_contexts = $pay_now_contexts;
|
||||
$this->funding_sources_without_redirect = $funding_sources_without_redirect;
|
||||
$this->vault_v3_enabled = $vault_v3_enabled;
|
||||
$this->logger = $logger;
|
||||
$this->payment_tokens_endpoint = $payment_tokens_endpoint;
|
||||
$this->should_handle_shipping_in_paypal = $should_handle_shipping_in_paypal;
|
||||
$this->disabled_funding_sources = $disabled_funding_sources;
|
||||
$this->dcc_configuration = $dcc_configuration;
|
||||
$this->partner_attribution = $partner_attribution;
|
||||
$this->module_url = $module_url;
|
||||
$this->version = $version;
|
||||
$this->session_handler = $session_handler;
|
||||
$this->settings = $settings;
|
||||
$this->payer_factory = $payer_factory;
|
||||
$this->client_id = $client_id;
|
||||
$this->request_data = $request_data;
|
||||
$this->dcc_applies = $dcc_applies;
|
||||
$this->subscription_helper = $subscription_helper;
|
||||
$this->messages_apply = $messages_apply;
|
||||
$this->environment = $environment;
|
||||
$this->payment_token_repository = $payment_token_repository;
|
||||
$this->settings_status = $settings_status;
|
||||
$this->currency = $currency;
|
||||
$this->all_funding_sources = $all_funding_sources;
|
||||
$this->basic_checkout_validation_enabled = $basic_checkout_validation_enabled;
|
||||
$this->early_validation_enabled = $early_validation_enabled;
|
||||
$this->pay_now_contexts = $pay_now_contexts;
|
||||
$this->funding_sources_without_redirect = $funding_sources_without_redirect;
|
||||
$this->vault_v3_enabled = $vault_v3_enabled;
|
||||
$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,
|
||||
|
|
|
@ -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,26 +219,28 @@ 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
|
||||
) {
|
||||
|
||||
$this->request_data = $request_data;
|
||||
$this->purchase_unit_factory = $purchase_unit_factory;
|
||||
$this->shipping_preference_factory = $shipping_preference_factory;
|
||||
$this->experience_context_builder = $experience_context_builder;
|
||||
$this->api_endpoint = $order_endpoint;
|
||||
$this->payer_factory = $payer_factory;
|
||||
$this->session_handler = $session_handler;
|
||||
$this->settings = $settings;
|
||||
$this->early_order_handler = $early_order_handler;
|
||||
$this->registration_needed = $registration_needed;
|
||||
$this->card_billing_data_mode = $card_billing_data_mode;
|
||||
$this->early_validation_enabled = $early_validation_enabled;
|
||||
$this->pay_now_contexts = $pay_now_contexts;
|
||||
$this->handle_shipping_in_paypal = $handle_shipping_in_paypal;
|
||||
$this->funding_sources_without_redirect = $funding_sources_without_redirect;
|
||||
$this->logger = $logger;
|
||||
$this->request_data = $request_data;
|
||||
$this->purchase_unit_factory = $purchase_unit_factory;
|
||||
$this->shipping_preference_factory = $shipping_preference_factory;
|
||||
$this->experience_context_builder = $experience_context_builder;
|
||||
$this->api_endpoint = $order_endpoint;
|
||||
$this->payer_factory = $payer_factory;
|
||||
$this->session_handler = $session_handler;
|
||||
$this->settings = $settings;
|
||||
$this->early_order_handler = $early_order_handler;
|
||||
$this->registration_needed = $registration_needed;
|
||||
$this->card_billing_data_mode = $card_billing_data_mode;
|
||||
$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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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'
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -172,6 +172,7 @@ class CreateOrderEndpointTest extends TestCase
|
|||
false,
|
||||
['checkout'],
|
||||
false,
|
||||
false,
|
||||
['paypal'],
|
||||
new NullLogger()
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue