diff --git a/modules/ppcp-subscription/services.php b/modules/ppcp-subscription/services.php index dbd78239a..b4f25c52d 100644 --- a/modules/ppcp-subscription/services.php +++ b/modules/ppcp-subscription/services.php @@ -23,12 +23,14 @@ return array( $endpoint = $container->get( 'api.endpoint.order' ); $purchase_unit_factory = $container->get( 'api.factory.purchase-unit' ); $payer_factory = $container->get( 'api.factory.payer' ); + $environment = $container->get( 'onboarding.environment' ); return new RenewalHandler( $logger, $repository, $endpoint, $purchase_unit_factory, - $payer_factory + $payer_factory, + $environment ); }, 'subscription.repository.payment-token' => static function ( ContainerInterface $container ): PaymentTokenRepository { diff --git a/modules/ppcp-subscription/src/RenewalHandler.php b/modules/ppcp-subscription/src/RenewalHandler.php index 7451dee9d..e2815baf6 100644 --- a/modules/ppcp-subscription/src/RenewalHandler.php +++ b/modules/ppcp-subscription/src/RenewalHandler.php @@ -10,21 +10,26 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\Subscription; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint; -use WooCommerce\PayPalCommerce\ApiClient\Entity\Order; -use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus; use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken; use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory; use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory; +use WooCommerce\PayPalCommerce\Onboarding\Environment; use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenRepository; -use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway; use Psr\Log\LoggerInterface; use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor; +use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderMetaTrait; +use WooCommerce\PayPalCommerce\WcGateway\Processor\PaymentsStatusHandlingTrait; +use WooCommerce\PayPalCommerce\WcGateway\Processor\TransactionIdHandlingTrait; /** * Class RenewalHandler */ class RenewalHandler { + use OrderMetaTrait; + use TransactionIdHandlingTrait; + use PaymentsStatusHandlingTrait; + /** * The logger. * @@ -60,6 +65,13 @@ class RenewalHandler { */ private $payer_factory; + /** + * The environment. + * + * @var Environment + */ + protected $environment; + /** * RenewalHandler constructor. * @@ -68,13 +80,15 @@ class RenewalHandler { * @param OrderEndpoint $order_endpoint The order endpoint. * @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory. * @param PayerFactory $payer_factory The payer factory. + * @param Environment $environment The environment. */ public function __construct( LoggerInterface $logger, PaymentTokenRepository $repository, OrderEndpoint $order_endpoint, PurchaseUnitFactory $purchase_unit_factory, - PayerFactory $payer_factory + PayerFactory $payer_factory, + Environment $environment ) { $this->logger = $logger; @@ -82,6 +96,7 @@ class RenewalHandler { $this->order_endpoint = $order_endpoint; $this->purchase_unit_factory = $purchase_unit_factory; $this->payer_factory = $payer_factory; + $this->environment = $environment; } /** @@ -135,10 +150,19 @@ class RenewalHandler { $token ); + $this->add_paypal_meta( $wc_order, $order, $this->environment ); + if ( $order->intent() === 'AUTHORIZE' ) { - $this->order_endpoint->authorize( $order ); + $order = $this->order_endpoint->authorize( $order ); $wc_order->update_meta_data( AuthorizedPaymentsProcessor::CAPTURED_META_KEY, 'false' ); } + + $transaction_id = $this->get_paypal_order_transaction_id( $order ); + if ( $transaction_id ) { + $this->update_transaction_id( $transaction_id, $wc_order ); + } + + $this->handle_new_order_status( $order, $wc_order ); } /**