A .NET client SDK for integrating Zarinpal payment gateway into your applications.
- Easy integration with Zarinpal payment gateway
- Support for both Sandbox and Production environments
- Async/await support for all operations
- Strongly typed request/response models
- Dependency injection support
- Built with .NET 9.0+
- Register the Zarinpal client in your dependency injection container:
services.AddZarinpalClient(new ZarinpalClientSettings
{
MerchantId = "your-merchant-id",
PaymentCallBackUrl = "https://your-domain.com/callback",
PaymentMode = PaymentMode.Sandbox // or PaymentMode.Production
});- Inject and use the ZarinpalClientService in your application:
public class PaymentController
{
private readonly ZarinpalClientService _zarinpalClient;
public PaymentController(ZarinpalClientService zarinpalClient)
{
_zarinpalClient = zarinpalClient;
}
public async Task<IActionResult> CreatePayment()
{
var request = new PaymentRequest
{
Amount = 1000, // Amount in Toman
Description = "Payment for order #123",
CallbackUrl = "https://your-domain.com/callback"
};
var response = await _zarinpalClient.CreatePaymentRequest(request);
if (response?.Data?.Code == 100)
{
return Redirect($"https://sandbox.zarinpal.com/pg/StartPay/{response.Data.Authority}");
}
return BadRequest(response?.Errors);
}
public async Task<IActionResult> VerifyPayment(string authority, string status)
{
if (status != "OK")
return BadRequest("Payment was not successful");
var request = new VerifyRequest
{
Amount = 1000, // Amount in Toman
Authority = authority
};
var response = await _zarinpalClient.VerifyPayment(request);
if (response?.Data?.Code == 100)
{
// Payment was successful
return Ok(response.Data);
}
return BadRequest(response?.Errors);
}
}The ZarinpalClientSettings class requires the following properties:
MerchantId: Your Zarinpal merchant IDPaymentCallBackUrl: The URL where Zarinpal will redirect after paymentPaymentMode: EitherSandboxorProduction
- .NET 9.0 SDK or later
- Visual Studio 2022 or later / VS Code with C# extension
dotnet builddotnet test- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions, please file an issue on the GitHub repository.