diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php index 076caa260..b153da161 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php @@ -180,6 +180,14 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway { $order = $this->order_endpoint->create( array( $purchase_unit ), $payment_source ); $this->add_paypal_meta( $wc_order, $order, $this->environment ); + as_schedule_single_action( + time() + ( 5 * MINUTE_IN_SECONDS ), + 'woocommerce_paypal_payments_check_pui_payment_captured', + array( + 'order_id' => $order_id, + ) + ); + WC()->cart->empty_cart(); return array( diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php index 4fe5a43ca..f7f3ebbaf 100644 --- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php +++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php @@ -194,6 +194,22 @@ class WCGatewayModule implements ModuleInterface { } } ); + + add_action( + 'woocommerce_paypal_payments_check_pui_payment_captured', + function ( int $order_id ) { + $wc_order = wc_get_order( $order_id ); + if ( ! is_a( $wc_order, WC_Order::class ) || $wc_order->get_status() !== 'on-hold' ) { + return; + } + + $message = __( + 'Could not process order because PAYMENT.CAPTURE.COMPLETED webhook not received.', + 'woocommerce-paypal-payments' + ); + $wc_order->update_status( 'failed', $message ); + } + ); } /** diff --git a/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php b/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php index 5b7db8899..4faabb68b 100644 --- a/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php +++ b/tests/PHPUnit/WcGateway/Gateway/PayUponInvoice/PayUponInvoiceGatewayTest.php @@ -53,6 +53,9 @@ class PayUponInvoiceGatewayTest extends TestCase $payment_source )->andReturn($order); + define( 'MINUTE_IN_SECONDS', 60 ); + when('as_schedule_single_action')->justReturn(); + $result = $this->testee->process_payment(1); $this->assertEquals('success', $result['result']); }