mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
Merge pull request #2394 from woocommerce/PCP-680-retain-subscription-functionality-for-existing-subscriptions-when-pay-pal-subscriptions-mode-or-pay-pal-features-are-disabled
Preserve subscription renewal processing when switching Subscriptions Mode or disabling gateway (680)
This commit is contained in:
commit
dd777f1401
4 changed files with 140 additions and 83 deletions
|
@ -185,29 +185,15 @@ class CardButtonGateway extends \WC_Payment_Gateway {
|
|||
$this->paypal_checkout_url_factory = $paypal_checkout_url_factory;
|
||||
$this->order_button_text = $place_order_button_text;
|
||||
|
||||
$this->supports = array(
|
||||
'refunds',
|
||||
$default_support = array(
|
||||
'products',
|
||||
'refunds',
|
||||
);
|
||||
|
||||
if (
|
||||
( $this->config->has( 'vault_enabled' ) && $this->config->get( 'vault_enabled' ) )
|
||||
|| ( $this->config->has( 'subscriptions_mode' ) && $this->config->get( 'subscriptions_mode' ) === 'subscriptions_api' )
|
||||
) {
|
||||
array_push(
|
||||
$this->supports,
|
||||
'subscriptions',
|
||||
'subscription_cancellation',
|
||||
'subscription_suspension',
|
||||
'subscription_reactivation',
|
||||
'subscription_amount_changes',
|
||||
'subscription_date_changes',
|
||||
'subscription_payment_method_change',
|
||||
'subscription_payment_method_change_customer',
|
||||
'subscription_payment_method_change_admin',
|
||||
'multiple_subscriptions'
|
||||
);
|
||||
}
|
||||
$this->supports = array_merge(
|
||||
$default_support,
|
||||
apply_filters( 'woocommerce_paypal_payments_card_button_gateway_supports', array() )
|
||||
);
|
||||
|
||||
$this->method_title = __( 'Standard Card Button', 'woocommerce-paypal-payments' );
|
||||
$this->method_description = __( 'The separate payment gateway with the card button. If disabled, the button is included in the PayPal gateway.', 'woocommerce-paypal-payments' );
|
||||
|
|
|
@ -240,38 +240,17 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
$this->wc_payment_tokens = $wc_payment_tokens;
|
||||
$this->logger = $logger;
|
||||
|
||||
if ( $state->current_state() === State::STATE_ONBOARDED ) {
|
||||
$this->supports = array( 'refunds' );
|
||||
}
|
||||
if ( $this->config->has( 'dcc_enabled' ) && $this->config->get( 'dcc_enabled' ) ) {
|
||||
$this->supports = array(
|
||||
'refunds',
|
||||
'products',
|
||||
);
|
||||
$default_support = array(
|
||||
'products',
|
||||
'refunds',
|
||||
'tokenization',
|
||||
'add_payment_method',
|
||||
);
|
||||
|
||||
if ( $this->config->has( 'vault_enabled_dcc' ) && $this->config->get( 'vault_enabled_dcc' ) ) {
|
||||
$supports = apply_filters(
|
||||
'woocommerce_paypal_payments_credit_card_gateway_vault_supports',
|
||||
array(
|
||||
'subscriptions',
|
||||
'subscription_cancellation',
|
||||
'subscription_suspension',
|
||||
'subscription_reactivation',
|
||||
'subscription_amount_changes',
|
||||
'subscription_date_changes',
|
||||
'subscription_payment_method_change',
|
||||
'subscription_payment_method_change_customer',
|
||||
'subscription_payment_method_change_admin',
|
||||
'multiple_subscriptions',
|
||||
)
|
||||
);
|
||||
|
||||
$this->supports = array_merge(
|
||||
$this->supports,
|
||||
$supports
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->supports = array_merge(
|
||||
$default_support,
|
||||
apply_filters( 'woocommerce_paypal_payments_credit_card_gateway_supports', array() )
|
||||
);
|
||||
|
||||
$this->method_title = __(
|
||||
'Advanced Card Processing',
|
||||
|
|
|
@ -271,39 +271,17 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
$this->vault_v3_enabled = $vault_v3_enabled;
|
||||
$this->wc_payment_tokens = $wc_payment_tokens;
|
||||
|
||||
if ( $this->onboarded ) {
|
||||
$this->supports = array( 'refunds', 'tokenization' );
|
||||
}
|
||||
if ( $this->config->has( 'enabled' ) && $this->config->get( 'enabled' ) ) {
|
||||
$this->supports = array(
|
||||
'refunds',
|
||||
'products',
|
||||
);
|
||||
$default_support = array(
|
||||
'products',
|
||||
'refunds',
|
||||
'tokenization',
|
||||
'add_payment_method',
|
||||
);
|
||||
|
||||
if (
|
||||
( $this->config->has( 'vault_enabled' ) && $this->config->get( 'vault_enabled' ) )
|
||||
|| ( $this->config->has( 'subscriptions_mode' ) && $this->config->get( 'subscriptions_mode' ) === 'subscriptions_api' )
|
||||
) {
|
||||
array_push(
|
||||
$this->supports,
|
||||
'tokenization',
|
||||
'subscriptions',
|
||||
'subscription_cancellation',
|
||||
'subscription_suspension',
|
||||
'subscription_reactivation',
|
||||
'subscription_amount_changes',
|
||||
'subscription_date_changes',
|
||||
'subscription_payment_method_change',
|
||||
'subscription_payment_method_change_customer',
|
||||
'subscription_payment_method_change_admin',
|
||||
'multiple_subscriptions'
|
||||
);
|
||||
} elseif ( $this->config->has( 'subscriptions_mode' ) && $this->config->get( 'subscriptions_mode' ) === 'subscriptions_api' ) {
|
||||
$this->supports[] = 'gateway_scheduled_payments';
|
||||
} elseif ( $this->config->has( 'vault_enabled_dcc' ) && $this->config->get( 'vault_enabled_dcc' ) ) {
|
||||
$this->supports[] = 'tokenization';
|
||||
}
|
||||
}
|
||||
$this->supports = array_merge(
|
||||
$default_support,
|
||||
apply_filters( 'woocommerce_paypal_payments_paypal_gateway_supports', array() )
|
||||
);
|
||||
|
||||
$this->method_title = $this->define_method_title();
|
||||
$this->method_description = $this->define_method_description();
|
||||
|
|
|
@ -49,6 +49,8 @@ class WcSubscriptionsModule implements ModuleInterface {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
public function run( ContainerInterface $c ): void {
|
||||
$this->add_gateways_support( $c );
|
||||
|
||||
add_action(
|
||||
'woocommerce_scheduled_subscription_payment_' . PayPalGateway::ID,
|
||||
/**
|
||||
|
@ -228,6 +230,31 @@ class WcSubscriptionsModule implements ModuleInterface {
|
|||
$endpoint->handle_request();
|
||||
}
|
||||
);
|
||||
|
||||
// Remove `gateway_scheduled_payments` feature support for non PayPal Subscriptions at subscription level.
|
||||
add_filter(
|
||||
'woocommerce_subscription_payment_gateway_supports',
|
||||
/**
|
||||
* Param types removed to avoid third-party issues.
|
||||
*
|
||||
* @psalm-suppress MissingClosureParamType
|
||||
*/
|
||||
function( $is_supported, $feature, $subscription ) {
|
||||
if (
|
||||
$subscription->get_payment_method() === PayPalGateway::ID
|
||||
&& $feature === 'gateway_scheduled_payments'
|
||||
) {
|
||||
$subscription_connected = $subscription->get_meta( 'ppcp_subscription' ) ?? '';
|
||||
if ( ! $subscription_connected ) {
|
||||
$is_supported = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $is_supported;
|
||||
},
|
||||
10,
|
||||
3
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -372,4 +399,91 @@ class WcSubscriptionsModule implements ModuleInterface {
|
|||
|
||||
return $default_fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups all filters for adding WC Subscriptions gateway support.
|
||||
*
|
||||
* @param ContainerInterface $c The container.
|
||||
* @return void
|
||||
*/
|
||||
private function add_gateways_support( ContainerInterface $c ): void {
|
||||
add_filter(
|
||||
'woocommerce_paypal_payments_paypal_gateway_supports',
|
||||
function ( array $supports ) use ( $c ): array {
|
||||
$subscriptions_helper = $c->get( 'wc-subscriptions.helper' );
|
||||
assert( $subscriptions_helper instanceof SubscriptionHelper );
|
||||
|
||||
$settings = $c->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
|
||||
if ( $subscriptions_helper->plugin_is_active() ) {
|
||||
$supports = array(
|
||||
'subscriptions',
|
||||
'subscription_cancellation',
|
||||
'subscription_suspension',
|
||||
'subscription_reactivation',
|
||||
'subscription_amount_changes',
|
||||
'subscription_date_changes',
|
||||
'subscription_payment_method_change',
|
||||
'subscription_payment_method_change_customer',
|
||||
'subscription_payment_method_change_admin',
|
||||
'multiple_subscriptions',
|
||||
'gateway_scheduled_payments',
|
||||
);
|
||||
}
|
||||
|
||||
return $supports;
|
||||
}
|
||||
);
|
||||
|
||||
add_filter(
|
||||
'woocommerce_paypal_payments_credit_card_gateway_supports',
|
||||
function ( array $supports ) use ( $c ): array {
|
||||
$subscriptions_helper = $c->get( 'wc-subscriptions.helper' );
|
||||
assert( $subscriptions_helper instanceof SubscriptionHelper );
|
||||
|
||||
if ( $subscriptions_helper->plugin_is_active() ) {
|
||||
$supports = array(
|
||||
'subscriptions',
|
||||
'subscription_cancellation',
|
||||
'subscription_suspension',
|
||||
'subscription_reactivation',
|
||||
'subscription_amount_changes',
|
||||
'subscription_date_changes',
|
||||
'subscription_payment_method_change',
|
||||
'subscription_payment_method_change_customer',
|
||||
'subscription_payment_method_change_admin',
|
||||
'multiple_subscriptions',
|
||||
);
|
||||
}
|
||||
|
||||
return $supports;
|
||||
}
|
||||
);
|
||||
|
||||
add_filter(
|
||||
'woocommerce_paypal_payments_card_button_gateway_supports',
|
||||
function ( array $supports ) use ( $c ): array {
|
||||
$subscriptions_helper = $c->get( 'wc-subscriptions.helper' );
|
||||
assert( $subscriptions_helper instanceof SubscriptionHelper );
|
||||
|
||||
if ( $subscriptions_helper->plugin_is_active() ) {
|
||||
$supports = array(
|
||||
'subscriptions',
|
||||
'subscription_cancellation',
|
||||
'subscription_suspension',
|
||||
'subscription_reactivation',
|
||||
'subscription_amount_changes',
|
||||
'subscription_date_changes',
|
||||
'subscription_payment_method_change',
|
||||
'subscription_payment_method_change_customer',
|
||||
'subscription_payment_method_change_admin',
|
||||
'multiple_subscriptions',
|
||||
);
|
||||
}
|
||||
|
||||
return $supports;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue