mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Add scheduled action for checking payment captured
This commit is contained in:
parent
df549b6dff
commit
d064c257db
3 changed files with 27 additions and 0 deletions
|
@ -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(
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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']);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue