Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves PayPal Express redirect - Issues #368 #370

Merged
merged 1 commit into from
Sep 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,19 @@ 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);

if (model.CurrentOrder.CustomProperties["ViaCheckout"] != null
&& model.CurrentOrder.CustomProperties["ViaCheckout"].Value == "1")
{
SavePaymentInfo(model);
ProcessOrder(model);
var redirectUrl = ProcessOrder(model);
if (redirectUrl != null)
return redirectUrl;
}

return View(model);
Expand All @@ -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);

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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)
Expand Down