Skip to content

Commit

Permalink
feat: upgrade to nopCommerce 430
Browse files Browse the repository at this point in the history
  • Loading branch information
mewajda committed Oct 27, 2021
1 parent 7924d09 commit 5c836e5
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 79 deletions.
16 changes: 11 additions & 5 deletions Nixtus.Plugin.Payments.Nmi/Components/NmiViewComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
using Nixtus.Plugin.Payments.Nmi.Dtos;
using Nixtus.Plugin.Payments.Nmi.Models;
using Nop.Core;
using Nop.Core.Domain.Customers;
using Nop.Services.Common;
using Nop.Services.Customers;
using Nop.Services.Logging;
using Nop.Web.Framework.Components;

Expand All @@ -21,27 +21,32 @@ public class NmiViewComponent : NopViewComponent
private readonly IWorkContext _workContext;
private readonly ILogger _logger;
private readonly NmiPaymentSettings _nmiPaymentSettings;
private readonly ICustomerService _customerService;
private readonly IGenericAttributeService _genericAttributeService;
private readonly HttpClient _httpClient = new HttpClient();
private const string NMI_QUERY_URL = "https://msgpay.transactiongateway.com/api/query.php";

public NmiViewComponent(IWorkContext workContext, ILogger logger, NmiPaymentSettings nmiPaymentSettings)
public NmiViewComponent(IWorkContext workContext, ILogger logger, NmiPaymentSettings nmiPaymentSettings,
ICustomerService customerService, IGenericAttributeService genericAttributeService)
{
_workContext = workContext;
_logger = logger;
_nmiPaymentSettings = nmiPaymentSettings;
_customerService = customerService;
_genericAttributeService = genericAttributeService;
}

public IViewComponentResult Invoke()
{
var model = new PaymentInfoModel
{
IsGuest = _workContext.CurrentCustomer.IsGuest(),
IsGuest = _customerService.IsGuest(_workContext.CurrentCustomer),
AllowCustomerToSaveCards = _nmiPaymentSettings.AllowCustomerToSaveCards
};

if (_nmiPaymentSettings.AllowCustomerToSaveCards)
{
if (!string.IsNullOrEmpty(_workContext.CurrentCustomer.GetAttribute<string>(Constants.CustomerVaultIdKey)))
if (!string.IsNullOrEmpty(_genericAttributeService.GetAttribute<string>(_workContext.CurrentCustomer, Constants.CustomerVaultIdKey)))
{
PopulateStoredCards(model);
}
Expand All @@ -61,7 +66,7 @@ private void PopulateStoredCards(PaymentInfoModel model)
{ "username", _nmiPaymentSettings.Username },
{ "password", _nmiPaymentSettings.Password },
{ "report_type", "customer_vault" },
{ "customer_vault_id", _workContext.CurrentCustomer.GetAttribute<string>(Constants.CustomerVaultIdKey) },
{ "customer_vault_id", _genericAttributeService.GetAttribute<string>(_workContext.CurrentCustomer, Constants.CustomerVaultIdKey) },
// this is an undocumented variable which will make the API return multiple billings (aka credit cards)
{ "ver", "2" }
};
Expand Down Expand Up @@ -105,6 +110,7 @@ private NmiQueryResponse DeserializeXml(string xml)
}
catch (Exception e)
{
_logger.Error("Error parsing xml", e);
return null;
}
}
Expand Down
13 changes: 9 additions & 4 deletions Nixtus.Plugin.Payments.Nmi/Controllers/PaymentNmiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Nop.Services;
using Nop.Services.Configuration;
using Nop.Services.Localization;
using Nop.Services.Messages;
using Nop.Services.Security;
using Nop.Services.Stores;
using Nop.Web.Framework;
Expand All @@ -20,18 +21,22 @@ public class PaymentNmiController : BasePaymentController
private readonly IStoreService _storeService;
private readonly IWorkContext _workContext;
private readonly IPermissionService _permissionService;
private readonly IStoreContext _storeContext;
private readonly INotificationService _notificationService;

