From 572c62c74c8d1e34be79355cecaf38fc667e1c21 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 20 Dec 2021 15:34:55 +0100 Subject: [PATCH] Check for captured vault webhook order meta --- modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php | 5 +++++ .../src/Processor/AuthorizedPaymentsProcessor.php | 3 ++- .../ppcp-webhooks/src/Handler/VaultPaymentTokenCreated.php | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php b/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php index abf1e7b34..c36499c4e 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php +++ b/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php @@ -171,6 +171,11 @@ trait ProcessPaymentTrait { try { if ( $this->order_processor->process( $wc_order ) ) { + + if($this->subscription_helper->has_subscription( $wc_order->get_id() )) { + $wc_order->update_meta_data('_ppcp_captured_vault_webhook', false); + } + WC()->cart->empty_cart(); $this->session_handler->destroy_session_data(); diff --git a/modules/ppcp-wc-gateway/src/Processor/AuthorizedPaymentsProcessor.php b/modules/ppcp-wc-gateway/src/Processor/AuthorizedPaymentsProcessor.php index 345d8ab8b..a3c902481 100644 --- a/modules/ppcp-wc-gateway/src/Processor/AuthorizedPaymentsProcessor.php +++ b/modules/ppcp-wc-gateway/src/Processor/AuthorizedPaymentsProcessor.php @@ -217,8 +217,9 @@ class AuthorizedPaymentsProcessor { if ($this->config->has('intent') && strtoupper((string)$this->config->get('intent')) === 'CAPTURE') { foreach ($wc_orders as $wc_order) { - if( $this->subscription_helper->has_subscription( $wc_order->get_id() ) ) { + if( $this->subscription_helper->has_subscription( $wc_order->get_id() ) && $wc_order->get_meta( '_ppcp_captured_vault_webhook' ) === false ) { $this->capture_authorized_payment($wc_order); + $wc_order->update_meta_data('_ppcp_captured_vault_webhook', true); } } } diff --git a/modules/ppcp-webhooks/src/Handler/VaultPaymentTokenCreated.php b/modules/ppcp-webhooks/src/Handler/VaultPaymentTokenCreated.php index 24f84705e..49cd07232 100644 --- a/modules/ppcp-webhooks/src/Handler/VaultPaymentTokenCreated.php +++ b/modules/ppcp-webhooks/src/Handler/VaultPaymentTokenCreated.php @@ -53,7 +53,7 @@ class VaultPaymentTokenCreated implements RequestHandler $response = array( 'success' => false ); $webhook_id = (string) ( $request['id'] ?? '' ); - $customer_id = $resource['customer_id'] ?? ''; + $customer_id = $request['customer_id'] ?? ''; if(!$customer_id) { $message = sprintf( 'No customer id for webhook event %s was found.', $webhook_id ); $this->logger->warning( $message, array( 'request' => $request ) );