Msh.Zarinpal.Api 1.0.3

dotnet add package Msh.Zarinpal.Api --version 1.0.3
NuGet\Install-Package Msh.Zarinpal.Api -Version 1.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Msh.Zarinpal.Api" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Msh.Zarinpal.Api --version 1.0.3
#r "nuget: Msh.Zarinpal.Api, 1.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Msh.Zarinpal.Api as a Cake Addin
#addin nuget:?package=Msh.Zarinpal.Api&version=1.0.3

// Install Msh.Zarinpal.Api as a Cake Tool
#tool nuget:?package=Msh.Zarinpal.Api&version=1.0.3

Msh.Zarinpal.Api

A light weight library to help online payment using Zarinpal for .NET core 2.2 web application.

Installation

You can download the latest version of Msh.Zarinpal.Api from Github repository. To install via nuget:

Install-Package Msh.Zarinpal.Api -Version 1.0.3

Install from Nuget directly.

How to use

Add these codes to startup.cs file:

using Zarinpal.Api;
using Zarinpal.Api.Models;
...
    public void ConfigureServices(IServiceCollection services)
    {
        services.Configure<ZarinpalConfiguration>(opt => Configuration.GetSection("ZarinpalConfig").Bind(opt));
        ...
        services.AddZarinpal();
    }
...

and some where in appsettings.json

  "ZarinpalConfig": {
    "Token": "Put your api token here",
    "UseSandbox": false,
    "UseZarinLink":  true
  }

in controller:

using Zarinpal.Api;
using Zarinpal.Api.Models;
...
    public class HomeController : Controller
    {
        private readonly IOptionsSnapshot<ZarinpalConfiguration> options;
        private readonly IZarinpalProvider _zarinpal;

        public HomeController(IOptionsSnapshot<ZarinpalConfiguration> options, IZarinpalProvider zarinpal)
        {
            _options = options;
            _zarinpal = zarinpal;
        }

        public IActionResult Index(string referenceId = null)
        {
            if (string.IsNullOrWhiteSpace(referenceId))
                return View();
            return Content(referenceId);
        }

        public async Task<IActionResult> StartPayment()
        {
            var model = new ZarinpalPaymentRequestModel
            {
                Amount = 2000,
                Description = "Some description goes here",
                CallbackUrl = "https://<domain>.com/PaymentResult",
                Email = "Client email",
                Mobile = "Client mobile"
            };
            //var t = await _zarinpal.InvokePaymentAsync(model);
            var t = await _zarinpal.PayAsync(model);
            if (t.Succeeded)
                return Redirect(t.Result.PaymentUrl);

            return BadRequest(t.Errors);
        }

        public IActionResult PaymentResult(string authority, string status)
        {
            var t = long.Parse(authority);
            //var result = _zarinpal.InvokePaymentVerification(new ZarinpalPaymentVerificationModel(2000, authority));
            var result = await _zarinpal.VerifyAsync(new ZarinpalPaymentVerificationModel(1000, authority));
            if (result.Succeeded)
                return RedirectToAction("Index", new { referenceId = result.Result.ReferenceId });

            return BadRequest(result.Errors);
        }
    }
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.2 is compatible.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 1,109 10/29/2019
1.0.2 468 9/23/2019
1.0.1 459 9/5/2019
1.0.0 468 9/2/2019