Skip to content

Commit 3523370

Browse files
committed
PayPal Plus: Service class for generic REST API implementation. We should not use old SOAP services for new providers.
1 parent 7d7bf95 commit 3523370

21 files changed

Lines changed: 676 additions & 119 deletions

src/Plugins/SmartStore.PayPal/Controllers/PayPalExpressController.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@
44
using System.Net;
55
using System.Text;
66
using System.Web.Mvc;
7-
using System.Web.Routing;
87
using SmartStore.Core.Domain.Customers;
98
using SmartStore.Core.Domain.Discounts;
10-
using SmartStore.Core.Domain.Localization;
119
using SmartStore.Core.Domain.Logging;
1210
using SmartStore.Core.Domain.Orders;
1311
using SmartStore.Core.Domain.Shipping;
1412
using SmartStore.PayPal.Models;
1513
using SmartStore.PayPal.PayPalSvc;
16-
using SmartStore.PayPal.Services;
1714
using SmartStore.PayPal.Settings;
1815
using SmartStore.PayPal.Validators;
1916
using SmartStore.Services.Common;

src/Plugins/SmartStore.PayPal/Controllers/PayPalPlusController.cs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using System.Web.Mvc;
44
using SmartStore.PayPal.Models;
5+
using SmartStore.PayPal.Services;
56
using SmartStore.PayPal.Settings;
67
using SmartStore.Services.Orders;
78
using SmartStore.Services.Payments;
@@ -13,15 +14,19 @@ namespace SmartStore.PayPal.Controllers
1314
{
1415
public class PayPalPlusController : PayPalControllerBase<PayPalPlusPaymentSettings>
1516
{
17+
private readonly IPayPalService _payPalService;
18+
1619
public PayPalPlusController(
1720
IPaymentService paymentService,
1821
IOrderService orderService,
19-
IOrderProcessingService orderProcessingService) : base(
22+
IOrderProcessingService orderProcessingService,
23+
IPayPalService payPalService) : base(
2024
PayPalPlusProvider.SystemName,
2125
paymentService,
2226
orderService,
2327
orderProcessingService)
2428
{
29+
_payPalService = payPalService;
2530
}
2631

2732
[NonAction]
@@ -93,5 +98,48 @@ public ActionResult Configure(PayPalPlusConfigurationModel model, FormCollection
9398
return Configure();
9499
}
95100

101+
[AdminAuthorize]
102+
public ActionResult CreateExperienceProfile()
103+
{
104+
string profileId = null;
105+
string error = null;
106+
107+
var storeScope = this.GetActiveStoreScopeConfiguration(Services.StoreService, Services.WorkContext);
108+
var settings = Services.Settings.LoadSetting<PayPalPlusPaymentSettings>(storeScope);
109+
110+
var store = Services.StoreService.GetStoreById(storeScope == 0 ? Services.StoreContext.CurrentStore.Id : storeScope);
111+
112+
var result = _payPalService.SetCheckoutExperience(settings, store);
113+
114+
if (result.Success)
115+
{
116+
profileId = (string)result.Json.id;
117+
}
118+
else
119+
{
120+
error = result.ErrorName.EmptyNull().EnsureEndsWith(".").Grow(result.ErrorMessage, " ");
121+
}
122+
123+
return new JsonResult { Data = new { id = profileId, error = error}, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
124+
}
125+
126+
public ActionResult PaymentInfo()
127+
{
128+
return new EmptyResult();
129+
}
130+
131+
public ActionResult PaymentWall()
132+
{
133+
var model = new PayPalPlusCheckoutModel();
134+
135+
return View(model);
136+
}
137+
138+
[HttpPost]
139+
public ActionResult PaymentWall(FormCollection form)
140+
{
141+
142+
return RedirectToAction("Confirm", "Checkout", new { area = "" });
143+
}
96144
}
97145
}

src/Plugins/SmartStore.PayPal/DependencyRegistrar.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using SmartStore.Core.Infrastructure;
44
using SmartStore.Core.Infrastructure.DependencyManagement;
55
using SmartStore.PayPal.Filters;
6+
using SmartStore.PayPal.Services;
67
using SmartStore.Web.Controllers;
78

89
namespace SmartStore.PayPal
@@ -11,10 +12,17 @@ public class DependencyRegistrar : IDependencyRegistrar
1112
{
1213
public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, bool isActiveModule)
1314
{
15+
builder.RegisterType<PayPalService>().As<IPayPalService>().InstancePerRequest();
16+
1417
if (isActiveModule)
1518
{
1619
builder.RegisterType<PayPalExpressCheckoutFilter>().AsActionFilterFor<CheckoutController>(x => x.PaymentMethod()).InstancePerRequest();
20+
1721
builder.RegisterType<PayPalExpressWidgetZoneFilter>().AsActionFilterFor<ShoppingCartController>(x => x.FlyoutShoppingCart()).InstancePerRequest();
22+
23+
builder.RegisterType<PayPalPlusCheckoutFilter>()
24+
.AsActionFilterFor<CheckoutController>(x => x.PaymentMethod())
25+
.InstancePerRequest();
1826
}
1927
}
2028

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.Web.Mvc;
2+
using System.Web.Routing;
3+
using SmartStore.Services;
4+
using SmartStore.Services.Payments;
5+
6+
namespace SmartStore.PayPal.Filters
7+
{
8+
public class PayPalPlusCheckoutFilter : IActionFilter
9+
{
10+
private readonly ICommonServices _services;
11+
private readonly IPaymentService _paymentService;
12+
13+
public PayPalPlusCheckoutFilter(
14+
ICommonServices services,
15+
IPaymentService paymentService)
16+
{
17+
_services = services;
18+
_paymentService = paymentService;
19+
}
20+
21+
public void OnActionExecuting(ActionExecutingContext filterContext)
22+
{
23+
if (filterContext == null || filterContext.ActionDescriptor == null || filterContext.HttpContext == null || filterContext.HttpContext.Request == null)
24+
return;
25+
26+
var store = _services.StoreContext.CurrentStore;
27+
28+
if (!_paymentService.IsPaymentMethodActive(PayPalPlusProvider.SystemName, store.Id))
29+
return;
30+
31+
var routeValues = new RouteValueDictionary(new { action = "PaymentWall", controller = "PayPalPlus" });
32+
33+
filterContext.Result = new RedirectToRouteResult("SmartStore.PayPalPlus", routeValues);
34+
}
35+
36+
public void OnActionExecuted(ActionExecutedContext filterContext)
37+
{
38+
39+
}
40+
}
41+
}

src/Plugins/SmartStore.PayPal/Localization/resources.de-de.xml

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,43 @@
44
<Value>PayPal Zahlungsarten</Value>
55
</LocaleResource>
66
<LocaleResource Name="Plugins.Description.SmartStore.PayPal" AppendRootKey="false">
7-
<Value>Stellt die PayPal-Zahlungsarten PayPal Standard, PayPal Direct, PayPal Express und PayPal Plus zur Verfügung.</Value>
7+
<Value>Stellt die PayPal-Zahlungsarten PayPal Standard, PayPal Direct, PayPal Express und PayPal PLUS zur Verfügung.</Value>
88
</LocaleResource>
99

1010
<LocaleResource Name="ConfigGroups">
1111
<Value>API Zugang;Datenaustausch;Sonstiges</Value>
1212
</LocaleResource>
13+
<LocaleResource Name="OrderNoteStrings">
14+
<Value><![CDATA[Antwort von PayPal:<br />{0}]]></Value>
15+
</LocaleResource>
1316
<LocaleResource Name="ModeAuth">
1417
<Value>Autorisierung sofort, Abbuchung später</Value>
1518
</LocaleResource>
1619
<LocaleResource Name="ModeAuthAndCapture">
1720
<Value>Sofort abbuchen</Value>
1821
</LocaleResource>
19-
<LocaleResource Name="ShowButtonInMiniShoppingCart">
20-
<Value>Button im Miniwarenkorb anzeigen</Value>
22+
<LocaleResource Name="CreateNow">
23+
<Value>Jetzt erstellen</Value>
2124
</LocaleResource>
22-
<LocaleResource Name="ShowButtonInMiniShoppingCart.Hint">
23-
<Value>Legt fest, ob der Checkout-Button im Miniwarenkorb angezeigt werden soll.</Value>
25+
<LocaleResource Name="ClientId">
26+
<Value>Client-ID</Value>
2427
</LocaleResource>
25-
28+
<LocaleResource Name="ClientId.Hint">
29+
<Value>Legt die API Client-ID fest.</Value>
30+
</LocaleResource>
31+
<LocaleResource Name="Secret">
32+
<Value>Secret</Value>
33+
</LocaleResource>
34+
<LocaleResource Name="Secret.Hint">
35+
<Value>Legt die API Secret fest.</Value>
36+
</LocaleResource>
37+
<LocaleResource Name="ExperienceProfileId">
38+
<Value>Experience Profil-ID</Value>
39+
</LocaleResource>
40+
<LocaleResource Name="ExperienceProfileId.Hint">
41+
<Value>Legt die Experience Profil-ID fest. Das Profil beinhaltet globale Daten wie z.B. Shop-Name und -Logo. Ein Profil braucht nur einmalig angelegt werden.</Value>
42+
</LocaleResource>
43+
2644
<LocaleResource Name="Plugins.Payments.PayPal" AppendRootKey="false">
2745
<Children>
2846
<LocaleResource Name="UseSandbox">
@@ -352,7 +370,7 @@ Zahlungsgebühr: {10}]]>
352370
</LocaleResource>
353371

