mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Check for captured vault webhook order meta
This commit is contained in:
parent
572c62c74c
commit
465855d061
5 changed files with 24 additions and 10 deletions
|
@ -215,6 +215,7 @@ return array(
|
||||||
$settings = $container->get( 'wcgateway.settings' );
|
$settings = $container->get( 'wcgateway.settings' );
|
||||||
$environment = $container->get( 'onboarding.environment' );
|
$environment = $container->get( 'onboarding.environment' );
|
||||||
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
||||||
|
$subscription_helper = $container->get( 'subscription.helper' );
|
||||||
return new OrderProcessor(
|
return new OrderProcessor(
|
||||||
$session_handler,
|
$session_handler,
|
||||||
$order_endpoint,
|
$order_endpoint,
|
||||||
|
@ -223,7 +224,8 @@ return array(
|
||||||
$authorized_payments_processor,
|
$authorized_payments_processor,
|
||||||
$settings,
|
$settings,
|
||||||
$logger,
|
$logger,
|
||||||
$environment
|
$environment,
|
||||||
|
$subscription_helper
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'wcgateway.processor.refunds' => static function ( ContainerInterface $container ): RefundProcessor {
|
'wcgateway.processor.refunds' => static function ( ContainerInterface $container ): RefundProcessor {
|
||||||
|
|
|
@ -172,10 +172,6 @@ trait ProcessPaymentTrait {
|
||||||
try {
|
try {
|
||||||
if ( $this->order_processor->process( $wc_order ) ) {
|
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();
|
WC()->cart->empty_cart();
|
||||||
$this->session_handler->destroy_session_data();
|
$this->session_handler->destroy_session_data();
|
||||||
|
|
||||||
|
|
|
@ -217,9 +217,12 @@ class AuthorizedPaymentsProcessor {
|
||||||
|
|
||||||
if ($this->config->has('intent') && strtoupper((string)$this->config->get('intent')) === 'CAPTURE') {
|
if ($this->config->has('intent') && strtoupper((string)$this->config->get('intent')) === 'CAPTURE') {
|
||||||
foreach ($wc_orders as $wc_order) {
|
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);
|
$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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\OrderFactory;
|
||||||
use WooCommerce\PayPalCommerce\Button\Helper\ThreeDSecure;
|
use WooCommerce\PayPalCommerce\Button\Helper\ThreeDSecure;
|
||||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||||
|
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
|
||||||
use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenRepository;
|
use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenRepository;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||||
|
@ -98,6 +99,11 @@ class OrderProcessor {
|
||||||
*/
|
*/
|
||||||
private $logger;
|
private $logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var SubscriptionHelper
|
||||||
|
*/
|
||||||
|
private $subscription_helper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OrderProcessor constructor.
|
* OrderProcessor constructor.
|
||||||
*
|
*
|
||||||
|
@ -118,7 +124,8 @@ class OrderProcessor {
|
||||||
AuthorizedPaymentsProcessor $authorized_payments_processor,
|
AuthorizedPaymentsProcessor $authorized_payments_processor,
|
||||||
Settings $settings,
|
Settings $settings,
|
||||||
LoggerInterface $logger,
|
LoggerInterface $logger,
|
||||||
Environment $environment
|
Environment $environment,
|
||||||
|
SubscriptionHelper $subscription_helper
|
||||||
) {
|
) {
|
||||||
|
|
||||||
$this->session_handler = $session_handler;
|
$this->session_handler = $session_handler;
|
||||||
|
@ -129,6 +136,7 @@ class OrderProcessor {
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
$this->environment = $environment;
|
$this->environment = $environment;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
|
$this->subscription_helper = $subscription_helper;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -172,6 +180,10 @@ class OrderProcessor {
|
||||||
$order = $this->order_endpoint->authorize( $order );
|
$order = $this->order_endpoint->authorize( $order );
|
||||||
|
|
||||||
$wc_order->update_meta_data( AuthorizedPaymentsProcessor::CAPTURED_META_KEY, 'false' );
|
$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 );
|
$transaction_id = $this->get_paypal_order_transaction_id( $order );
|
||||||
|
|
|
@ -53,7 +53,7 @@ class VaultPaymentTokenCreated implements RequestHandler
|
||||||
$response = array( 'success' => false );
|
$response = array( 'success' => false );
|
||||||
$webhook_id = (string) ( $request['id'] ?? '' );
|
$webhook_id = (string) ( $request['id'] ?? '' );
|
||||||
|
|
||||||
$customer_id = $request['customer_id'] ?? '';
|
$customer_id = $request['resource']['customer_id'] ?? '';
|
||||||
if(!$customer_id) {
|
if(!$customer_id) {
|
||||||
$message = sprintf( 'No customer id for webhook event %s was found.', $webhook_id );
|
$message = sprintf( 'No customer id for webhook event %s was found.', $webhook_id );
|
||||||
$this->logger->warning( $message, array( 'request' => $request ) );
|
$this->logger->warning( $message, array( 'request' => $request ) );
|
||||||
|
@ -62,7 +62,8 @@ class VaultPaymentTokenCreated implements RequestHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
$customer_id_parts = explode('-', $customer_id);
|
$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;
|
$response['success'] = true;
|
||||||
return rest_ensure_response($response);
|
return rest_ensure_response($response);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue