forked from smartstore/SmartStoreNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.cs
More file actions
187 lines (157 loc) · 5.28 KB
/
Copy pathPlugin.cs
File metadata and controls
187 lines (157 loc) · 5.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
using System;
using System.Collections.Generic;
using System.Web.Routing;
using SmartStore.AmazonPay.Controllers;
using SmartStore.AmazonPay.Services;
using SmartStore.Core.Domain.Orders;
using SmartStore.Core.Logging;
using SmartStore.Core.Plugins;
using SmartStore.Services;
using SmartStore.Services.Authentication.External;
using SmartStore.Services.Customers;
using SmartStore.Services.Orders;
using SmartStore.Services.Payments;
using SmartStore.Services.Tasks;
namespace SmartStore.AmazonPay
{
[DependentWidgets("Widgets.AmazonPay")]
[FriendlyName("Amazon Pay")]
[DisplayOrder(-1)]
public class AmazonPayPlugin : PaymentPluginBase, IExternalAuthenticationMethod, IConfigurable
{
private readonly IAmazonPayService _apiService;
private readonly ICommonServices _services;
private readonly IOrderTotalCalculationService _orderTotalCalculationService;
private readonly IScheduleTaskService _scheduleTaskService;
public AmazonPayPlugin(
IAmazonPayService apiService,
ICommonServices services,
IOrderTotalCalculationService orderTotalCalculationService,
IScheduleTaskService scheduleTaskService)
{
_apiService = apiService;
_services = services;
_orderTotalCalculationService = orderTotalCalculationService;
_scheduleTaskService = scheduleTaskService;
Logger = NullLogger.Instance;
}
public ILogger Logger { get; set; }
public static string SystemName
{
get { return "SmartStore.AmazonPay"; }
}
public override void Install()
{
_services.Settings.SaveSetting(new AmazonPaySettings());
_services.Localization.ImportPluginResourcesFromXml(PluginDescriptor);
// Polling task every 30 minutes.
_scheduleTaskService.GetOrAddTask<DataPollingTask>(x =>
{
x.Name = _services.Localization.GetResource("Plugins.Payments.AmazonPay.TaskName");
x.CronExpression = "*/30 * * * *";
});
base.Install();
}
public override void Uninstall()
{
_scheduleTaskService.TryDeleteTask<DataPollingTask>();
_services.Settings.DeleteSetting<AmazonPaySettings>();
_services.Localization.DeleteLocaleStringResources(PluginDescriptor.ResourceRootKey);
base.Uninstall();
}
public override ProcessPaymentResult ProcessPayment(ProcessPaymentRequest processPaymentRequest)
{
var result = _apiService.ProcessPayment(processPaymentRequest);
return result;
}
public override void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest)
{
_apiService.PostProcessPayment(postProcessPaymentRequest);
}
public override decimal GetAdditionalHandlingFee(IList<OrganizedShoppingCartItem> cart)
{
var result = decimal.Zero;
try
{
var settings = _services.Settings.LoadSetting<AmazonPaySettings>(_services.StoreContext.CurrentStore.Id);
result = this.CalculateAdditionalFee(_orderTotalCalculationService, cart, settings.AdditionalFee, settings.AdditionalFeePercentage);
}
catch (Exception exception)
{
Logger.Error(exception);
}
return result;
}
public override CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
{
var result = _apiService.Capture(capturePaymentRequest);
return result;
}
public override RefundPaymentResult Refund(RefundPaymentRequest refundPaymentRequest)
{
var result = _apiService.Refund(refundPaymentRequest);
return result;
}
public override VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest)
{
var result = _apiService.Void(voidPaymentRequest);
return result;
}
public override void GetConfigurationRoute(out string actionName, out string controllerName, out RouteValueDictionary routeValues)
{
actionName = "Configure";
controllerName = "AmazonPay";
routeValues = new RouteValueDictionary { { "Namespaces", "SmartStore.AmazonPay.Controllers" }, { "area", SystemName } };
}
public void GetPublicInfoRoute(out string actionName, out string controllerName, out RouteValueDictionary routeValues)
{
actionName = "AuthenticationPublicInfo";
controllerName = "AmazonPay";
routeValues = new RouteValueDictionary { { "Namespaces", "SmartStore.AmazonPay.Controllers" }, { "area", SystemName } };
}
public override void GetPaymentInfoRoute(out string actionName, out string controllerName, out RouteValueDictionary routeValues)
{
try
{
var settings = _services.Settings.LoadSetting<AmazonPaySettings>(_services.StoreContext.CurrentStore.Id);
if (settings.ShowPayButtonForAdminOnly && !_services.WorkContext.CurrentCustomer.IsAdmin())
{
actionName = controllerName = null;
routeValues = null;
return;
}
}
catch (Exception exception)
{
Logger.Error(exception);
}
actionName = "ShoppingCart";
controllerName = "AmazonPayShoppingCart";
routeValues = new RouteValueDictionary { { "Namespaces", "SmartStore.AmazonPay.Controllers" }, { "area", SystemName } };
}
public override Type GetControllerType()
{
return typeof(AmazonPayController);
}
public override bool SupportCapture
{
get { return true; }
}
public override bool SupportPartiallyRefund
{
get { return true; }
}
public override bool SupportRefund
{
get { return true; }
}
public override bool SupportVoid
{
get { return true; }
}
public override PaymentMethodType PaymentMethodType
{
get { return PaymentMethodType.StandardAndButton; }
}
}
}