Nopcommerce 4.20 Payment Plugin - Plugin Configure Error - "Page not found"

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
Hi,

I am updating a payment plugin I developed for nopCommerce 3.9 to nopCommerce 4.20.

I can get nopCommerce 4.20 to install the plugin without any problems. However when I click on the "Configure" button I get a "Page not found" error.

I searched these forums for similar issues, and double-checked the following:


1)   GetConfigurationPageUrl:

        public override string GetConfigurationPageUrl()
        {
            return $"{_webHelper.GetStoreLocation()}Admin/SagePay/Configure";
        }

2)   GetPublicViewComponentName:

        public string GetPublicViewComponentName()
        {
            return "SagePay";
        }

3)   File located of the Views folder:

    - _ViewImports.cshtml
    - Configure.cshtml
    - PaymentInfo.cshtml

4)   Contents of my Configure.cshtml file:

@model Nop.Plugin.Payments.SagePay.Models.ConfigurationModel
@inject Nop.Core.IWebHelper webHelper
@{
    Layout = "";
}

@await Component.InvokeAsync("StoreScopeConfiguration")


<form asp-controller="PaymentSagePay" asp-action="Configure" method="post">
    <div class="panel-group">
        <div class="panel panel-default">
            <div class="panel-body">
                <h5>This payment plugin is for use with the Sage PayNow Payment Gateway South Africa.</h5>
                <div class="form-group">
                    <div class="col-md-3">
                        <nop-override-store-checkbox asp-for="MerchantId_OverrideForStore" asp-input="MerchantId" asp-store-scope="@Model.ActiveStoreScopeConfiguration" />
                        <nop-label asp-for="MerchantId" />
                    </div>
                    <div class="col-md-9">
                        <nop-editor asp-for="MerchantId" />
                        <span asp-validation-for="MerchantId"></span>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        <nop-override-store-checkbox asp-for="SagePayServiceKey_OverrideForStore" asp-input="SagePayServiceKey" asp-store-scope="@Model.ActiveStoreScopeConfiguration" />
                        <nop-label asp-for="SagePayServiceKey" />
                    </div>
                    <div class="col-md-9">
                        <nop-editor asp-for="SagePayServiceKey" />
                        <span asp-validation-for="SagePayServiceKey"></span>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-9 col-md-offset-3">
                        <input type="submit" name="save" class="btn bg-primary" value="@T("Admin.Common.Save")" />
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>

5)   My Configure Method in my plugin Controller:

    [AuthorizeAdmin]
    [Area(AreaNames.Admin)]
    public IActionResult Configure()
    {
      if (!_permissionService.Authorize(StandardPermissionProvider.ManagePaymentMethods))
        return AccessDeniedView();

      //load settings for a chosen store scope
      var storeScope = _storeContext.ActiveStoreScopeConfiguration;
      var sagePayPaymentSettings = _settingService.LoadSetting<SagePayPaymentSettings>(storeScope);

      var model = new ConfigurationModel
      {
        MerchantId = sagePayPaymentSettings.MerchantId,
        SagePayServiceKey = sagePayPaymentSettings.SagePayServiceKey

      };

      if (storeScope <= 0)
        return View("~/Plugins/Payments.SagePay/Views/Configure.cshtml", model);

      model.MerchantId_OverrideForStore = _settingService.SettingExists(sagePayPaymentSettings, x => x.MerchantId, storeScope);
      model.SagePayServiceKey_OverrideForStore = _settingService.SettingExists(sagePayPaymentSettings, x => x.SagePayServiceKey, storeScope);

      return View("~/Plugins/Payments.SagePay/Views/Configure.cshtml", model);
    }


Am I doing something wrong, or perhaps missing something? I've also tried clearing the cache, uninstalling the plugin and re-installing it.

Any suggestions would be greatly appreciated.

Regards
Jaco Ferreira
4 years ago
You said you could install the plugin so the build must have worked and copied files to ~/Plugins/Payments.SagePay

