Paystack.Client.Sdk
1.1.0
dotnet add package Paystack.Client.Sdk --version 1.1.0
NuGet\Install-Package Paystack.Client.Sdk -Version 1.1.0
<PackageReference Include="Paystack.Client.Sdk" Version="1.1.0" />
<PackageVersion Include="Paystack.Client.Sdk" Version="1.1.0" />
<PackageReference Include="Paystack.Client.Sdk" />
paket add Paystack.Client.Sdk --version 1.1.0
#r "nuget: Paystack.Client.Sdk, 1.1.0"
#:package Paystack.Client.Sdk@1.1.0
#addin nuget:?package=Paystack.Client.Sdk&version=1.1.0
#tool nuget:?package=Paystack.Client.Sdk&version=1.1.0
Paystack.Client.Sdk
A .NET 8 SDK for integrating with the Paystack payment gateway. Provides a clean, strongly-typed client for initializing transactions and verifying payment status.
Installation
Install via NuGet Package Manager Console:
Install-Package Paystack.Client.Sdk
Or via the .NET CLI:
dotnet add package Paystack.Client.Sdk
Requirements
- .NET 8.0 or later
- A Paystack account and secret key — get yours at paystack.com
Configuration
Add a PaystackConfig section to your appsettings.json:
{
"PaystackConfig": {
"BaseUrl": "https://api.paystack.co",
"SecretKey": "sk_live_your_secret_key_here"
}
}
Use
sk_test_...keys during development andsk_live_...in production.
Setup
Register the SDK in your Program.cs or Startup.cs:
using Paystack.Client.Sdk.Extensions;
builder.Services.AddPaystackClient(builder.Configuration);
This registers IPaystackClient as a scoped dependency, ready for constructor injection.
Usage
Inject IPaystackClient wherever you need it:
public class PaymentService
{
private readonly IPaystackClient _paystack;
public PaymentService(IPaystackClient paystack)
{
_paystack = paystack;
}
}
Initialize a Transaction
Start a payment by creating a transaction. Paystack returns an authorization URL to redirect the user to.
Important: Paystack expects amounts in the smallest currency unit (kobo for NGN). Multiply naira amounts by 100.
var request = new PaystackInitializeTransactionRequest
{
Email = "customer@example.com",
Amount = 5000 * 100, // ₦5,000 in kobo
Reference = Guid.NewGuid().ToString("N"),
CallbackUrl = "https://yourapp.com/payment/callback",
MetaData = new { orderId = "ORD-001" }
};
var result = await _paystack.InitializeTransaction(request);
if (result.Data?.Status == true)
{
var authorizationUrl = result.Data.Data?.AuthorizationUrl;
// redirect the user to authorizationUrl
}
PaystackInitializeTransactionRequest fields:
| Property | Type | Description |
|---|---|---|
Email |
string |
Customer's email address |
Amount |
decimal |
Amount in the smallest currency unit (e.g. kobo for NGN) |
Reference |
string |
Unique transaction reference |
CallbackUrl |
string |
URL Paystack redirects to after payment |
MetaData |
object |
Any extra data to attach to the transaction |
Verify a Transaction
After the user completes payment, verify the transaction using the reference:
var result = await _paystack.CheckTransactionStatus("your-transaction-reference");
if (result.Data?.Status == true)
{
var transaction = result.Data.Data;
Console.WriteLine($"Status: {transaction?.Status}");
Console.WriteLine($"Amount: {transaction?.Amount}");
Console.WriteLine($"Channel: {transaction?.Channel}");
Console.WriteLine($"Paid At: {transaction?.PaidAt}");
var customer = transaction?.Customer;
Console.WriteLine($"Customer: {customer?.FirstName} {customer?.LastName} ({customer?.Email})");
var auth = transaction?.Authorization;
Console.WriteLine($"Card: {auth?.CardType} ending {auth?.Last4}");
}
Using a Per-Request API Key
Both methods accept an optional apiKey parameter to override the configured secret key. Useful for multi-tenant scenarios:
var result = await _paystack.InitializeTransaction(request, apiKey: "sk_live_tenant_key");
var status = await _paystack.CheckTransactionStatus(reference, apiKey: "sk_live_tenant_key");
Response Models
ApiResults<T>
All methods return ApiResults<T>. Check Data for the typed payload.
PaystackResponseData (InitializeTransaction)
public class PaystackResponseData
{
public bool Status { get; set; }
public string? Message { get; set; }
public PaystackAuthorizationData? Data { get; set; }
}
public class PaystackAuthorizationData
{
public string? AuthorizationUrl { get; set; } // redirect the user here
public string? AccessCode { get; set; }
public string? Reference { get; set; }
}
PaystackTransactionResponse (CheckTransactionStatus)
public class PaystackTransactionResponse
{
public bool Status { get; set; }
public string? Message { get; set; }
public PaystackTransaction? Data { get; set; }
}
PaystackTransaction key fields:
| Property | Type | Description |
|---|---|---|
Id |
long |
Internal Paystack transaction ID |
Status |
string |
"success", "failed", etc. |
Reference |
string |
Your transaction reference |
Amount |
decimal |
Amount charged (in kobo) |
RequestedAmount |
decimal |
Original requested amount |
Channel |
string |
Payment channel (card, bank, etc.) |
Currency |
string |
Currency code (e.g. "NGN") |
GatewayResponse |
string |
Human-readable gateway message |
PaidAt |
DateTime |
When payment was completed |
CreatedAt |
DateTime |
When the transaction was created |
Fees |
int |
Paystack fees charged |
Customer |
Customer |
Customer details |
Authorization |
Authorization |
Card/payment method details |
Metadata |
Metadata |
Custom metadata attached to the tx |
License
MIT © Samuel Biliksuun
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- FlurlHttpClient (>= 1.1.0)
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version 1.1.0 - fixed JSON property mapping for snake_case fields, updated README