From 24aea214a7c5767b77a68451c64cc09464df666a Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Thu, 7 Sep 2023 13:36:14 +0800 Subject: [PATCH 1/3] Potentially fix #3265 --- src/controllers/PaymentsController.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/controllers/PaymentsController.php b/src/controllers/PaymentsController.php index 1e9504cc4c..8488d90f5f 100644 --- a/src/controllers/PaymentsController.php +++ b/src/controllers/PaymentsController.php @@ -455,6 +455,7 @@ public function actionPay(): ?Response ); } + $redirect = ($redirect ?: null) ?? $order->returnUrl ?? $this->getPostedRedirectUrl($order); if ($this->request->getAcceptsJson()) { return $this->asModelSuccess( @@ -472,15 +473,7 @@ public function actionPay(): ?Response ); } - if ($redirect) { - return $this->redirect($redirect); - } - - if ($order->returnUrl) { - return $this->redirect($order->returnUrl); - } - - return $this->redirectToPostedUrl($order); + return $this->redirect($redirect); } /** From 5c35f5b6b4f65e315dd5822a65b6a508ecb155fd Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Tue, 17 Oct 2023 17:20:37 +0800 Subject: [PATCH 2/3] Cleanup --- src/controllers/PaymentsController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/controllers/PaymentsController.php b/src/controllers/PaymentsController.php index f15ad0dd22..e767fddc8d 100644 --- a/src/controllers/PaymentsController.php +++ b/src/controllers/PaymentsController.php @@ -457,7 +457,11 @@ public function actionPay(): ?Response ); } - $redirect = ($redirect ?: null) ?? $order->returnUrl ?? $this->getPostedRedirectUrl($order); + // If the gateway did not give us a redirect URL, use the order's return URL. + if (!$redirect) { + // Can be set from the redirect body param + $redirect = $order->returnUrl; + } if ($this->request->getAcceptsJson()) { return $this->asModelSuccess( From 21e3a107443998dbbd52fd357c7e6194f7f400fe Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Tue, 17 Oct 2023 17:22:47 +0800 Subject: [PATCH 3/3] Release notes --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9cf19e41e..e57e7a2728 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Fixed an error that could occur when rendering a PDF. ([#2633](https://github.com/craftcms/commerce/issues/2633)) - Fixed a bug where Sale’s and Discount’s date audit columns weren’t populated after saving. ([#3298](https://github.com/craftcms/commerce/issues/3298)) - Fixed a bug where duplicate inactive users could be created when using the `commerce/upgrade` command. ([#3286](https://github.com/craftcms/commerce/issues/3286)) +- Fixed a bug where the `commerce/payments/pay` action was missing the `redirect` in JSON responses. ([#3265](https://github.com/craftcms/commerce/issues/3265)) - The order param is now included when triggering the `craft\commerce\services\Purchasables::EVENT_PURCHASABLE_SHIPPABLE` event. ([#3279](https://github.com/craftcms/commerce/pull/3279)) - The auto-generated variant titles and SKUs are now generated when before saving a product in addition to before validation. ((#3297)[https://github.com/craftcms/commerce/pull/3297])