diff --git a/Components/PaymentPayUViewComponent.cs b/Components/PaymentPayUViewComponent.cs new file mode 100644 index 0000000..d7d2bf0 --- /dev/null +++ b/Components/PaymentPayUViewComponent.cs @@ -0,0 +1,14 @@ +using Microsoft.AspNetCore.Mvc; +using Nop.Web.Framework.Components; + +namespace NopBrasil.Plugin.Payments.PayU.Components +{ + [ViewComponent(Name = "PaymentPayU")] + public class PaymentPayUViewComponent : NopViewComponent + { + public IViewComponentResult Invoke() + { + return View("~/Plugins/Payments.PayU/Views/PaymentInfo.cshtml"); + } + } +} diff --git a/Controllers/PaymentPayUController.cs b/Controllers/PaymentPayUController.cs index 997d866..bb18fde 100644 --- a/Controllers/PaymentPayUController.cs +++ b/Controllers/PaymentPayUController.cs @@ -1,42 +1,46 @@ -using Nop.Core; -using Nop.Services.Configuration; -using Nop.Services.Payments; +using Nop.Services.Configuration; using Nop.Web.Framework.Controllers; -using System.Collections.Generic; -using System.Web.Mvc; -using NopBrasil.Plugin.Payments.PayU.Services; using NopBrasil.Plugin.Payments.PayU.Models; +using Nop.Web.Framework; +using Microsoft.AspNetCore.Mvc; +using Nop.Services.Security; +using Nop.Web.Framework.Mvc.Filters; namespace NopBrasil.Plugin.Payments.PayU.Controllers { + [Area(AreaNames.Admin)] public class PaymentPayUController : BasePaymentController { private readonly ISettingService _settingService; - private readonly IWebHelper _webHelper; - private readonly IPaymentPayUService _payUService; private readonly PayUPaymentSettings _payUPaymentSettings; + private readonly IPermissionService _permissionService; - public PaymentPayUController(ISettingService settingService, IWebHelper webHelper, IPaymentPayUService payUService, PayUPaymentSettings payUPaymentSettings) + public PaymentPayUController(ISettingService settingService, PayUPaymentSettings payUPaymentSettings, IPermissionService permissionService) { this._settingService = settingService; - this._webHelper = webHelper; - this._payUService = payUService; this._payUPaymentSettings = payUPaymentSettings; + this._permissionService = permissionService; } - [AdminAuthorize] - [ChildActionOnly] - public ActionResult Configure() + [AuthorizeAdmin] + public IActionResult Configure() { - var model = new ConfigurationModel() { EmailPayU = _payUPaymentSettings.EmailPayU, PaymentMethodDescription = _payUPaymentSettings.PaymentMethodDescription }; - return View(@"~/Plugins/Payments.PayU/Views/PaymentPayU/Configure.cshtml", model); + var model = new ConfigurationModel() + { + EmailPayU = _payUPaymentSettings.EmailPayU, + PaymentMethodDescription = _payUPaymentSettings.PaymentMethodDescription + }; + return View(@"~/Plugins/Payments.PayU/Views/Configure.cshtml", model); } [HttpPost] - [AdminAuthorize] - [ChildActionOnly] - public ActionResult Configure(ConfigurationModel model) + [AuthorizeAdmin] + [AdminAntiForgery] + public IActionResult Configure(ConfigurationModel model) { + if (!_permissionService.Authorize(StandardPermissionProvider.ManagePaymentMethods)) + return AccessDeniedView(); + if (!ModelState.IsValid) return Configure(); @@ -44,15 +48,7 @@ public ActionResult Configure(ConfigurationModel model) _payUPaymentSettings.PaymentMethodDescription = model.PaymentMethodDescription; _settingService.SaveSetting(_payUPaymentSettings); - return View(@"~/Plugins/Payments.PayU/Views/PaymentPayU/Configure.cshtml", model); + return View(@"~/Plugins/Payments.PayU/Views/Configure.cshtml", model); } - - - [ChildActionOnly] - public ActionResult PaymentInfo() => View("~/Plugins/Payments.PayU/Views/PaymentPayU/PaymentInfo.cshtml"); - - public override IList ValidatePaymentForm(System.Web.Mvc.FormCollection form) => new List(); - - public override ProcessPaymentRequest GetPaymentInfo(System.Web.Mvc.FormCollection form) => new ProcessPaymentRequest(); } } diff --git a/Description.txt b/Description.txt deleted file mode 100644 index 2167a94..0000000 --- a/Description.txt +++ /dev/null @@ -1,8 +0,0 @@ -Group: Payment methods -FriendlyName: PayU -SystemName: Payments.PayU -Version: 1.00 -SupportedVersions: 3.90 -Author: nopCommerce Brasil - www.nopcommercebrasil.com - nopcommercebrasil@nopcommercebrasil.com -DisplayOrder: 2 -FileName: NopBrasil.Plugin.Payments.PayU.dll \ No newline at end of file diff --git a/Models/ConfigurationModel.cs b/Models/ConfigurationModel.cs index d5b0e9a..1530500 100644 --- a/Models/ConfigurationModel.cs +++ b/Models/ConfigurationModel.cs @@ -1,5 +1,5 @@ -using Nop.Web.Framework; -using Nop.Web.Framework.Mvc; +using Nop.Web.Framework.Mvc.ModelBinding; +using Nop.Web.Framework.Mvc.Models; namespace NopBrasil.Plugin.Payments.PayU.Models { diff --git a/NopBrasil.Plugin.Payments.PayU.csproj b/NopBrasil.Plugin.Payments.PayU.csproj index 63fd6a3..811c9d5 100644 --- a/NopBrasil.Plugin.Payments.PayU.csproj +++ b/NopBrasil.Plugin.Payments.PayU.csproj @@ -1,148 +1,67 @@ - - - - - Debug - AnyCPU - {D3E43FBE-F8D6-4A3A-AE66-650EBE4EF25B} - Library - Properties - NopBrasil.Plugin.Payments.PayU - NopBrasil.Plugin.Payments.PayU - v4.5.1 - 512 - SAK - SAK - SAK - SAK - - - - true - full - false - ..\NopCommerce\src\Presentation\Nop.Web\Plugins\Payments.PayU\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - ..\NopCommerce\src\Presentation\Nop.Web\Plugins\Payments.PayU\ - TRACE - prompt - 4 - - - - ..\nopCommerce\src\packages\Autofac.4.4.0\lib\net45\Autofac.dll - False - - - ..\nopCommerce\src\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll - False - - - - - - - ..\nopCommerce\src\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll - False - - - ..\nopCommerce\src\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll - False - - - ..\nopCommerce\src\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll - False - - - ..\nopCommerce\src\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.dll - False - - - ..\nopCommerce\src\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Deployment.dll - False - - - ..\nopCommerce\src\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll - False - - - - - - - - - - - - - - - - - - - - - PreserveNewest - - - PreserveNewest - - - Always - - - Always - - - - PreserveNewest - - - - - - {6bda8332-939f-45b7-a25e-7a797260ae59} - Nop.Core - False - - - {ccd7f2c9-6a2c-4cf0-8e89-076b8fc0f144} - Nop.Data - False - - - {210541ad-f659-47da-8763-16f36c5cd2f4} - Nop.Services - False - - - {75fd4163-333c-4dd5-854d-2ef294e45d94} - Nop.Web.Framework - False - - - - - PreserveNewest - - - PreserveNewest - - - - + + + net461 + Copyright © nopCommerce Brasil + nopCommerce Brasil + nopCommerce Brasil - www.nopcommercebrasil.com - nopcommercebrasil@nopcommercebrasil.com + 1.00 + Payment plugin for integration with PayU (bCash) for nopCommerce + + http://www.nopcommercebrasil.com/ + https://github.com/nopCommerceBrasil/NopBrasil.Plugin.Payments.PayU + Git + + + ..\nopCommerce400\Presentation\Nop.Web\Plugins\Payments.PayU\ + $(OutputPath) + + + ..\nopCommerce400\Presentation\Nop.Web\Plugins\Payments.PayU\ + $(OutputPath) + + + + + + + + + + + + + + + + + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + + + + \ No newline at end of file diff --git a/PayUPaymentProcessor.cs b/PayUPaymentProcessor.cs index 510f050..7e349cc 100644 --- a/PayUPaymentProcessor.cs +++ b/PayUPaymentProcessor.cs @@ -3,13 +3,13 @@ using Nop.Services.Payments; using System; using System.Collections.Generic; -using System.Web; -using System.Web.Routing; using Nop.Services.Localization; using Nop.Services.Configuration; using Nop.Core.Plugins; using NopBrasil.Plugin.Payments.PayU.Controllers; using NopBrasil.Plugin.Payments.PayU.Services; +using Microsoft.AspNetCore.Http; +using Nop.Core; namespace NopBrasil.Plugin.Payments.PayU { @@ -19,13 +19,18 @@ public class PayUPaymentProcessor : BasePlugin, IPaymentMethod private readonly ISettingService _settingService; private readonly IPaymentPayUService _payUService; private readonly PayUPaymentSettings _payUPaymentSettings; + private readonly IHttpContextAccessor _httpContextAccessor; + private readonly IWebHelper _webHelper; - public PayUPaymentProcessor(ILogger logger, ISettingService settingService, IPaymentPayUService payUService, PayUPaymentSettings payUPaymentSettings) + public PayUPaymentProcessor(ILogger logger, ISettingService settingService, IPaymentPayUService payUService, PayUPaymentSettings payUPaymentSettings, + IHttpContextAccessor httpContextAccessor, IWebHelper webHelper) { this._logger = logger; this._settingService = settingService; this._payUService = payUService; this._payUPaymentSettings = payUPaymentSettings; + this._httpContextAccessor = httpContextAccessor; + this._webHelper = webHelper; } public override void Install() @@ -47,8 +52,10 @@ public override void Uninstall() public ProcessPaymentResult ProcessPayment(ProcessPaymentRequest processPaymentRequest) { - var processPaymentResult = new ProcessPaymentResult(); - processPaymentResult.NewPaymentStatus = PaymentStatus.Pending; + var processPaymentResult = new ProcessPaymentResult() + { + NewPaymentStatus = PaymentStatus.Pending + }; return processPaymentResult; } @@ -56,10 +63,10 @@ public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentReque { try { - HttpContext.Current.Response.Clear(); - HttpContext.Current.Response.Write(_payUService.GetStringPost(postProcessPaymentRequest)); - HttpContext.Current.Response.Flush(); - HttpContext.Current.Response.End(); + _httpContextAccessor.HttpContext.Response.Clear(); + var write = _httpContextAccessor.HttpContext.Response.WriteAsync(_payUService.GetStringPost(postProcessPaymentRequest)); + _httpContextAccessor.HttpContext.Response.Body.FlushAsync(); + _httpContextAccessor.HttpContext.Response.Body.EndWrite(write); } catch (Exception e) { @@ -81,28 +88,6 @@ public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentReque public bool CanRePostProcessPayment(Nop.Core.Domain.Orders.Order order) => false; - public void GetConfigurationRoute(out string actionName, out string controllerName, out System.Web.Routing.RouteValueDictionary routeValues) - { - actionName = "Configure"; - controllerName = "PaymentPayU"; - routeValues = new RouteValueDictionary() - { - { "Namespaces", "NopBrasil.Plugin.Payments.PayU.Controllers" }, - { "area", null } - }; - } - - public void GetPaymentInfoRoute(out string actionName, out string controllerName, out System.Web.Routing.RouteValueDictionary routeValues) - { - actionName = "PaymentInfo"; - controllerName = "PaymentPayU"; - routeValues = new RouteValueDictionary() - { - { "Namespaces", "NopBrasil.Plugin.Payments.PayU.Controllers" }, - { "area", null } - }; - } - public Type GetControllerType() => typeof(PaymentPayUController); public bool SupportCapture => false; @@ -121,6 +106,14 @@ public void GetPaymentInfoRoute(out string actionName, out string controllerName public bool SkipPaymentInfo => false; + public IList ValidatePaymentForm(IFormCollection form) => new List(); + + public ProcessPaymentRequest GetPaymentInfo(IFormCollection form) => new ProcessPaymentRequest(); + + public void GetPublicViewComponent(out string viewComponentName) => viewComponentName = "PaymentPayU"; + public string PaymentMethodDescription => _payUPaymentSettings.PaymentMethodDescription; + + public override string GetConfigurationPageUrl() => $"{_webHelper.GetStoreLocation()}Admin/PaymentPayU/Configure"; } } diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs deleted file mode 100644 index 2e94883..0000000 --- a/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("NopBrasil.Plugin.Payments.PayU")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("NopBrasil.Plugin.Payments.PayU")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("f4e46e83-594a-4d8d-8bc2-5fae0f6b2932")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Views/PaymentPayU/Configure.cshtml b/Views/Configure.cshtml similarity index 71% rename from Views/PaymentPayU/Configure.cshtml rename to Views/Configure.cshtml index bd04afd..64f2e8e 100644 --- a/Views/PaymentPayU/Configure.cshtml +++ b/Views/Configure.cshtml @@ -1,17 +1,10 @@ -@{ - Layout = ""; -} -@model ConfigurationModel -@using NopBrasil.Plugin.Payments.PayU.Models; -@using Nop.Web.Framework; +@model NopBrasil.Plugin.Payments.PayU.Models.ConfigurationModel -
- @Html.ValidationSummary(false) -
+@{ + Layout = "_ConfigurePlugin"; +} -@using (@Html.BeginForm()) -{ - @Html.AntiForgeryToken() +
@@ -24,32 +17,30 @@ Este plugin é open-source e seu código-fonte está disponível no GitHub do NopCommerce Brasil no repositório NopBrasil.Plugin.Payments.PayU


-
- @Html.NopLabelFor(model => model.EmailPayU) +
- @Html.EditorFor(model => model.EmailPayU) + +
- @Html.NopLabelFor(model => model.PaymentMethodDescription) +
- @Html.EditorFor(model => model.PaymentMethodDescription) + +
-
-   -
-
+
@@ -57,6 +48,4 @@
-} - - +
\ No newline at end of file diff --git a/Views/PaymentPayU/PaymentInfo.cshtml b/Views/PaymentInfo.cshtml similarity index 90% rename from Views/PaymentPayU/PaymentInfo.cshtml rename to Views/PaymentInfo.cshtml index 2b3a2f6..7bee7c1 100644 --- a/Views/PaymentPayU/PaymentInfo.cshtml +++ b/Views/PaymentInfo.cshtml @@ -2,9 +2,6 @@ Layout = ""; Html.AddCssFileParts("~/Plugins/Payments.PayU/Content/PayU.css"); } -@using System -@using Nop.Web.Framework.UI - diff --git a/Views/_ViewImports.cshtml b/Views/_ViewImports.cshtml new file mode 100644 index 0000000..2d4ad97 --- /dev/null +++ b/Views/_ViewImports.cshtml @@ -0,0 +1,8 @@ +@inherits Nop.Web.Framework.Mvc.Razor.NopRazorPage +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@addTagHelper *, Nop.Web.Framework + +@using Microsoft.AspNetCore.Mvc.ViewFeatures +@using Nop.Web.Framework.UI +@using Nop.Web.Framework.Extensions +@using System.Text.Encodings.Web \ No newline at end of file diff --git a/app.config b/app.config deleted file mode 100644 index 5da104c..0000000 --- a/app.config +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages.config b/packages.config deleted file mode 100644 index d8d80cf..0000000 --- a/packages.config +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/plugin.json b/plugin.json new file mode 100644 index 0000000..2b6df4b --- /dev/null +++ b/plugin.json @@ -0,0 +1,11 @@ +{ + "Group": "Payment methods", + "FriendlyName": "PayU", + "SystemName": "Payments.PayU", + "Version": "1.00", + "SupportedVersions": [ "4.00" ], + "Author": "nopCommerce Brasil - www.nopcommercebrasil.com - nopcommercebrasil@nopcommercebrasil.com", + "DisplayOrder": 1, + "FileName": "NopBrasil.Plugin.Payments.PayU.dll", + "Description": "Payment plugin for integration with PayU (bCash) for nopCommerce" +} \ No newline at end of file diff --git a/web.config b/web.config deleted file mode 100644 index e6e0b3d..0000000 --- a/web.config +++ /dev/null @@ -1,47 +0,0 @@ - - - - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file