I assume you have checked the ~/Plugins/Payments.SagePay/Views/Configure.cshtml file exists ?
4 years ago
Hi Yidna,

Thanks for the reply...

Yes, I can see the files sitting in the Views folder.

This is what my Project file (Nop.Plugin.Payments.SagePay.csproj) looks like:

----------------------->>

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>netcoreapp2.2</TargetFramework>
        <Copyright>Copyright © Sage Pay, 2019</Copyright>
        <Company>Sage Pay</Company>
        <Authors>Jaco Ferreira, Teknique Studios</Authors>
        <PackageLicenseUrl>http://www.nopcommerce.com/</PackageLicenseUrl>
        <PackageProjectUrl>http://www.nopcommerce.com/</PackageProjectUrl>
        <RepositoryUrl></RepositoryUrl>
        <RepositoryType>Git</RepositoryType>
        <OutputPath>..\..\Presentation\Nop.Web\Plugins\Payments.SagePay</OutputPath>
        <OutDir>$(OutputPath)</OutDir>
        <!--Set this parameter to true to get the dlls copied from the NuGet cache to the output of your    project. You need to set this parameter to true if your plugin has a nuget package to ensure that   the dlls copied from the NuGet cache to the output of your project-->
        <CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
    </PropertyGroup>
  
  <ItemGroup>
    <None Remove="logo.png" />
    <None Remove="plugin.json" />
    <None Remove="Views\_ViewImports.cshtml" />
    <None Remove="Views\Configure.cshtml" />
    <None Remove="Views\PaymentInfo.cshtml" />
    <None Remove="Views\SagePayResultAccept.cshtml" />
    <None Remove="Views\SagePayResultDecline.cshtml" />
    <None Remove="Views\SagePayResultNotify.cshtml" />
    <None Remove="Views\SagePayResultRedirect.cshtml" />
  </ItemGroup>
  
  <ItemGroup>
    <Content Include="logo.png">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
    <Content Include="plugin.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
    <Content Include="Views\_ViewImports.cshtml">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
    <Content Include="Views\Configure.cshtml">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
    <Content Include="Views\PaymentInfo.cshtml">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
    <Content Include="Views\SagePayResultAccept.cshtml">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
    <Content Include="Views\SagePayResultDecline.cshtml">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
    <Content Include="Views\SagePayResultNotify.cshtml">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
    <Content Include="Views\SagePayResultRedirect.cshtml">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
  
  <ItemGroup>
        <ProjectReference Include="..\..\Presentation\Nop.Web.Framework\Nop.Web.Framework.csproj" />
    <ClearPluginAssemblies Include="$(MSBuildProjectDirectory)\..\..\Build\ClearPluginAssemblies.proj" />
    </ItemGroup>

    <!-- This target execute after "Build" target -->
    <Target Name="NopTarget" AfterTargets="Build">
        <!-- Delete unnecessary libraries from plugins path -->
        <MSBuild Projects="@(ClearPluginAssemblies)" Properties="PluginPath=$(MSBuildProjectDirectory)\ $(OutDir)" Targets="NopClear" />
    </Target>
  
</Project>

----------------------->>
4 years ago
I solved the problem...

Sometimes you try and find the complex solutions for a bug in your code, when the simple, "back to basics" solution is the one that works.

Changed the following to match my Controller name, which is "PaymentSagePay":

       public override string GetConfigurationPageUrl()
        {
            return $"{_webHelper.GetStoreLocation()}Admin/SagePay/Configure";
        }

to...

       public override string GetConfigurationPageUrl()
        {
            return $"{_webHelper.GetStoreLocation()}Admin/PaymentSagePay/Configure";
        }


and...


        public string GetPublicViewComponentName()
        {
            return "SagePay";
        }

to...

        public string GetPublicViewComponentName()
        {
            return "PaymentSagePay";
        }


This did the trick for me.

Thanks you Yidna for the reply... all sorted now!

Regards

Jaco
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.