diff --git a/modules/ppcp-wc-gateway/src/Gateway/CreditCardGateway.php b/modules/ppcp-wc-gateway/src/Gateway/CreditCardGateway.php index 7236e687b..6d152eb33 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/CreditCardGateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/CreditCardGateway.php @@ -180,10 +180,7 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC { 'products', ); - if ( - ( $this->config->has( 'vault_enabled_dcc' ) && $this->config->get( 'vault_enabled_dcc' ) ) - || ( $this->config->has( 'subscriptions_mode' ) && $this->config->get( 'subscriptions_mode' ) === 'subscriptions_api' ) - ) { + if ( $this->config->has( 'vault_enabled_dcc' ) && $this->config->get( 'vault_enabled_dcc' ) ) { array_push( $this->supports, 'subscriptions', diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php index 933e6ce51..a2a42a589 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php @@ -543,6 +543,7 @@ class PayPalGateway extends \WC_Payment_Gateway { } $wc_order->payment_complete(); + return $this->handle_payment_success( $wc_order ); } diff --git a/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php b/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php index ab16ec178..d330a11a6 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php +++ b/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php @@ -77,6 +77,7 @@ trait ProcessPaymentTrait { } $this->session_handler->destroy_session_data(); + WC()->session->set( 'ppcp_subscription_id', '' ); wc_add_notice( $error->getMessage(), 'error' ); @@ -100,6 +101,7 @@ trait ProcessPaymentTrait { } $this->session_handler->destroy_session_data(); + WC()->session->set( 'ppcp_subscription_id', '' ); return array( 'result' => 'success', diff --git a/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php b/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php index 0f479c4cc..4b871750c 100644 --- a/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php +++ b/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php @@ -340,7 +340,20 @@ class SettingsListener { * phpcs:disable WordPress.Security.NonceVerification.Missing * phpcs:disable WordPress.Security.NonceVerification.Recommended */ - if ( ! isset( $_POST['ppcp']['vault_enabled'] ) ) { + $vault_enabled = wc_clean( wp_unslash( $_POST['ppcp']['vault_enabled'] ?? '' ) ); + $subscription_mode = wc_clean( wp_unslash( $_POST['ppcp']['subscriptions_mode'] ?? '' ) ); + + if ( $subscription_mode === 'vaulting_api' && $vault_enabled !== '1' ) { + $this->settings->set( 'vault_enabled', true ); + $this->settings->persist(); + } + + if ( $subscription_mode === 'disable_paypal_subscriptions' && $vault_enabled === '1' ) { + $this->settings->set( 'vault_enabled', false ); + $this->settings->persist(); + } + + if ( $vault_enabled !== '1' ) { return; } diff --git a/tests/PHPUnit/WcGateway/Gateway/CreditCardGatewayTest.php b/tests/PHPUnit/WcGateway/Gateway/CreditCardGatewayTest.php index 693658756..5e2a8bbc7 100644 --- a/tests/PHPUnit/WcGateway/Gateway/CreditCardGatewayTest.php +++ b/tests/PHPUnit/WcGateway/Gateway/CreditCardGatewayTest.php @@ -78,6 +78,12 @@ class CreditCardGatewayTest extends TestCase $wc_order = Mockery::mock(WC_Order::class); when('wc_get_order')->justReturn($wc_order); + $woocommerce = Mockery::mock(\WooCommerce::class); + $session = Mockery::mock(\WC_Session::class); + when('WC')->justReturn($woocommerce); + $woocommerce->session = $session; + $session->shouldReceive('set')->andReturn([]); + $this->orderProcessor->shouldReceive('process') ->with($wc_order) ->andReturn(true); @@ -95,6 +101,12 @@ class CreditCardGatewayTest extends TestCase $wc_order->shouldReceive('get_customer_id')->andReturn(1); when('wc_get_order')->justReturn($wc_order); + $woocommerce = Mockery::mock(\WooCommerce::class); + $session = Mockery::mock(\WC_Session::class); + when('WC')->justReturn($woocommerce); + $woocommerce->session = $session; + $session->shouldReceive('set')->andReturn([]); + $savedCreditCard = 'abc123'; $_POST['saved_credit_card'] = $savedCreditCard; diff --git a/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php b/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php index a5a1dea3e..aa9057c67 100644 --- a/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php +++ b/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php @@ -147,9 +147,11 @@ class WcGatewayTest extends TestCase when('WC')->justReturn($woocommerce); $woocommerce->cart = $cart; $cart->shouldReceive('empty_cart'); + $session = Mockery::mock(\WC_Session::class); $woocommerce->session = $session; $session->shouldReceive('get'); + $session->shouldReceive('set'); $result = $testee->process_payment($orderId); @@ -164,6 +166,12 @@ class WcGatewayTest extends TestCase $testee = $this->createGateway(); + $woocommerce = Mockery::mock(\WooCommerce::class); + $session = Mockery::mock(\WC_Session::class); + when('WC')->justReturn($woocommerce); + $woocommerce->session = $session; + $session->shouldReceive('set')->andReturn([]); + expect('wc_get_order') ->with($orderId) ->andReturn(false); @@ -227,6 +235,7 @@ class WcGatewayTest extends TestCase $session = Mockery::mock(\WC_Session::class); $woocommerce->session = $session; $session->shouldReceive('get'); + $session->shouldReceive('set'); $result = $testee->process_payment($orderId);