public PaymentNmiController(ILocalizationService localizationService,
ISettingService settingService,
IStoreService storeService,
IWorkContext workContext,
IPermissionService permissionService)
IPermissionService permissionService, IStoreContext storeContext, INotificationService notificationService)
{
_localizationService = localizationService;
_settingService = settingService;
_storeService = storeService;
_workContext = workContext;
_permissionService = permissionService;
_storeContext = storeContext;
_notificationService = notificationService;
}

[AuthorizeAdmin]
Expand All @@ -42,7 +47,7 @@ public IActionResult Configure()
return AccessDeniedView();

//load settings for a chosen store scope
var storeScope = GetActiveStoreScopeConfiguration(_storeService, _workContext);
var storeScope = _storeContext.ActiveStoreScopeConfiguration;
var nmiPaymentSettings = _settingService.LoadSetting<NmiPaymentSettings>(storeScope);

var model = new ConfigurationModel
Expand Down Expand Up @@ -88,7 +93,7 @@ public IActionResult Configure(ConfigurationModel model)
return Configure();

//load settings for a chosen store scope
var storeScope = GetActiveStoreScopeConfiguration(_storeService, _workContext);
var storeScope = _storeContext.ActiveStoreScopeConfiguration;
var nmiPaymentSettings = _settingService.LoadSetting<NmiPaymentSettings>(storeScope);

//save settings
Expand Down Expand Up @@ -118,7 +123,7 @@ public IActionResult Configure(ConfigurationModel model)
//now clear settings cache
_settingService.ClearCache();

SuccessNotification(_localizationService.GetResource("Admin.Plugins.Saved"));
_notificationService.SuccessNotification(_localizationService.GetResource("Admin.Plugins.Saved"));

return Configure();
}
Expand Down
3 changes: 1 addition & 2 deletions Nixtus.Plugin.Payments.Nmi/Models/ConfigurationModel.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using Microsoft.AspNetCore.Mvc.Rendering;
using Nop.Web.Framework.Mvc.ModelBinding;
using Nop.Web.Framework.Mvc.Models;

namespace Nixtus.Plugin.Payments.Nmi.Models
{
public class ConfigurationModel : BaseNopModel
public class ConfigurationModel
{
public int ActiveStoreScopeConfiguration { get; set; }

Expand Down
5 changes: 2 additions & 3 deletions Nixtus.Plugin.Payments.Nmi/Models/PaymentInfoModel.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc.Rendering;
using Nop.Web.Framework.Mvc.ModelBinding;
using Nop.Web.Framework.Mvc.Models;

namespace Nixtus.Plugin.Payments.Nmi.Models
{
public class PaymentInfoModel : BaseNopModel
public class PaymentInfoModel
{
public PaymentInfoModel()
{
StoredCards = new List<SelectListItem>();
}

// These properties are only used to display label on the payment info screen
[NopResourceDisplayName("Payment.CardNumber")]
public string CardNumber { get; set; }
Expand Down
5 changes: 3 additions & 2 deletions Nixtus.Plugin.Payments.Nmi/Nixtus.Plugin.Payments.Nmi.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Copyright>Copyright © Nixtus, LLC</Copyright>
<Company>Nixtus, LLC</Company>
<Authors>Nixtus, LLC</Authors>
<Version>1.00</Version>
<Version>1.30</Version>
<Description>This plugin allows paying with NMI (Network Merchants Inc)</Description>
<PackageLicenseUrl></PackageLicenseUrl>
<PackageProjectUrl></PackageProjectUrl>
Expand Down Expand Up @@ -50,6 +50,7 @@

<ItemGroup>
<ProjectReference Include="..\..\Presentation\Nop.Web.Framework\Nop.Web.Framework.csproj" />
<ClearPluginAssemblies Include="$(MSBuildProjectDirectory)\..\..\Build\ClearPluginAssemblies.proj" />
</ItemGroup>

<!-- This target execute after "Build" target -->
Expand Down
Loading

0 comments on commit 5c836e5

Please sign in to comment.