Add scheduled action for checking payment captured

This commit is contained in:
dinamiko 2022-05-04 09:44:15 +02:00
parent df549b6dff
commit d064c257db
3 changed files with 27 additions and 0 deletions

View file

@ -180,6 +180,14 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
$order = $this->order_endpoint->create( array( $purchase_unit ), $payment_source ); $order = $this->order_endpoint->create( array( $purchase_unit ), $payment_source );
$this->add_paypal_meta( $wc_order, $order, $this->environment ); $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(); WC()->cart->empty_cart();
return array( return array(

View file

@ -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 );
}
);
} }
/** /**

View file

@ -53,6 +53,9 @@ class PayUponInvoiceGatewayTest extends TestCase
$payment_source $payment_source
)->andReturn($order); )->andReturn($order);
define( 'MINUTE_IN_SECONDS', 60 );
when('as_schedule_single_action')->justReturn();
$result = $this->testee->process_payment(1); $result = $this->testee->process_payment(1);
$this->assertEquals('success', $result['result']); $this->assertEquals('success', $result['result']);
} }