PayStack.Net
0.7.2
See the version list below for details.
dotnet add package PayStack.Net --version 0.7.2
NuGet\Install-Package PayStack.Net -Version 0.7.2
<PackageReference Include="PayStack.Net" Version="0.7.2" />
paket add PayStack.Net --version 0.7.2
#r "nuget: PayStack.Net, 0.7.2"
// Install PayStack.Net as a Cake Addin #addin nuget:?package=PayStack.Net&version=0.7.2 // Install PayStack.Net as a Cake Tool #tool nuget:?package=PayStack.Net&version=0.7.2
PayStack API for .Net
This library makes it easy to consume the Payment API from .Net projects.
How to Install
From Nuget
Install-Package PayStack.Net
Usage
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;
...
Transactions API
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
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
Working with Metadata
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
...
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Newtonsoft.Json (>= 10.0.3)
NuGet packages (6)
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 |
GitHub repositories (1)
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.1 | 7,107 | 3/18/2024 |
1.1.0 | 43,532 | 10/3/2022 |
1.0.1 | 3,813 | 8/20/2022 |
0.7.7 | 19,833 | 9/12/2019 |
0.7.6 | 1,620 | 9/7/2019 |
0.7.4 | 2,869 | 4/2/2019 |
0.7.3 | 1,245 | 3/25/2019 |
0.7.2 | 1,544 | 12/6/2018 |
0.7.1 | 2,596 | 10/28/2017 |
0.7.0 | 1,646 | 10/1/2017 |
0.6.6 | 54,853 | 1/20/2017 |
0.6.5 | 1,648 | 12/28/2016 |
0.6.4 | 1,525 | 12/27/2016 |
-- 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.