Paystack.NET Client is a .NET package designed to provide seamless integration with the Paystack API. It is a portable class library that facilitates easy access to various Paystack services, enabling developers to effortlessly manage payments, transactions, and more within their .NET applications.
Whether you're building a payment gateway, managing transactions, or integrating with Paystack's rich feature set, Paystack.NET Client streamlines the process, saving you development time and effort.
Using the .NET Core command-line interface (CLI) tools:
dotnet add package Paystack.NET.Client
Using the NuGet Command Line Interface (CLI):
nuget install Paystack.NET.Client
Using the Package Manager Console:
Install-Package Paystack.NET.Client
From within Visual Studio:
- Open the Solution Explorer.
- Right-click on a project within your solution.
- Click on Manage NuGet Packages...
- Click on the Browse tab and search for "Paystack.NET".
- Click on the Paystack.NET package, select the appropriate version in the right-tab and click Install.
For a comprehensive list of examples, check out the Examples Project.
Paystack authenticates API requests using your account’s secret key, which you can find in the Paystack Dashboard (Settings > API Keys & Webhooks)
Use Configure method in PaystackConfiguration to set the Secret Key and the Base URL if needed.
PaystackConfiguration.Configure("sk_test_...");
Initialize a Transaction
using Paystack.NET.Configuration;
using Paystack.NET.Services.Transactions;
using Paystack.NET.Models.Transactions.Options;
PaystackConfiguration.Configure("sk_test_...");
var transactionService = new TransactionService();
var initializeOptions = new InitializeTransactionOptions
{
Reference = "TEST-" + DateTime.Now.ToString("yyyyMMddHHmmss");
Amount = 5000, // Amount in pesewas
Email = "customer@example.com"
};
var response = await transactionService.Initialize(initializeOptions);
Console.WriteLine($"Transaction Reference: {response.Data.Reference}");
Verify a Transaction
var reference = "TRANSACTION_REFERENCE_HERE";
var response = await transactionService.Verify(reference);
if (response.Data is { Status: TransactionStatus.Success })
{
Console.WriteLine("Transaction successful!");
}
Setup a Callback (Webhook)
using Paystack.NET.Services.Callback;
var requestBody = "{ ... }"; // Raw request body from Paystack webhook
var signatureHeader = "X-Paystack-Signature header from request";
var callbackService = new CallbackService();
try
{
var callback = callbackService.HandleCallback(requestBody, signatureHeader);
Console.WriteLine($"Event: {callback.Event}");
Console.WriteLine($"Data: {callback.Data}");
}
catch (UnauthorizedAccessException)
{
Console.WriteLine("Invalid webhook signature.");
}
Contribution guidelines for this project
.NET 8 is required to build and test Paystack.NET SDK, you can install it from get.dot.net.
For any requests, bug or comments, please open an issue or submit a pull request.