Save the session data before proceeding with order payment (#40964)

* Save the session early before proceeding with order payment.

As part of the checkout process an order is created and the order id
is stored in a session variable right before requesting payment
processing to the appropriate payment gateway. Thus if the payment
fails and the user submits the order again, the order id will be
picked from the session so the existing order can be retrieved and
updated.

However if the payment process hangs (instead of returning an error)
and the request never finishes the session data will never actually
be sorted, and the next time the user submits the order a duplicate
of the first order will be created.

This commit simply does WC()->session->save_data() after the
WC()->session->set that stores the order id, so that the session is
effectively updated even if the request hangs.

* Add changelog file
This commit is contained in:
Néstor Soriano 2023-10-24 16:38:39 +02:00 committed by GitHub
parent 82b90d07ec
commit eafc87b453
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Save the session data before proceeding with order payment

View File

@ -1046,6 +1046,11 @@ class WC_Checkout {
// Store Order ID in session so it can be re-used after payment failure.
WC()->session->set( 'order_awaiting_payment', $order_id );
// We save the session early because if the payment gateway hangs
// the request will never finish, thus the session data will neved be saved,
// and this can lead to duplicate orders if the user submits the order again.
WC()->session->save_data();
// Process Payment.
$result = $available_gateways[ $payment_method ]->process_payment( $order_id );