Merge PCP-412-when-there-is-a-payment-saved-th

This commit is contained in:
dinamiko 2022-03-02 12:23:20 +01:00
commit 5d7de0a212
11 changed files with 212 additions and 14 deletions

View file

@ -216,6 +216,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,
@ -224,7 +225,8 @@ return array(
$authorized_payments_processor,
$settings,
$logger,
$environment
$environment,
$subscription_helper
);
},
'wcgateway.processor.refunds' => static function ( ContainerInterface $container ): RefundProcessor {
@ -238,7 +240,16 @@ return array(
$payments_endpoint = $container->get( 'api.endpoint.payments' );
$logger = $container->get( 'woocommerce.logger.woocommerce' );
$notice = $container->get( 'wcgateway.notice.authorize-order-action' );
return new AuthorizedPaymentsProcessor( $order_endpoint, $payments_endpoint, $logger, $notice );
$settings = $container->get( 'wcgateway.settings' );
$subscription_helper = $container->get( 'subscription.helper' );
return new AuthorizedPaymentsProcessor(
$order_endpoint,
$payments_endpoint,
$logger,
$notice,
$settings,
$subscription_helper
);
},
'wcgateway.admin.render-authorize-action' => static function ( ContainerInterface $container ): RenderAuthorizeAction {
$column = $container->get( 'wcgateway.admin.orders-payment-status-column' );

View file

@ -10,8 +10,6 @@ declare( strict_types=1 );
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway;
use Exception;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Authorization;
use WooCommerce\PayPalCommerce\ApiClient\Entity\AuthorizationStatus;
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;

View file

@ -10,6 +10,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway\Processor;
use Exception;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use WC_Order;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
@ -20,6 +21,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\Capture;
use WooCommerce\PayPalCommerce\ApiClient\Entity\CaptureStatus;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
@ -74,6 +76,18 @@ class AuthorizedPaymentsProcessor {
*/
private $notice;
/**
* The settings.
*
* @var ContainerInterface
*/
private $config;
/**
* @var SubscriptionHelper
*/
private $subscription_helper;
/**
* AuthorizedPaymentsProcessor constructor.
*
@ -81,18 +95,23 @@ class AuthorizedPaymentsProcessor {
* @param PaymentsEndpoint $payments_endpoint The Payments endpoint.
* @param LoggerInterface $logger The logger.
* @param AuthorizeOrderActionNotice $notice The notice.
* @param ContainerInterface $config The settings.
*/
public function __construct(
OrderEndpoint $order_endpoint,
PaymentsEndpoint $payments_endpoint,
LoggerInterface $logger,
AuthorizeOrderActionNotice $notice
AuthorizeOrderActionNotice $notice,
ContainerInterface $config,
SubscriptionHelper $subscription_helper
) {
$this->order_endpoint = $order_endpoint;
$this->payments_endpoint = $payments_endpoint;
$this->logger = $logger;
$this->notice = $notice;
$this->config = $config;
$this->subscription_helper = $subscription_helper;
}
/**
@ -190,6 +209,27 @@ class AuthorizedPaymentsProcessor {
return false;
}
public function capture_authorized_payments_for_customer(int $customer_id) {
$wc_orders = wc_get_orders(array(
'customer_id' => $customer_id,
'status' => array('wc-on-hold'),
'limit' => -1,
));
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'
) {
$this->capture_authorized_payment($wc_order);
$wc_order->update_meta_data('_ppcp_captured_vault_webhook', 'true');
}
}
}
}
/**
* Displays the notice for a status.
*

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;
}
/**
@ -173,6 +181,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 );