Skip to content

Commit dc94d85

Browse files
authored
Redirect to correct page when payment fails (#3682)
* Redirect to correct page when payment fails * Add changelog and readme entries * Switch to flags instead of actual URLs * Feedback: simplify by using boolean flag
1 parent 00da47f commit dc94d85

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Changelog ***
22

33
= 9.1.0 - xxxx-xx-xx =
4+
* Fix - Return to the correct page when redirect-based payment method fails.
45
* Fix - Show default recipient for Payment Authentication Requested email.
56
* Fix - Correctly handles IPP failed payments webhook calls by extracting the order ID from the payment intent metadata.
67
* Fix - Fix ECE crash in classic cart and checkout pages for non-English language sites.

includes/payment-methods/class-wc-stripe-upe-payment-gateway.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,12 @@ public function maybe_process_upe_redirect() {
11961196
return;
11971197
}
11981198

1199-
$this->process_upe_redirect_payment( $order_id, $intent_id, $save_payment_method );
1199+
$this->process_upe_redirect_payment(
1200+
$order_id,
1201+
$intent_id,
1202+
$save_payment_method,
1203+
isset( $_GET['pay_for_order'] ) && 'yes' === $_GET['pay_for_order']
1204+
);
12001205
}
12011206

12021207
/**
@@ -1246,11 +1251,12 @@ private function is_order_associated_to_setup_intent( int $order_id, string $int
12461251
* @param int $order_id The order ID being processed.
12471252
* @param string $intent_id The Stripe setup/payment intent ID for the order payment.
12481253
* @param bool $save_payment_method Boolean representing whether payment method for order should be saved.
1254+
* @param bool $is_pay_for_order True if processing payment from Pay for Order page. Optional.
12491255
*
12501256
* @since 5.5.0
12511257
* @version 5.5.0
12521258
*/
1253-
public function process_upe_redirect_payment( $order_id, $intent_id, $save_payment_method ) {
1259+
public function process_upe_redirect_payment( $order_id, $intent_id, $save_payment_method, $is_pay_for_order = false ) {
12541260
$order = wc_get_order( $order_id );
12551261

12561262
if ( ! is_object( $order ) ) {
@@ -1276,7 +1282,15 @@ public function process_upe_redirect_payment( $order_id, $intent_id, $save_payme
12761282
$order->update_status( 'failed', sprintf( __( 'UPE payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) );
12771283

12781284
wc_add_notice( $e->getMessage(), 'error' );
1279-
wp_safe_redirect( wc_get_checkout_url() );
1285+
1286+
$redirect_url = '';
1287+
if ( $is_pay_for_order ) {
1288+
$redirect_url = $order->get_checkout_payment_url();
1289+
} else {
1290+
$redirect_url = wc_get_checkout_url();
1291+
}
1292+
wp_safe_redirect( wp_sanitize_redirect( $redirect_url ) );
1293+
12801294
exit;
12811295
}
12821296
}
@@ -2384,6 +2398,7 @@ private function get_return_url_for_redirect( $order, $save_payment_method ) {
23842398
'wc_payment_method' => self::ID,
23852399
'_wpnonce' => wp_create_nonce( 'wc_stripe_process_redirect_order_nonce' ),
23862400
'save_payment_method' => $save_payment_method ? 'yes' : 'no',
2401+
'pay_for_order' => parent::is_valid_pay_for_order_endpoint() ? 'yes' : 'no',
23872402
],
23882403
$this->get_return_url( $order )
23892404
)

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
111111
== Changelog ==
112112

113113
= 9.1.0 - xxxx-xx-xx =
114+
* Fix - Return to the correct page when redirect-based payment method fails.
114115
* Fix - Show default recipient for Payment Authentication Requested email.
115116
* Fix - Correctly handles IPP failed payments webhook calls by extracting the order ID from the payment intent metadata.
116117
* Fix - Fix ECE crash in classic cart and checkout pages for non-English language sites.

0 commit comments

Comments
 (0)