![]() |
VOOZH | about |
dotnet add package Paystack.Net --version 1.1.3
NuGet\Install-Package Paystack.Net -Version 1.1.3
<PackageReference Include="Paystack.Net" Version="1.1.3" />
<PackageVersion Include="Paystack.Net" Version="1.1.3" />Directory.Packages.props
<PackageReference Include="Paystack.Net" />Project file
paket add Paystack.Net --version 1.1.3
#r "nuget: Paystack.Net, 1.1.3"
#:package Paystack.Net@1.1.3
#addin nuget:?package=Paystack.Net&version=1.1.3Install as a Cake Addin
#tool nuget:?package=Paystack.Net&version=1.1.3Install as a Cake Tool
This library makes it easy to consume the Payment API from .Net projects.
100% API coverage, simply!
With this update, all Paystack APIs are now available via the Type-less API, exposed directly on PayStackApi. This makes it possible to call new or existing endpoints previously not suppported via this library's Typed API.
See Usage > below for details.
From Nuget
Install-Package PayStack.Net
The most important type in this library is the PayStackApi class. This can be created as follows:
var testOrLiveSecret = ConfigurationManager.AppSettings["PayStackSecret"];
var api = new PayStackApi(testOrLiveSecret);
To enhance discovery, all types are exposed under the PayStack.Net namespace. So, remember to include:
...
using PayStack.Net;
...
As implemented from version 1.0.0 and later, this library exposes Paystack APIs in two major ways:
Please see usage examples (and instructions) below:
To consume the Transactions API, use methods from the ITransactionsApi interface (available via the Transactions property of PayStackApi, viz:
// Initializing a transaction
var response = api.Transactions.Initialize("user@somewhere.net", 5000000);
if (response.Status)
// use response.Data
else
// show response.Message
// Verifying a transaction
var verifyResponse = api.Transactions.Verify("transaction-reference"); // auto or supplied when initializing;
if (verifyResponse.Status)
/*
You can save the details from the json object returned above so that the authorization code
can be used for charging subsequent transactions
// var authCode = verifyResponse.Data.Authorization.AuthorizationCode
// Save 'authCode' for future charges!
*/
The ITransactionsApi is defined as follows:
public interface ITransactionsApi
{
TransactionInitializeResponse Initialize(string email, int amount);
TransactionInitializeResponse Initialize(TransactionInitializeRequest request);
TransactionVerifyResponse Verify(string reference);
TransactionListResponse List(TransactionListRequest request = null);
TransactionFetchResponse Fetch(string transactionId);
TransactionTimelineResponse Timeline(string transactionIdOrReference);
TransactionTotalsResponse Totals(DateTime? from = null, DateTime? to = null);
TransactionExportResponse Export(DateTime? from = null, DateTime? to = null,
bool settled = false, string paymentPage = null);
}
Other APIs are implemented in like manner and exposed via the PayStackApi type as given below:
// Customer APIs
var request = new CustomerCreateRequest { ... };
var response = api.Customers.Create(request);
var listRequest = new CustomerListRequest { ... };
var listResponse = api.Customers.List(listRequest); // api.Customers is of type ICustomersApi
// Sub Accounts APIs
var saRequest = new SubAccountCreateRequest { ... };
var response = api.SubAccounts.Create(saRequest); // api.SubAccounts is of type ISubAccountsApi
// response.Status, response.Message, response.Data are available
// etc
The only exception to this is the API for resolving a card's identity given its Bank Identification Number (BIN), ResolveCardBin("..."), which is defined directly on the PayStackApi class, as follows:
ResolveCardBinResponse response = api.ResolveCardBin("123456");
// Use response as necessary
The Get, Post, and Put methods on PayStackApi allow for Type-less access to the entire PayStack API (100% coverage! Albeit without intellisense, by default).
For example, the InitializePayment endpoint can be called via the Type-less API, viz:
var _api = new PayStackApi(...);
var result = _api
.Post<ApiResponse<dynamic>, dynamic>(
"/transaction/initialize",
new {
amount = 5000000, // N50,000.00,
email = "someone@somewhere.net",
currency = "NGN",
reference = "",
}
);
if (result.Status) {
// use result.Data.authorization_url
// Note: result.Data properties appear as presented in API docs.
}
else {
// display result.Message
}
Intellisense can be enabled for the Type-less API by creating a custom Response class that matches the .data schema of the API being called.
For example, the following snippet will enable intellisense for the InitializePayment Type-less API:
// defined a .data schema compatible class
public class DtoInitializePayment {
public string authorization_url { get; set; }
public string reference { get; set; }
public string access_code { get; set; }
}
or with .Net naming convention
// define a result.data schema compatible class
public class DtoInitializePayment {
[JsonProperty("authorization_url")]
public string AuthorizationUrl { get; set; }
public string Reference { get; set; }
[JsonProperty("access_code")]
public string AccessCode { get; set; }
}
The DTO class can then be used when calling Type-less API, viz:
var _api = new PayStackApi(...);
var result = _api
.Post<ApiResponse<DtoInitializePayment>, dynamic>(
"/transaction/initialize",
new {
amount = 5000000, // N50,000.00,
email = "someone@somewhere.net",
currency = "NGN",
reference = "",
}
);
if (result.Status) {
// Use result as follows (with properties available via intellisense!):
// result.Data.authorization_url; or
// result.Data.AuthorizationUrl
// ...depending on the Dto class used.
}
else {
// display result.Message
}
Some PayStack API allow sending additional information about your request via an optional metadata property. PayStack.Net Request Types that support this feature (e.g. TransactionInitializeRequest, SubAccountCreateRequest, ChargeAuthorizationRequest, among others) inherit from the RequestMetadataExtender class. RequestMetadataExtender class has two properties, CustomFields (a List of CustomField) and MetadataObject (a string-keyed dictionary of object), and can be used thus:
// Prepare request object and set necessary payload on request
var request = new TransactionInitializeRequest { ... };
// Add a custom-field to metadata
request.CustomFields.Add(
CustomField.From("Field Name", "field_variable_name", "Field Value")
);
// Send request
var response = api.Transactions.Initialize(request);
// Use response as needed
...
Arbitary non custom-field metadata can be set, viz:
// Prepare request object and set necessary payload on request
var request = new SubAccountCreateRequest { ... };
// Add arbitary information to metadata
request.MetadataObject["Technical-Tip"] = "Microservices are awesome with Docker & Kubernetes!";
request.MetadataObject["ProductionUrl"] = "http://amazon.co.uk/product-url-slugified";
// Send request
var response = api.SubAccounts.Create(request);
// Use response as needed
...
~Response Types (since v0.7.2)!For situations where some properties (data.[property1][property2][...n]) are not directly exposed via the Typed Interface implemented by this library, all PayStack.Net ~Response types expose the .RawJson property that contains the raw JSON content returned from the PayStack Server, as a String.
As a String, this value can be parsed using any .Net compatible JSON parser, for use.
However, to make it easier to work this raw JSON (especially to remove the need for extra parsing before use), all ~Response types has an extension method, .AsJObject(), which returns a JObject instance. With this object, any property of the returned JSON can be retrieved as described on this page.
~Response Enhancement (since v1.1.3)To ease parsing the .RawJson property, all ~Response types expose the following generic extension methods: .As<T>() (alias .ToObject<T>()), .DataAs<T>, and (alias .DataToObject<T>()). These can be used as follows:
// Types
class Bank
{
public string name { get; set; }
// will match json 'code' property, not case sensitive.
public string coDe { get; set; }
[JsonProperty("slug")]
public string BankSlug { get; set; }
}
class CustomListBankResponse
{
public bool Status { get; set; }
public string message { get; set; } // Not case sensitive
public IList<Bank> data { get; set; }
}
// METHOD 1: With Typed Response
Console.WriteLine("Method 1:");
var response = _api.Miscellaneous.ListBanks();
foreach (var b in response.Data.Take(2)) // First two(2) banks
Console.WriteLine($"[{b.Code}] {b.Name} {b.Slug}");
Console.WriteLine("Status: {0}", response.Status); // should be "True"
Console.WriteLine();
// METHOD 2: With Custom Types or dynamic
// Example 1: Parse the response's data to a custom list of Banks
Console.WriteLine("Method 2.1: Response's data parsing");
var banks = response.DataAs<IList<Bank>>();
foreach (var b in banks.Take(2)) // First two(2) banks.
Console.WriteLine($"[{b.coDe}] {b.name} {b.BankSlug}");
Console.WriteLine();
// Example 2: Parse the full response to a custom type
Console.WriteLine("Method 2.2: Full response parsing via Custom Type.");
var customResponse = response.As<CustomListBankResponse>();
foreach (var b in customResponse.data.Take(2)) // First two(2) banks.
Console.WriteLine($"[{b.coDe}] {b.name} {b.BankSlug}");
Console.WriteLine("Status: {0}", customResponse.Status); // should be "True"
Console.WriteLine();
// Example 3: Parse the full response json to a dynamic
Console.WriteLine("Method 2.3: Full response parsing via dynamic");
var customResponseDynamic = response.As<dynamic>();
var firstTwoBanks = ((IEnumerable<dynamic>)customResponseDynamic.data).Take(2); // First two(2) banks.
foreach (var b in firstTwoBanks)
// For dynamic, properties (including nested) must be used as it appeared in the raw json
Console.WriteLine($"[{b.code}] {b.name} {b.slug}");
Console.WriteLine("Status: {0}", customResponseDynamic.status); // should be "True"
Console.WriteLine();
/* Output
~/src/test-console$ dotnet run
Method 1:
[120001] 9mobile 9Payment Service Bank 9mobile-9payment-service-bank-ng
[404] Abbey Mortgage Bank abbey-mortgage-bank-ng
Status: True
Method 2.1: Response's data parsing
[120001] 9mobile 9Payment Service Bank 9mobile-9payment-service-bank-ng
[404] Abbey Mortgage Bank abbey-mortgage-bank-ng
Method 2.2: Full response parsing via Custom Type.
[120001] 9mobile 9Payment Service Bank 9mobile-9payment-service-bank-ng
[404] Abbey Mortgage Bank abbey-mortgage-bank-ng
Status: True
Method 2.3: Full response parsing via dynamic
[120001] 9mobile 9Payment Service Bank 9mobile-9payment-service-bank-ng
[404] Abbey Mortgage Bank abbey-mortgage-bank-ng
Status: True
*/
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Paystack.Net:
| Package | Downloads |
|---|---|
|
Xown.Travels.Core
The core library for travel operations |
|
|
madeinOffice
Package Description |
|
|
Xown.Hotels.Core
The core library for hotel operations |
|
|
Generic.Payment.Integrations
A Library to centralize payment and fintech integrations in .NET. |
|
|
247Travels.Core
The Core Library for 247 Travels |
Showing the top 1 popular GitHub repositories that depend on Paystack.Net:
| Repository | Stars |
|---|---|
|
CodeMazeBlog/CodeMazeGuides
The main repository for all the Code Maze guides
|
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.3 | 11,904 | 7/10/2025 |
| 1.1.2 | 298 | 7/8/2025 |
| 1.1.1 | 103,991 | 3/18/2024 |
| 1.1.0 | 56,959 | 10/3/2022 |
| 1.0.1 | 4,183 | 8/20/2022 |
| 0.7.7 | 24,184 | 9/12/2019 |
| 0.7.6 | 2,007 | 9/7/2019 |
| 0.7.4 | 3,633 | 4/2/2019 |
| 0.7.3 | 1,576 | 3/25/2019 |
| 0.7.2 | 1,910 | 12/6/2018 |
| 0.7.1 | 3,242 | 10/28/2017 |
| 0.7.0 | 2,284 | 10/1/2017 |
| 0.6.6 | 62,295 | 1/20/2017 |
| 0.6.5 | 2,159 | 12/28/2016 |
| 0.6.4 | 2,020 | 12/27/2016 |
-- v1.1.3 --
* Feat: Flexible Custom Response types. (see "~Response Enhanacement" in README)
* Refactor: Use CSharpier (a dotnet cli tool) for code formatting.
-- v1.1.2 --
* Fix: HTTP GET RequestDTOs' serialization to query string. (Gracias @teghoz!)
* Fix: TransactionList.Meta's TotalVolume type change from Int32 to Int64. (Thanks @teghoz!)
-- v1.1.1 --
* Fix: Add `type` property to the ListBank API's response. (Thanks @@lexTutor!)
-- v1.1.0 --
* [Breaking] Update transaction ID from Int32 (int) to Int64 (long). (Thanks @teghoz!)
-- v1.0.1 --
* Fix: Clean-up URL for Type-less API calls.
-- v1.0.0 --
* Feat: 100% API coverage (via the Type-less API)
* Bug fix: Closes #21 (Thanks @thrizy, sorry it took so long!)
* Feat: Adds PartialDebit (Typed API).
-- v0.7.7 --
* Bug fix: Correct the BVN endpoint. #17
-- v0.7.6 --
* Bug fix: Ensure response.data exists before parsing metadata, especially when response.status is 'false'. #16
-- v0.7.5 --
* Bug fix: #15 Incorrect attempt to parse 'metadata' from JArray responses.
* Enable multi-currency for transaction initializer (Inspired by @django101, #14)
-- v0.7.4 --
* Bug fix. Adds ChargeApi missing request DTOs properties: Reference and DeviceId - (#12)
* Minor bug fixes.
-- v0.7.3 --
* Bug fix. Transaction's ChargeAuthorization method included (big thanks to Aghogho Bernard - @teghoz)
* Transaction's CheckAuthorization and RequestReauthorization methods now included.
* Expose more query params to the Transaction's Export method.
-- v0.7.2 --
* Bug fix. Charge.Data field Url
* All response types now implements IHasRawResponse interface. This introduces 'RawJson' property which contains the raw server's JSON response.
-- v0.7.1 --
* "Charge" API (Bank, Card, Authorization Code) now available [Complete].
-- v0.7.0 --
* .Net Core support (implements .Net Standard 2.0).
* "Miscellaneous" API now available [Complete].
* "Funds Transfer" API (Bulk, Control, Initiate, List, & Fetch) now available [Complete].
-- up to v0.6.6 --
Implements PayStack Standard Flow along with APIs for Transactions, Customers, SubAccounts, among others.