https://github.com/salman-basmechi/zarinpal-driver
ZarinPal payment gateway driver in c#
https://github.com/salman-basmechi/zarinpal-driver
csharp zarinpal zarinpal-driver zarinpal-gateway zarinpal-payment-service
Last synced: 12 months ago
JSON representation
ZarinPal payment gateway driver in c#
- Host: GitHub
- URL: https://github.com/salman-basmechi/zarinpal-driver
- Owner: salman-basmechi
- Created: 2020-07-20T18:15:17.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-06-23T06:45:23.000Z (about 4 years ago)
- Last Synced: 2025-07-15T07:36:49.294Z (12 months ago)
- Topics: csharp, zarinpal, zarinpal-driver, zarinpal-gateway, zarinpal-payment-service
- Language: C#
- Homepage:
- Size: 40 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ZarinPal Driver
ZarinPal payment gateway driver in c#
You can get the latest stable release from the [nuget.org](http://www.nuget.org/packages/zarinpaldriver) or from [github releases page](https://github.com/salmanbasmechi/zarinpaldriver/releases).
Getting Started
---------------
```C#
using ZarinPalDriver;
```
```C#
public void ConfigureServices(IServiceCollection services)
{
services.AddZarinPalDriver();
}
```
```C#
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using ZarinPalDriver;
using ZarinPalDriver.Models;
namespace WebApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class ProductController : ControllerBase
{
[HttpPost]
public async Task PurchaseRequest([FromServices] IZarinPalClient client)
{
var mode = Mode.SandBox;
var request = new PaymentRequest
{
MerchantId = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
Amount = 1000,
Email = "salmanbasmechi@gmail.com",
Mobile = "09129335607",
Description = "Test Payment",
CallbackUrl = "http://localhost:5000/api/product/completepurchase",
Mode = mode
};
var response = await client.SendAsync(request);
if(response.Status != Status.Success)
{
return BadRequest();
}
return Redirect(response.GatewayUri.AbsoluteUri);
}
[HttpPost, HttpGet]
public async Task CompletePurchase([FromServices] IZarinPalClient client)
{
var mode = Mode.SandBox;
string status = Request.Query["status"];
string authority = Request.Query["authority"];
if (string.IsNullOrEmpty(status) || string.IsNullOrEmpty(authority) || status.ToLower() != "ok")
{
return BadRequest();
}
var request = new VerificationRequest
{
MerchantId = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
Amount = 1000,
Authority = authority,
Mode = mode
};
var response = await client.SendAsync(request);
if (response.Status != Status.Success)
{
return BadRequest($"Payment with reference id '{response.ReferenceId}' failed.");
}
return Ok(response.ReferenceId);
}
}
}
```