diff --git a/modules/ppcp-vaulting/src/PaymentTokenChecker.php b/modules/ppcp-vaulting/src/PaymentTokenChecker.php index 8d922ef60..ff3b4d26d 100644 --- a/modules/ppcp-vaulting/src/PaymentTokenChecker.php +++ b/modules/ppcp-vaulting/src/PaymentTokenChecker.php @@ -20,7 +20,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\Order; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway; use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor; use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; -use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException; /** * Class PaymentTokenChecker @@ -98,17 +97,18 @@ class PaymentTokenChecker { /** * Check if payment token exist and updates order accordingly. * - * @param int $order_id The order ID. - * @param int $customer_id The customer ID. + * @param int $order_id The order ID. + * @param int $customer_id The customer ID. + * @param string $intent The intent from settings when order was created. * @return void */ - public function check_and_update( int $order_id, int $customer_id ):void { + public function check_and_update( int $order_id, int $customer_id, string $intent ):void { $wc_order = wc_get_order( $order_id ); if ( ! is_a( $wc_order, WC_Order::class ) ) { return; } - if ( $wc_order->get_status() === 'processing' ) { + if ( $wc_order->get_status() === 'processing' || 'capture' !== $intent ) { return; } diff --git a/modules/ppcp-vaulting/src/VaultingModule.php b/modules/ppcp-vaulting/src/VaultingModule.php index 06ee15364..636ac06ba 100644 --- a/modules/ppcp-vaulting/src/VaultingModule.php +++ b/modules/ppcp-vaulting/src/VaultingModule.php @@ -132,12 +132,12 @@ class VaultingModule implements ModuleInterface { add_action( 'woocommerce_paypal_payments_check_saved_payment', - function ( int $order_id, int $customer_id ) use ( $container ) { + function ( int $order_id, int $customer_id, string $intent ) use ( $container ) { $payment_token_checker = $container->get( 'vaulting.payment-token-checker' ); - $payment_token_checker->check_and_update( $order_id, $customer_id ); + $payment_token_checker->check_and_update( $order_id, $customer_id, $intent ); }, 10, - 2 + 3 ); } diff --git a/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php b/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php index 88f5fb01b..814b2cae8 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php +++ b/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php @@ -178,6 +178,7 @@ trait ProcessPaymentTrait { array( 'order_id' => $order_id, 'customer_id' => $wc_order->get_customer_id(), + 'intent' => $this->config->has( 'intent' ) ? $this->config->get( 'intent' ) : '', ) ); }