354372
<LocaleResource Name="Plugins.FriendlyName.Payments.PayPalPlus" AppendRootKey="false">
355-
<Value>PayPal Plus</Value>
373+
<Value>PayPal PLUS</Value>
356374
</LocaleResource>
357375
<LocaleResource Name="Plugins.Payments.PayPalPlus" AppendRootKey="false">
358376
<Children>

src/Plugins/SmartStore.PayPal/Localization/resources.en-us.xml

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,41 @@
44
<Value>PayPal Payment Methods</Value>
55
</LocaleResource>
66
<LocaleResource Name="Plugins.Description.SmartStore.PayPal" AppendRootKey="false">
7-
<Value>Provides the PayPal payment methods PayPal Standard, PayPal Direct, PayPal Express and PayPal Plus.</Value>
7+
<Value>Provides the PayPal payment methods PayPal Standard, PayPal Direct, PayPal Express and PayPal PLUS.</Value>
88
</LocaleResource>
99

1010
<LocaleResource Name="ConfigGroups">
1111
<Value>API access;Data exchange;Miscellaneous</Value>
1212
</LocaleResource>
13+
<LocaleResource Name="OrderNoteStrings">
14+
<Value><![CDATA[Response from PayPal:<br />{0}]]></Value>
15+
</LocaleResource>
1316
<LocaleResource Name="ModeAuth">
1417
<Value>Authorize immediately, debit later</Value>
1518
</LocaleResource>
1619
<LocaleResource Name="ModeAuthAndCapture">
1720
<Value>Immediately debit</Value>
1821
</LocaleResource>
19-
<LocaleResource Name="ShowButtonInMiniShoppingCart">
20-
<Value>Show button in mini shopping cart</Value>
22+
<LocaleResource Name="CreateNow">
23+
<Value>Create now</Value>
24+
</LocaleResource>
25+
<LocaleResource Name="ClientId">
26+
<Value>Client ID</Value>
27+
</LocaleResource>
28+
<LocaleResource Name="ClientId.Hint">
29+
<Value>Specifies the API client ID.</Value>
30+
</LocaleResource>
31+
<LocaleResource Name="Secret">
32+
<Value>Secret</Value>
33+
</LocaleResource>
34+
<LocaleResource Name="Secret.Hint">
35+
<Value>Specifies the API secret.</Value>
36+
</LocaleResource>
37+
<LocaleResource Name="ExperienceProfileId">
38+
<Value>Experience profile ID</Value>
2139
</LocaleResource>
22-
<LocaleResource Name="ShowButtonInMiniShoppingCart.Hint">
23-
<Value>Soecifies to show the checkout button in the mini shopping cart.</Value>
40+
<LocaleResource Name="ExperienceProfileId.Hint">
41+
<Value>Specifies the experience profile ID. The profile conatins global data like shop name and logo. A profile needs to be created only once.</Value>
2442
</LocaleResource>
2543

