From 3f8453d5955b8428bd02aa8efa8369631f682501 Mon Sep 17 00:00:00 2001 From: Erwin Yulianto Date: Sat, 11 Sep 2021 22:57:55 +0700 Subject: [PATCH] Resolves PayPal Express redirect --- .../PayPalExpressCheckoutController.cs | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Website/DesktopModules/Hotcakes/Core/Controllers/PayPalExpressCheckoutController.cs b/Website/DesktopModules/Hotcakes/Core/Controllers/PayPalExpressCheckoutController.cs index 5403d6a5e..e77c74f9a 100644 --- a/Website/DesktopModules/Hotcakes/Core/Controllers/PayPalExpressCheckoutController.cs +++ b/Website/DesktopModules/Hotcakes/Core/Controllers/PayPalExpressCheckoutController.cs @@ -49,6 +49,9 @@ public class PayPalExpressCheckoutController : BaseStoreController public ActionResult Index() { var model = IndexSetup(); + if (string.IsNullOrEmpty(model.PayPalToken)) + return Redirect(Url.RouteHccUrl(HccRoute.Cart)); + DisplayPaypalExpressMode(model); LoadValuesFromForm(model); @@ -56,7 +59,9 @@ public ActionResult Index() && model.CurrentOrder.CustomProperties["ViaCheckout"].Value == "1") { SavePaymentInfo(model); - ProcessOrder(model); + var redirectUrl = ProcessOrder(model); + if (redirectUrl != null) + return redirectUrl; } return View(model); @@ -68,6 +73,9 @@ public ActionResult Index() public ActionResult IndexPost() { var model = IndexSetup(); + if (string.IsNullOrEmpty(model.PayPalToken)) + return Redirect(Url.RouteHccUrl(HccRoute.Cart)); + DisplayPaypalExpressMode(model); LoadValuesFromForm(model); @@ -77,7 +85,9 @@ public ActionResult IndexPost() // Save Payment Information SavePaymentInfo(model); - ProcessOrder(model); + var redirectUrl = ProcessOrder(model); + if (redirectUrl != null) + return redirectUrl; } // Render Error Summary foreach (var v in model.Violations) @@ -90,7 +100,7 @@ public ActionResult IndexPost() private CheckoutViewModel IndexSetup() { - var model = new CheckoutViewModel {CurrentOrder = CurrentCart}; + var model = new CheckoutViewModel { CurrentOrder = CurrentCart }; // Agree Checkbox if (HccApp.CurrentStore.Settings.ForceTermsAgreement) @@ -117,10 +127,6 @@ private void DisplayPaypalExpressMode(CheckoutViewModel model) model.PayPalToken = Request.QueryString["token"] ?? string.Empty; model.PayPalPayerId = Request.QueryString["payerId"] ?? string.Empty; - if (string.IsNullOrEmpty(model.PayPalToken)) - Redirect(Url.RouteHccUrl(HccRoute.Cart)); - - var ppAPI = PaypalExpressUtilities.GetPaypalAPI(HccApp.CurrentStore); var failed = false; GetExpressCheckoutDetailsResponseType ppResponse = null; @@ -257,7 +263,7 @@ private void LoadShippingMethodsForOrder(Order o) ViewBag.ShippingRates = HtmlRendering.ShippingRatesToRadioButtons(rates, 300, o.ShippingMethodUniqueKey); } - private void ProcessOrder(CheckoutViewModel model) + private RedirectResult ProcessOrder(CheckoutViewModel model) { HccApp.OrderServices.Orders.Update(model.CurrentOrder); @@ -280,10 +286,11 @@ private void ProcessOrder(CheckoutViewModel model) var tempOrder = HccApp.OrderServices.Orders.FindForCurrentStore(model.CurrentOrder.bvin); HccApp.CurrentRequestContext.IntegrationEvents.OrderReceived(tempOrder, HccApp); SessionManager.AnalyticsOrderId = model.CurrentOrder.bvin; - Redirect(Url.RouteHccUrl(HccRoute.Checkout, - new {action = "receipt", id = model.CurrentOrder.bvin})); + return Redirect(Url.RouteHccUrl(HccRoute.Checkout, + new { action = "receipt", id = model.CurrentOrder.bvin })); } } + return null; } private bool ValidatePage(CheckoutViewModel model)