-
Notifications
You must be signed in to change notification settings - Fork 0
WebApplication
MohammadReza edited this page Jan 7, 2022
·
1 revision
To use this library in a asp dotnet app you can install ZarinpalSharp.Asp from nuget.
This is simple extension package and you don't really need that. just take a look at AspExtensions.cs so you can see!
After installation you should add ZarinClient
to IServicesCollection
in Startup.cs
file, like below:
- Add reference to ZarinpalSharp.Asp.
using ZarinSharp.Asp;
- Add
ZarinClient
with configurations.
// Add Zarinpal client with Configurations specified in appsettings.json
services.AddZarinClient(Configuration.GetZarinpalConfiguration());
- Add configurations to
appsettings.json
- (
GetZarinpalConfiguration()
Reads configs fromappsettings.json
)
"ZarinpalConfiguration": {
"Token": "1344b5d4-0048-11e8-94db-005056a205be",
"CallbackUrl": "http://yoursite.com/verify"
}
- Use client in your Controller or anywhere else using DI.
// Get ZarinClient from services collection via DI.
private readonly IZarinClient _zarinClient;
public PaymentController(IZarinClient zarinClient)
{
_zarinClient = zarinClient;
}
#region Request Payment
[HttpGet]
public async Task<ZarinpalPaymentRequestRespond> GetAsync()
{
// Request a payment.
return await _zarinClient.PaymentRequestAsync(20000, "This is my payment!");
}
#endregion
Created with 🧡.