2644
<LocaleResource Name="Plugins.Payments.PayPal" AppendRootKey="false">
@@ -352,7 +370,7 @@ Payment fee: {10}]]>
352370
</LocaleResource>
353371

354372
<LocaleResource Name="Plugins.FriendlyName.Payments.PayPalPlus" AppendRootKey="false">
355-
<Value>PayPal Plus</Value>
373+
<Value>PayPal PLUS</Value>
356374
</LocaleResource>
357375
<LocaleResource Name="Plugins.Payments.PayPalPlus" AppendRootKey="false">
358376
<Children>

src/Plugins/SmartStore.PayPal/Models/ApiConfigurationModels.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,14 @@ public void Copy(PayPalExpressPaymentSettings settings, bool fromSettings)
134134

135135
public class PayPalPlusConfigurationModel : ApiConfigurationModel
136136
{
137-
[SmartResourceDisplayName("Plugins.SmartStore.PayPal.ShowButtonInMiniShoppingCart")]
138-
public bool ShowButtonInMiniShoppingCart { get; set; }
137+
[SmartResourceDisplayName("Plugins.SmartStore.PayPal.ClientId")]
138+
public string ClientId { get; set; }
139+
140+
[SmartResourceDisplayName("Plugins.SmartStore.PayPal.Secret")]
141+
public string Secret { get; set; }
142+
143+
[SmartResourceDisplayName("Plugins.SmartStore.PayPal.ExperienceProfileId")]
144+
public string ExperienceProfileId { get; set; }
139145

140146
public void Copy(PayPalPlusPaymentSettings settings, bool fromSettings)
141147
{
@@ -150,7 +156,10 @@ public void Copy(PayPalPlusPaymentSettings settings, bool fromSettings)
150156
Signature = settings.Signature;
151157
AdditionalFee = settings.AdditionalFee;
152158
AdditionalFeePercentage = settings.AdditionalFeePercentage;
153-
ShowButtonInMiniShoppingCart = settings.ShowButtonInMiniShoppingCart;
159+
160+
ClientId = settings.ClientId;
161+
Secret = settings.Secret;
162+
ExperienceProfileId = settings.ExperienceProfileId;
154163
}
155164
else
156165
{
@@ -163,7 +172,10 @@ public void Copy(PayPalPlusPaymentSettings settings, bool fromSettings)
163172
settings.Signature = Signature;
164173
settings.AdditionalFee = AdditionalFee;
165174
settings.AdditionalFeePercentage = AdditionalFeePercentage;
166-
settings.ShowButtonInMiniShoppingCart = ShowButtonInMiniShoppingCart;
175+
176+
settings.ClientId = ClientId;
177+
settings.Secret = Secret;
178+
settings.ExperienceProfileId = ExperienceProfileId;
167179
}
168180
}
169181
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using SmartStore.Web.Framework.Modelling;
2+
3+
namespace SmartStore.PayPal.Models
4+
{
5+
public class PayPalPlusCheckoutModel : ModelBase
6+
{
7+
}
8+
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using SmartStore.Core.Plugins;
1313
using SmartStore.PayPal.Controllers;
1414
using SmartStore.PayPal.PayPalSvc;
15-
using SmartStore.PayPal.Services;
1615
using SmartStore.PayPal.Settings;
1716
using SmartStore.Services.Catalog;
1817
using SmartStore.Services.Common;
@@ -576,4 +575,13 @@ public DoExpressCheckoutPaymentResponseType DoExpressCheckoutPayment(ProcessPaym
576575
return result;
577576
}
578577
}
578+
579+
580+
public class PayPalProcessPaymentRequest : ProcessPaymentRequest
581+
{
582+
/// <summary>
583+
/// Gets or sets an order Discount Amount
584+
/// </summary>
585+
public decimal Discount { get; set; }
586+
}
579587
}

0 commit comments

Comments
 (0)