Check for captured vault webhook order meta

This commit is contained in:
dinamiko 2021-12-22 12:18:17 +01:00
parent 572c62c74c
commit 465855d061
5 changed files with 24 additions and 10 deletions

View file

@ -215,6 +215,7 @@ return array(
$settings = $container->get( 'wcgateway.settings' );
$environment = $container->get( 'onboarding.environment' );
$logger = $container->get( 'woocommerce.logger.woocommerce' );
$subscription_helper = $container->get( 'subscription.helper' );
return new OrderProcessor(
$session_handler,
$order_endpoint,
@ -223,7 +224,8 @@ return array(
$authorized_payments_processor,
$settings,
$logger,
$environment
$environment,
$subscription_helper
);
},
'wcgateway.processor.refunds' => static function ( ContainerInterface $container ): RefundProcessor {

View file

@ -172,10 +172,6 @@ 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();

View file

@ -217,9 +217,12 @@ 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() ) && $wc_order->get_meta( '_ppcp_captured_vault_webhook' ) === false ) {
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);
$wc_order->update_meta_data('_ppcp_captured_vault_webhook', 'true');
}
}
}

View file

@ -17,6 +17,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\OrderFactory;
use WooCommerce\PayPalCommerce\Button\Helper\ThreeDSecure;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Session\SessionHandler;
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenRepository;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
@ -98,6 +99,11 @@ class OrderProcessor {
*/
private $logger;
/**
* @var SubscriptionHelper
*/
private $subscription_helper;
/**
* OrderProcessor constructor.
*
@ -118,7 +124,8 @@ class OrderProcessor {
AuthorizedPaymentsProcessor $authorized_payments_processor,
Settings $settings,
LoggerInterface $logger,
Environment $environment
Environment $environment,
SubscriptionHelper $subscription_helper
) {
$this->session_handler = $session_handler;
@ -129,6 +136,7 @@ class OrderProcessor {
$this->settings = $settings;
$this->environment = $environment;
$this->logger = $logger;
$this->subscription_helper = $subscription_helper;
}
/**
@ -172,6 +180,10 @@ class OrderProcessor {
$order = $this->order_endpoint->authorize( $order );
$wc_order->update_meta_data( AuthorizedPaymentsProcessor::CAPTURED_META_KEY, 'false' );
if($this->subscription_helper->has_subscription( $wc_order->get_id() )) {
$wc_order->update_meta_data('_ppcp_captured_vault_webhook', 'false');
}
}
$transaction_id = $this->get_paypal_order_transaction_id( $order );

View file

@ -53,7 +53,7 @@ class VaultPaymentTokenCreated implements RequestHandler
$response = array( 'success' => false );
$webhook_id = (string) ( $request['id'] ?? '' );
$customer_id = $request['customer_id'] ?? '';
$customer_id = $request['resource']['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 ) );
@ -62,7 +62,8 @@ class VaultPaymentTokenCreated implements RequestHandler
}
$customer_id_parts = explode('-', $customer_id);
$this->authorized_payments_processor->capture_authorized_payments_for_customer((int) end($customer_id_parts));
$wc_customer_id = (int) end($customer_id_parts);
$this->authorized_payments_processor->capture_authorized_payments_for_customer($wc_customer_id);
$response['success'] = true;
return rest_ensure_response($response);