Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Plugin Payments.PayPalStandard - change type of project to Microsoft.NET.Sdk.Razor
KrzysztofPajak6669d146b618
diff --git a/src/Plugins/Payments.PayPalStandard/Areas/Admin/Controllers/PayPalStandardController.cs b/src/Plugins/Payments.PayPalStandard/Areas/Admin/Controllers/PayPalStandardController.csnew file mode 100644index 000000000..3f196d486--- /dev/null+++ b/src/Plugins/Payments.PayPalStandard/Areas/Admin/Controllers/PayPalStandardController.cs@@ -0,0 +1,113 @@+using Grand.Business.Common.Interfaces.Configuration;+using Grand.Business.Common.Interfaces.Localization;+using Grand.Business.Common.Interfaces.Security;+using Grand.Business.Common.Interfaces.Stores;+using Grand.Business.Common.Services.Security;+using Grand.Domain.Common;+using Grand.Domain.Customers;+using Grand.Infrastructure;+using Grand.Web.Common.Controllers;+using Grand.Web.Common.Filters;+using Grand.Web.Common.Security.Authorization;+using Microsoft.AspNetCore.Mvc;+using Payments.PayPalStandard.Models;+using System.Linq;+using System.Threading.Tasks;++namespace Payments.PayPalStandard.Controllers+{+ [AuthorizeAdmin]+ [Area("Admin")]+ [PermissionAuthorize(PermissionSystemName.PaymentMethods)]+ public class PayPalStandardController : BasePaymentController+ {+ private readonly IWorkContext _workContext;+ private readonly IStoreService _storeService;+ private readonly ISettingService _settingService;+ private readonly ITranslationService _translationService;+ private readonly IPermissionService _permissionService;++ public PayPalStandardController(IWorkContext workContext,+ IStoreService storeService,+ ISettingService settingService,+ ITranslationService translationService,+ IPermissionService permissionService)+ {+ _workContext = workContext;+ _storeService = storeService;+ _settingService = settingService;+ _translationService = translationService;+ _permissionService = permissionService;+ }++ protected virtual async Task<string> GetActiveStore(IStoreService storeService, IWorkContext workContext)+ {+ var stores = await storeService.GetAllStores();+ if (stores.Count < 2)+ return stores.FirstOrDefault().Id;++ var storeId = workContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.AdminAreaStoreScopeConfiguration);+ var store = await storeService.GetStoreById(storeId);++ return store != null ? store.Id : "";+ }++ public async Task<IActionResult> Configure()+ {+ if (!await _permissionService.Authorize(StandardPermission.ManagePaymentMethods))+ return AccessDeniedView();++ //load settings for a chosen store scope+ var storeScope = await GetActiveStore(_storeService, _workContext);+ var payPalStandardPaymentSettings = _settingService.LoadSetting<PayPalStandardPaymentSettings>(storeScope);++ var model = new ConfigurationModel();+ model.UseSandbox = payPalStandardPaymentSettings.UseSandbox;+ model.BusinessEmail = payPalStandardPaymentSettings.BusinessEmail;+ model.PdtToken = payPalStandardPaymentSettings.PdtToken;+ model.PdtValidateOrderTotal = payPalStandardPaymentSettings.PdtValidateOrderTotal;+ model.AdditionalFee = payPalStandardPaymentSettings.AdditionalFee;+ model.AdditionalFeePercentage = payPalStandardPaymentSettings.AdditionalFeePercentage;+ model.PassProductNamesAndTotals = payPalStandardPaymentSettings.PassProductNamesAndTotals;+ model.DisplayOrder = payPalStandardPaymentSettings.DisplayOrder;++ model.StoreScope = storeScope;++ return View(model);+ }++ [HttpPost]+ public async Task<IActionResult> Configure(ConfigurationModel model)+ {+ if (!await _permissionService.Authorize(StandardPermission.ManagePaymentMethods))+ return AccessDeniedView();++ if (!ModelState.IsValid)+ return await Configure();++ //load settings for a chosen store scope+ var storeScope = await this.GetActiveStore(_storeService, _workContext);+ var payPalStandardPaymentSettings = _settingService.LoadSetting<PayPalStandardPaymentSettings>(storeScope);++ //save settings+ payPalStandardPaymentSettings.UseSandbox = model.UseSandbox;+ payPalStandardPaymentSettings.BusinessEmail = model.BusinessEmail;+ payPalStandardPaymentSettings.PdtToken = model.PdtToken;+ payPalStandardPaymentSettings.PdtValidateOrderTotal = model.PdtValidateOrderTotal;+ payPalStandardPaymentSettings.AdditionalFee = model.AdditionalFee;+ payPalStandardPaymentSettings.AdditionalFeePercentage = model.AdditionalFeePercentage;+ payPalStandardPaymentSettings.PassProductNamesAndTotals = model.PassProductNamesAndTotals;+ payPalStandardPaymentSettings.DisplayOrder = model.DisplayOrder;++ await _settingService.SaveSetting(payPalStandardPaymentSettings, storeScope);++ //now clear settings cache+ await _settingService.ClearCache();++ Success(_translationService.GetResource("Admin.Plugins.Saved"));++ return await Configure();+ }++ }+}\ No newline at end of filediff --git a/src/Plugins/Payments.PayPalStandard/Views/PaymentPayPalStandard/Configure.cshtml b/src/Plugins/Payments.PayPalStandard/Areas/Admin/Views/PayPalStandard/Configure.cshtmlsimilarity index 98%rename from src/Plugins/Payments.PayPalStandard/Views/PaymentPayPalStandard/Configure.cshtmlrename to src/Plugins/Payments.PayPalStandard/Areas/Admin/Views/PayPalStandard/Configure.cshtmlindex e14668188..6ac5a4252 100644--- a/src/Plugins/Payments.PayPalStandard/Views/PaymentPayPalStandard/Configure.cshtml+++ b/src/Plugins/Payments.PayPalStandard/Areas/Admin/Views/PayPalStandard/Configure.cshtml@@ -5,7 +5,7 @@@using Payments.PayPalStandard.Models;@await Component.InvokeAsync("StoreScope")-<form asp-controller="PaymentPayPalStandard" asp-action="Configure" method="post">+<form asp-area="Admin" asp-controller="PayPalStandard" asp-action="Configure" method="post"><div class="form-horizontal"><div class="form-body">diff --git a/src/Plugins/Payments.PayPalStandard/Views/PaymentPayPalStandard/_ViewImports.cshtml b/src/Plugins/Payments.PayPalStandard/Areas/Admin/Views/_ViewImports.cshtmlsimilarity index 100%rename from src/Plugins/Payments.PayPalStandard/Views/PaymentPayPalStandard/_ViewImports.cshtmlrename to src/Plugins/Payments.PayPalStandard/Areas/Admin/Views/_ViewImports.cshtmldiff --git a/src/Plugins/Payments.PayPalStandard/Components/PaymentPayPalStandardViewComponent.cs b/src/Plugins/Payments.PayPalStandard/Components/PaymentPayPalStandardViewComponent.csindex 2118484da..4e9150536 100644--- a/src/Plugins/Payments.PayPalStandard/Components/PaymentPayPalStandardViewComponent.cs+++ b/src/Plugins/Payments.PayPalStandard/Components/PaymentPayPalStandardViewComponent.cs@@ -8,7 +8,7 @@ namespace Payments.PayPalStandard.Controllers{public IViewComponentResult Invoke(){- return View("~/Plugins/Payments.PayPalStandard/Views/PaymentPayPalStandard/PaymentInfo.cshtml");+ return View(this.GetViewPath());}}}\ No newline at end of filediff --git a/src/Plugins/Payments.PayPalStandard/Controllers/PaymentPayPalStandardController.cs b/src/Plugins/Payments.PayPalStandard/Controllers/PaymentPayPalStandardController.csindex ecac61d39..1d726939e 100644--- a/src/Plugins/Payments.PayPalStandard/Controllers/PaymentPayPalStandardController.cs+++ b/src/Plugins/Payments.PayPalStandard/Controllers/PaymentPayPalStandardController.cs@@ -1,16 +1,23 @@-using Grand.Business.Checkout.Interfaces.Orders;+using Grand.Business.Checkout.Commands.Models.Orders;+using Grand.Business.Checkout.Extensions;+using Grand.Business.Checkout.Interfaces.Orders;using Grand.Business.Checkout.Interfaces.Payments;+using Grand.Business.Checkout.Queries.Models.Orders;+using Grand.Business.Common.Extensions;using Grand.Business.Common.Interfaces.Configuration;using Grand.Business.Common.Interfaces.Localization;+using Grand.Business.Common.Interfaces.Logging;using Grand.Business.Common.Interfaces.Security;using Grand.Business.Common.Interfaces.Stores;-using Grand.Web.Common.Controllers;using Grand.Domain.Orders;using Grand.Domain.Payments;using Grand.Infrastructure;+using Grand.SharedKernel;+using Grand.Web.Common.Controllers;+using MediatR;using Microsoft.AspNetCore.Http;using Microsoft.AspNetCore.Mvc;-using Payments.PayPalStandard.Models;+using Microsoft.Extensions.Primitives;using System;using System.Collections.Generic;using System.Globalization;@@ -18,19 +25,6 @@ using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;-using Grand.Business.Common.Interfaces.Logging;-using Grand.Web.Common.Filters;-using Grand.Business.Common.Services.Security;-using Grand.Domain.Common;-using Grand.Domain.Customers;-using Grand.Business.Checkout.Extensions;-using Grand.SharedKernel;-using Grand.Business.Common.Extensions;-using Grand.SharedKernel.Extensions;-using Microsoft.Extensions.Primitives;-using MediatR;-using Grand.Business.Checkout.Queries.Models.Orders;-using Grand.Business.Checkout.Commands.Models.Orders;namespace Payments.PayPalStandard.Controllers{@@ -38,116 +32,35 @@ namespace Payments.PayPalStandard.Controllerspublic class PaymentPayPalStandardController : BasePaymentController{private readonly IWorkContext _workContext;- private readonly IStoreService _storeService;- private readonly ISettingService _settingService;private readonly IPaymentService _paymentService;private readonly IOrderService _orderService;- private readonly ITranslationService _translationService;private readonly ILogger _logger;private readonly IMediator _mediator;- private readonly IPermissionService _permissionService;private readonly IPaymentTransactionService _paymentTransactionService;private readonly PaymentSettings _paymentSettings;+ private readonly PayPalStandardPaymentSettings _payPalStandardPaymentSettings;- public PaymentPayPalStandardController(IWorkContext workContext,- IStoreService storeService,- ISettingService settingService,+ public PaymentPayPalStandardController(+ IWorkContext workContext,IPaymentService paymentService,IOrderService orderService,- ITranslationService translationService,ILogger logger,IMediator mediator,- IPermissionService permissionService,IPaymentTransactionService paymentTransactionService,+ PayPalStandardPaymentSettings payPalStandardPaymentSettings,PaymentSettings paymentSettings){_workContext = workContext;- _storeService = storeService;- _settingService = settingService;_paymentService = paymentService;_orderService = orderService;- _translationService = translationService;_logger = logger;_mediator = mediator;- _permissionService = permissionService;_paymentTransactionService = paymentTransactionService;+ _payPalStandardPaymentSettings = payPalStandardPaymentSettings;_paymentSettings = paymentSettings;}- protected virtual async Task<string> GetActiveStore(IStoreService storeService, IWorkContext workContext)- {- var stores = await storeService.GetAllStores();- if (stores.Count < 2)- return stores.FirstOrDefault().Id;-- var storeId = workContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.AdminAreaStoreScopeConfiguration);- var store = await storeService.GetStoreById(storeId);-- return store != null ? store.Id : "";- }-- [AuthorizeAdmin]- [Area("Admin")]- public async Task<IActionResult> Configure()- {- if (!await _permissionService.Authorize(StandardPermission.ManagePaymentMethods))- return AccessDeniedView();-- //load settings for a chosen store scope- var storeScope = await GetActiveStore(_storeService, _workContext);- var payPalStandardPaymentSettings = _settingService.LoadSetting<PayPalStandardPaymentSettings>(storeScope);-- var model = new ConfigurationModel();- model.UseSandbox = payPalStandardPaymentSettings.UseSandbox;- model.BusinessEmail = payPalStandardPaymentSettings.BusinessEmail;- model.PdtToken = payPalStandardPaymentSettings.PdtToken;- model.PdtValidateOrderTotal = payPalStandardPaymentSettings.PdtValidateOrderTotal;- model.AdditionalFee = payPalStandardPaymentSettings.AdditionalFee;- model.AdditionalFeePercentage = payPalStandardPaymentSettings.AdditionalFeePercentage;- model.PassProductNamesAndTotals = payPalStandardPaymentSettings.PassProductNamesAndTotals;- model.DisplayOrder = payPalStandardPaymentSettings.DisplayOrder;-- model.StoreScope = storeScope;-- return View("~/Plugins/Payments.PayPalStandard/Views/PaymentPayPalStandard/Configure.cshtml", model);- }-- [HttpPost]- [AuthorizeAdmin]- [Area("Admin")]- public async Task<IActionResult> Configure(ConfigurationModel model)- {- if (!await _permissionService.Authorize(StandardPermission.ManagePaymentMethods))- return AccessDeniedView();-- if (!ModelState.IsValid)- return await Configure();-- //load settings for a chosen store scope- var storeScope = await this.GetActiveStore(_storeService, _workContext);- var payPalStandardPaymentSettings = _settingService.LoadSetting<PayPalStandardPaymentSettings>(storeScope);-- //save settings- payPalStandardPaymentSettings.UseSandbox = model.UseSandbox;- payPalStandardPaymentSettings.BusinessEmail = model.BusinessEmail;- payPalStandardPaymentSettings.PdtToken = model.PdtToken;- payPalStandardPaymentSettings.PdtValidateOrderTotal = model.PdtValidateOrderTotal;- payPalStandardPaymentSettings.AdditionalFee = model.AdditionalFee;- payPalStandardPaymentSettings.AdditionalFeePercentage = model.AdditionalFeePercentage;- payPalStandardPaymentSettings.PassProductNamesAndTotals = model.PassProductNamesAndTotals;- payPalStandardPaymentSettings.DisplayOrder = model.DisplayOrder;-- await _settingService.SaveSetting(payPalStandardPaymentSettings, storeScope);-- //now clear settings cache- await _settingService.ClearCache();- Success(_translationService.GetResource("Admin.Plugins.Saved"));-- return await Configure();- }--private string QueryString(string name){if (StringValues.IsNullOrEmpty(HttpContext.Request.Query[name]))@@ -231,8 +144,7 @@ namespace Payments.PayPalStandard.Controllerssb.AppendLine("New payment status: " + newPaymentStatus);//order note- await _orderService.InsertOrderNote(new OrderNote- {+ await _orderService.InsertOrderNote(new OrderNote {Note = sb.ToString(),DisplayToCustomer = false,CreatedOnUtc = DateTime.UtcNow,@@ -240,18 +152,14 @@ namespace Payments.PayPalStandard.Controllers});//load settings for a chosen store scope- var storeScope = await this.GetActiveStore(_storeService, _workContext);- var payPalStandardPaymentSettings = _settingService.LoadSetting<PayPalStandardPaymentSettings>(storeScope);-//validate order total- if (payPalStandardPaymentSettings.PdtValidateOrderTotal && !Math.Round(mc_gross, 2).Equals(Math.Round(order.OrderTotal * order.CurrencyRate, 2)))+ if (_payPalStandardPaymentSettings.PdtValidateOrderTotal && !Math.Round(mc_gross, 2).Equals(Math.Round(order.OrderTotal * order.CurrencyRate, 2))){string errorStr = string.Format("PayPal PDT. Returned order total {0} doesn't equal order total {1}. Order# {2}.", mc_gross, order.OrderTotal * order.CurrencyRate, order.OrderNumber);_logger.Error(errorStr);//order note- await _orderService.InsertOrderNote(new OrderNote- {+ await _orderService.InsertOrderNote(new OrderNote {Note = errorStr,OrderId = order.Id,DisplayToCustomer = false,@@ -289,8 +197,7 @@ namespace Payments.PayPalStandard.Controllersif (order != null){//order note- await _orderService.InsertOrderNote(new OrderNote- {+ await _orderService.InsertOrderNote(new OrderNote {Note = "PayPal PDT failed. " + response,DisplayToCustomer = false,CreatedOnUtc = DateTime.UtcNow,@@ -387,8 +294,7 @@ namespace Payments.PayPalStandard.Controllersif (order != null){//order note- await _orderService.InsertOrderNote(new OrderNote- {+ await _orderService.InsertOrderNote(new OrderNote {Note = sb.ToString(),DisplayToCustomer = false,CreatedOnUtc = DateTime.UtcNow,@@ -420,8 +326,7 @@ namespace Payments.PayPalStandard.Controllers//log_logger.Error(errorStr);//order note- await _orderService.InsertOrderNote(new OrderNote- {+ await _orderService.InsertOrderNote(new OrderNote {Note = errorStr,DisplayToCustomer = false,CreatedOnUtc = DateTime.UtcNow,@@ -451,8 +356,7 @@ namespace Payments.PayPalStandard.Controllers//log_logger.Error(errorStr);//order note- await _orderService.InsertOrderNote(new OrderNote- {+ await _orderService.InsertOrderNote(new OrderNote {Note = errorStr,DisplayToCustomer = false,CreatedOnUtc = DateTime.UtcNow,diff --git a/src/Plugins/Payments.PayPalStandard/PayPalStandardPaymentDefaults.cs b/src/Plugins/Payments.PayPalStandard/PayPalStandardPaymentDefaults.csindex 3c6ec2c59..8f5f9385f 100644--- a/src/Plugins/Payments.PayPalStandard/PayPalStandardPaymentDefaults.cs+++ b/src/Plugins/Payments.PayPalStandard/PayPalStandardPaymentDefaults.cs@@ -4,6 +4,6 @@{public const string ProviderSystemName = "Payments.PayPalStandard";public const string FriendlyName = "Payments.PayPalStandard.FriendlyName";- public const string ConfigurationUrl = "/Admin/PaymentPayPalStandard/Configure";+ public const string ConfigurationUrl = "/Admin/PayPalStandard/Configure";}}diff --git a/src/Plugins/Payments.PayPalStandard/Payments.PayPalStandard.csproj b/src/Plugins/Payments.PayPalStandard/Payments.PayPalStandard.csprojindex 41de6a234..e31599add 100644--- a/src/Plugins/Payments.PayPalStandard/Payments.PayPalStandard.csproj+++ b/src/Plugins/Payments.PayPalStandard/Payments.PayPalStandard.csproj@@ -1,4 +1,4 @@-<Project Sdk="Microsoft.NET.Sdk">+<Project Sdk="Microsoft.NET.Sdk.Razor"><PropertyGroup><TargetFramework>net5.0</TargetFramework>@@ -7,6 +7,7 @@<Company>UNIT-SOFT Sp. z o.o.</Company><PackageProjectUrl>https://grandnode.com/</PackageProjectUrl><TieredCompilation>true</TieredCompilation>+ <AddRazorSupportForMvc>true</AddRazorSupportForMvc></PropertyGroup><PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">@@ -74,15 +75,6 @@<None Update="logo.jpg"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></None>- <None Update="Views\PaymentPayPalStandard\Configure.cshtml">- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>- </None>- <None Update="Views\PaymentPayPalStandard\PaymentInfo.cshtml">- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>- </None>- <None Update="Views\PaymentPayPalStandard\_ViewImports.cshtml">- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>- </None></ItemGroup></Project>\ No newline at end of filediff --git a/src/Plugins/Payments.PayPalStandard/Views/PaymentPayPalStandard/PaymentInfo.cshtml b/src/Plugins/Payments.PayPalStandard/Views/Shared/Components/PaymentPayPalStandard/Default.cshtmlsimilarity index 100%rename from src/Plugins/Payments.PayPalStandard/Views/PaymentPayPalStandard/PaymentInfo.cshtmlrename to src/Plugins/Payments.PayPalStandard/Views/Shared/Components/PaymentPayPalStandard/Default.cshtmldiff --git a/src/Plugins/Payments.PayPalStandard/Views/_ViewImports.cshtml b/src/Plugins/Payments.PayPalStandard/Views/_ViewImports.cshtmlnew file mode 100644index 000000000..2fb08c043--- /dev/null+++ b/src/Plugins/Payments.PayPalStandard/Views/_ViewImports.cshtml@@ -0,0 +1,8 @@+@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers+@addTagHelper *, Grand.Web.Common+@addTagHelper *, Grand.Web++@using Microsoft.AspNetCore.Mvc.ViewFeatures+@using Grand.Infrastructure.Extensions++@inject Grand.Web.Common.Localization.LocService Loc