Merge branch 'trunk' into PCP-1970-unify-conditional-display-logic-for-plugin-settings

# Conflicts:
#	modules/ppcp-wc-gateway/resources/js/SettingsHandler/SubElementsHandler.js
This commit is contained in:
Pedro Silva 2023-09-19 09:45:35 +01:00
commit a9766c01e1
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3
6 changed files with 39 additions and 5 deletions

View file

@ -180,10 +180,7 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
'products', 'products',
); );
if ( if ( $this->config->has( 'vault_enabled_dcc' ) && $this->config->get( 'vault_enabled_dcc' ) ) {
( $this->config->has( 'vault_enabled_dcc' ) && $this->config->get( 'vault_enabled_dcc' ) )
|| ( $this->config->has( 'subscriptions_mode' ) && $this->config->get( 'subscriptions_mode' ) === 'subscriptions_api' )
) {
array_push( array_push(
$this->supports, $this->supports,
'subscriptions', 'subscriptions',

View file

@ -543,6 +543,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
} }
$wc_order->payment_complete(); $wc_order->payment_complete();
return $this->handle_payment_success( $wc_order ); return $this->handle_payment_success( $wc_order );
} }

View file

@ -77,6 +77,7 @@ trait ProcessPaymentTrait {
} }
$this->session_handler->destroy_session_data(); $this->session_handler->destroy_session_data();
WC()->session->set( 'ppcp_subscription_id', '' );
wc_add_notice( $error->getMessage(), 'error' ); wc_add_notice( $error->getMessage(), 'error' );
@ -100,6 +101,7 @@ trait ProcessPaymentTrait {
} }
$this->session_handler->destroy_session_data(); $this->session_handler->destroy_session_data();
WC()->session->set( 'ppcp_subscription_id', '' );
return array( return array(
'result' => 'success', 'result' => 'success',

View file

@ -340,7 +340,20 @@ class SettingsListener {
* phpcs:disable WordPress.Security.NonceVerification.Missing * phpcs:disable WordPress.Security.NonceVerification.Missing
* phpcs:disable WordPress.Security.NonceVerification.Recommended * 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; return;
} }

View file

@ -78,6 +78,12 @@ class CreditCardGatewayTest extends TestCase
$wc_order = Mockery::mock(WC_Order::class); $wc_order = Mockery::mock(WC_Order::class);
when('wc_get_order')->justReturn($wc_order); 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') $this->orderProcessor->shouldReceive('process')
->with($wc_order) ->with($wc_order)
->andReturn(true); ->andReturn(true);
@ -95,6 +101,12 @@ class CreditCardGatewayTest extends TestCase
$wc_order->shouldReceive('get_customer_id')->andReturn(1); $wc_order->shouldReceive('get_customer_id')->andReturn(1);
when('wc_get_order')->justReturn($wc_order); 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'; $savedCreditCard = 'abc123';
$_POST['saved_credit_card'] = $savedCreditCard; $_POST['saved_credit_card'] = $savedCreditCard;

View file

@ -147,9 +147,11 @@ class WcGatewayTest extends TestCase
when('WC')->justReturn($woocommerce); when('WC')->justReturn($woocommerce);
$woocommerce->cart = $cart; $woocommerce->cart = $cart;
$cart->shouldReceive('empty_cart'); $cart->shouldReceive('empty_cart');
$session = Mockery::mock(\WC_Session::class); $session = Mockery::mock(\WC_Session::class);
$woocommerce->session = $session; $woocommerce->session = $session;
$session->shouldReceive('get'); $session->shouldReceive('get');
$session->shouldReceive('set');
$result = $testee->process_payment($orderId); $result = $testee->process_payment($orderId);
@ -164,6 +166,12 @@ class WcGatewayTest extends TestCase
$testee = $this->createGateway(); $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') expect('wc_get_order')
->with($orderId) ->with($orderId)
->andReturn(false); ->andReturn(false);
@ -227,6 +235,7 @@ class WcGatewayTest extends TestCase
$session = Mockery::mock(\WC_Session::class); $session = Mockery::mock(\WC_Session::class);
$woocommerce->session = $session; $woocommerce->session = $session;
$session->shouldReceive('get'); $session->shouldReceive('get');
$session->shouldReceive('set');
$result = $testee->process_payment($orderId); $result = $testee->process_payment($orderId);