Skip to content

Epinova/Epinova.NetsPaymentGateway

Repository files navigation

Epinova.NetsPaymentGateway

Epinova's take on a NETS payment gateway API.

Quality Gate Status Build status Tests License: MIT

Getting Started

Configuration

No configuration via config files are needed. The MerchantInfo passed in to each method described in IPaymentGatewayService dictates merchant info and environment to be used (test or production).

Set up payment transact example:

public class NetsProcessor : IPaymentGatewayProcessor
{
    private readonly IPaymentGatewayService _paymentGateway;

    public NetsProcessor(IPaymentGatewayService paymentGateway)
    {
        _paymentGateway = paymentGateway;
    }

    public async Task<PaymentSetupModel> InitializePaymentAsync(string orderNumber, decimal totalAmount)
    {
        var request = new RegisterRequest
        {
            Amount = totalAmount,
            CurrencyCode = "NOK",
            OrderDescription = "Order description. Line by line.",
            OrderNumber = orderNumber,
            RedirectUrl = new Uri($"https://absolute.url/to/your/site/NetsCallBack?orderNumber={orderNumber}")
        };
        //Send in specific payment method, or leave blank to use default payment methods defined in MerchantInfo model.
        //request.PaymentMethods.Add("Vipps");

        RegisterResponse response = await _paymentGateway.RegisterAsync(GetMerchantInfo(), request);

        return new PaymentSetupModel(registerResponse.TransactionId, registerResponse.TerminalUrl);
    }
 
    private static MerchantInfo GetMerchantInfo()
    {
        return new MerchantInfo
        {
            IsTestEnvironment = Boolean.Parse(ConfigurationManager.AppSettings["Nets.IsTestMode"] ?? "false"),
            MerchantId = ConfigurationManager.AppSettings["Nets.MerchantId"],
            Token = ConfigurationManager.AppSettings["Nets.Token"],
            DefaultPaymentMethods = (ConfigurationManager.AppSettings[$"Nets.DefaultPaymentMethods"] ?? String.Empty)
                .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(x => x.Trim())
                .ToArray(),
            ValidCallbackIPs = (ConfigurationManager.AppSettings["Nets.ValidCallbackIPs"]?.Split(',') ?? Enumerable.Empty<string>())
                .Select(ip => IPAddress.TryParse(ip.Trim(), out IPAddress parsedIp) ? parsedIp : IPAddress.None)
                .Where(ip => !ip.Equals(IPAddress.None)).ToArray()
            };
        }
}

web.config:

<configuration>
    <appSettings>
        <add key="Nets.IsTestMode" value="true" />
        <add key="Nets.MerchantId" value="1337" />
        <add key="Nets.Token" value="xyzabc" />
        <add key="Nets.DefaultPaymentMethods" value="Visa, MasterCard" />
        <add key="Nets.ValidCallbackIPs" value="127.0.0.1" />
    <appSettings>
</configuration>

Add registry to IoC container

if using Structuremap:

container.Configure(
    x =>
    {
        x.Scan(y =>
        {
            y.TheCallingAssembly();
            y.WithDefaultConventions();
        });

        x.AddRegistry<Epinova.NetsPaymentGateway.PaymentGatewayRegistry>();
    });

If you cannot use the structuremap registry provided with this module, you can manually set up PaymentGatewayService for IPaymentGatewayService

Inject contract and use service

Epinova.NetsPaymentGateway.IPaymentGatewayService describes the NETS payment gateway service.

Prerequisites

Installing

The module is published on nuget.org.

nuget install Epinova.NetsPaymentGateway

Target framework

  • .NET Standard 2.0
  • Tests target .NET Core 2.1

Authors

  • Tarjei Olsen - Initial work - apeneve

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details

Further reading

Netaxept Technical documentation

About

Epinova's take on a NETS payment gateway API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages