Skip to content

Commit cd55dd5

Browse files
committed
Resolves smartstore#523 Redirecting to payment provider performed by core instead of plugin
1 parent fb832f9 commit cd55dd5

9 files changed

Lines changed: 44 additions & 87 deletions

File tree

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
* #725 Prevent LowestProductPrice being 0
2020
* #709 News feed produced invalid RSS feed. Added content:encoded. Added maximum news age setting for feed export.
2121

22+
### Bugfixes
23+
* #523 Redirecting to payment provider performed by core instead of plugin
24+
2225

2326
## SmartStore.NET 2.2.2
2427

src/Libraries/SmartStore.Core/IWebHelper.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,5 @@ public partial interface IWebHelper
118118
/// <param name="redirectUrl">Redirect URL; empty string if you want to redirect to the current page URL</param>
119119
/// <param name="aggressive">Usually <c>true</c> after a new plugin was installed (nukes the MVC cache)</param>
120120
void RestartAppDomain(bool makeRedirect = false, string redirectUrl = "", bool aggressive = false);
121-
122-
/// <summary>
123-
/// Gets a value that indicates whether the client is being redirected to a new location
124-
/// </summary>
125-
bool IsRequestBeingRedirected { get; }
126-
127-
/// <summary>
128-
/// Gets or sets a value that indicates whether the client is being redirected to a new location using POST
129-
/// </summary>
130-
bool IsPostBeingDone { get; set; }
131-
132121
}
133122
}

src/Libraries/SmartStore.Core/WebHelper.cs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -474,29 +474,6 @@ internal static bool OptimizedCompilationsEnabled
474474
}
475475
}
476476

477-
public virtual bool IsRequestBeingRedirected
478-
{
479-
get
480-
{
481-
var response = _httpContext.Response;
482-
return response.IsRequestBeingRedirected;
483-
}
484-
}
485-
486-
public virtual bool IsPostBeingDone
487-
{
488-
get
489-
{
490-
if (_httpContext.Items["sm.IsPOSTBeingDone"] == null)
491-
return false;
492-
return Convert.ToBoolean(_httpContext.Items["sm.IsPOSTBeingDone"]);
493-
}
494-
set
495-
{
496-
_httpContext.Items["sm.IsPOSTBeingDone"] = value;
497-
}
498-
}
499-
500477
/// <summary>
501478
/// Finds the trust level of the running application (http://blogs.msdn.com/dmitryr/archive/2007/01/23/finding-out-the-current-trust-level-in-asp-net.aspx)
502479
/// </summary>

src/Libraries/SmartStore.Services/Payments/PostProcessPaymentRequest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,10 @@ public partial class PostProcessPaymentRequest
1616
/// Whether the customer clicked the button to re-post the payment process
1717
/// </summary>
1818
public bool IsRePostProcessPayment { get; set; }
19+
20+
/// <summary>
21+
/// URL to a payment provider to fulfill the payment. The .NET core will redirect to it.
22+
/// </summary>
23+
public string RedirectUrl { get; set; }
1924
}
2025
}

src/Plugins/SmartStore.PayPal/Description.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Description: Provides the PayPal payment methods PayPal Express, PayPal Standard and PayPal Direct.
33
SystemName: SmartStore.PayPal
44
Group: Payment
5-
Version: 2.2.0.1
5+
Version: 2.2.0.2
66
MinAppVersion: 2.2.0
77
DisplayOrder: 1
88
FileName: SmartStore.PayPal.dll

src/Plugins/SmartStore.PayPal/Providers/PayPalStandardProvider.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
using SmartStore.PayPal.Services;
1919
using SmartStore.PayPal.Settings;
2020
using SmartStore.Services;
21-
using SmartStore.Services.Directory;
2221
using SmartStore.Services.Localization;
2322
using SmartStore.Services.Orders;
2423
using SmartStore.Services.Payments;
@@ -34,18 +33,15 @@ namespace SmartStore.PayPal
3433
public partial class PayPalStandardProvider : PaymentPluginBase, IConfigurable
3534
{
3635
private readonly IOrderTotalCalculationService _orderTotalCalculationService;
37-
private readonly HttpContextBase _httpContext;
3836
private readonly ICommonServices _services;
3937
private readonly ILogger _logger;
4038

4139
public PayPalStandardProvider(
42-
HttpContextBase httpContext,
4340
IOrderTotalCalculationService orderTotalCalculationService,
4441
ICommonServices services,
4542
ILogger logger)
4643
{
4744
_orderTotalCalculationService = orderTotalCalculationService;
48-
_httpContext = httpContext;
4945
_services = services;
5046
_logger = logger;
5147
}
@@ -280,7 +276,7 @@ public override void PostProcessPayment(PostProcessPaymentRequest postProcessPay
280276
builder.AppendFormat("&zip={0}", HttpUtility.UrlEncode(address.ZipPostalCode));
281277
builder.AppendFormat("&email={0}", HttpUtility.UrlEncode(address.Email));
282278

283-
_httpContext.Response.Redirect(builder.ToString());
279+
postProcessPaymentRequest.RedirectUrl = builder.ToString();
284280
}
285281

286282
/// <summary>
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
#Release Notes#
22

3+
##PayPal 2.2.0.2
4+
###Improvements
5+
* Redirecting to payment provider performed by core instead of plugin
6+
37
##Paypal 2.2.0.1
48
### New Features
59
* Supports order list label for new incoming IPNs
610

7-
##Paypal 1.22##
8-
###Bugfixes###
11+
##Paypal 1.22
12+
###Bugfixes
913
* PayPal Standard provider now using shipping rather than billing address if shipping is required
1014

11-
##Paypal 1.21##
12-
###Improvements###
15+
##Paypal 1.21
16+
###Improvements
1317
* Multistore configuration

src/Presentation/SmartStore.Web/Controllers/CheckoutController.cs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,6 @@ public ActionResult ConfirmOrder(FormCollection form)
793793
if ((_workContext.CurrentCustomer.IsGuest() && !_orderSettings.AnonymousCheckoutAllowed))
794794
return new HttpUnauthorizedResult();
795795

796-
797796
//model
798797
var model = new CheckoutConfirmModel();
799798
try
@@ -827,35 +826,30 @@ public ActionResult ConfirmOrder(FormCollection form)
827826

828827
if (placeOrderResult.Success)
829828
{
829+
var postProcessPaymentRequest = new PostProcessPaymentRequest
830+
{
831+
Order = placeOrderResult.PlacedOrder
832+
};
833+
830834
if (isPaymentPaymentWorkflowRequired)
831835
{
832-
var postProcessPaymentRequest = new PostProcessPaymentRequest()
833-
{
834-
Order = placeOrderResult.PlacedOrder
835-
};
836836
_paymentService.PostProcessPayment(postProcessPaymentRequest);
837837
}
838838

839839
_httpContext.Session["PaymentData"] = null;
840840
_httpContext.Session["OrderPaymentInfo"] = null;
841841
_httpContext.RemoveCheckoutState();
842842

843-
if (_webHelper.IsRequestBeingRedirected || _webHelper.IsPostBeingDone)
844-
{
845-
//redirection or POST has been done in PostProcessPayment
846-
return Content("Redirected");
847-
}
848-
else
849-
{
850-
//if no redirection has been done (to a third-party payment page)
851-
//theoretically it's not possible
852-
return RedirectToAction("Completed");
853-
}
843+
if (postProcessPaymentRequest.RedirectUrl.HasValue())
844+
{
845+
return Redirect(postProcessPaymentRequest.RedirectUrl);
846+
}
847+
848+
return RedirectToAction("Completed");
854849
}
855850
else
856851
{
857-
foreach (var error in placeOrderResult.Errors)
858-
model.Warnings.Add(error);
852+
model.Warnings.AddRange(placeOrderResult.Errors);
859853
}
860854
}
861855
catch (Exception exc)
@@ -864,12 +858,6 @@ public ActionResult ConfirmOrder(FormCollection form)
864858
model.Warnings.Add(exc.Message);
865859
}
866860

867-
//If we got this far, something failed, redisplay form
868-
869-
//if (model.Warnings.Count > 0)
870-
// TempData["ConfirmOrderWarnings"] = model.Warnings;
871-
872-
//return RedirectToRoute("CheckoutConfirm");
873861
return View(model);
874862
}
875863

src/Presentation/SmartStore.Web/Controllers/OrderController.cs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -611,27 +611,22 @@ public ActionResult RePostPayment(int id)
611611
if (IsUnauthorizedOrder(order))
612612
return new HttpUnauthorizedResult();
613613

614-
if (!_paymentService.CanRePostProcessPayment(order))
615-
return RedirectToAction("Details", "Order", new { id = order.Id });
614+
if (_paymentService.CanRePostProcessPayment(order))
615+
{
616+
var postProcessPaymentRequest = new PostProcessPaymentRequest
617+
{
618+
Order = order,
619+
IsRePostProcessPayment = true
620+
};
616621

617-
var postProcessPaymentRequest = new PostProcessPaymentRequest()
618-
{
619-
Order = order,
620-
IsRePostProcessPayment = true
621-
};
622-
_paymentService.PostProcessPayment(postProcessPaymentRequest);
622+
_paymentService.PostProcessPayment(postProcessPaymentRequest);
623623

624-
if (_services.WebHelper.IsRequestBeingRedirected || _services.WebHelper.IsPostBeingDone)
625-
{
626-
//redirection or POST has been done in PostProcessPayment
627-
return Content("Redirected");
628-
}
629-
else
630-
{
631-
//if no redirection has been done (to a third-party payment page)
632-
//theoretically it's not possible
633-
return RedirectToAction("Details", "Order", new { id = order.Id });
634-
}
624+
if (postProcessPaymentRequest.RedirectUrl.HasValue())
625+
{
626+
return Redirect(postProcessPaymentRequest.RedirectUrl);
627+
}
628+
}
629+
return RedirectToAction("Details", "Order", new { id = order.Id });
635630
}
636631

637632
[RequireHttpsByConfigAttribute(SslRequirement.Yes)]

0 commit comments

Comments
 (0)