Yet a new Paystack API wrapper 😉
For Yarn
yarn add paystack-api
For NPM
npm install paystack-api --save
// Require the library
var paystack = require("paystack-api")("secret_key");
The resource methods promisified
Format → paystack.{resource}.{method}
// paystack.{resource}.{method}
paystack.customer
.list()
.then(function(body) {
console.log(body);
})
.catch(function(error) {
console.log(error);
});
All Resource methods parameters are provided as the only argument
paystack.plan
.create({
name: "API demo",
amount: 10000,
interval: "monthly"
})
.then(function(error, body) {
console.log(error);
console.log(body);
});
paystack.transactions.list({ perPage: 20 }).then(function(error, body) {
console.log(error);
console.log(body);
});
A function to add Paystack's fee to your charging fee
const helper = new paystack.FeeHelper();
console.log(helper.addFeesTo(5000));
Outputs → 5077
which includes Paystack's fee upfront
OR set your desired parameters
const helper = new paystack.FeeHelper({
percentage: ...,
cap: ...,
threshold: ...,
additionalCharge: ....
});
console.log(helper.addFeesTo(5000));
A Paystack Events helper (Express Middleware)
const paystack = require("paystack-api")("secret_key");
const events = paystack.Events;
events.on("event_name", data => {
// Act
console.log("hola!");
});
// Hooks with Express
app.post("/my/webhook/url", events.middleware);
const PaystackAPI = require("paystack-api")
class Paystack extends PaystackApi {
constructor(key) {
super(key);
// Update BVN match method with the new route
this.verification.matchBVN = this.extend({
method: 'post',
route: `/bvn/match`,
args: ['account_number*', 'bank_code*', 'bvn*'],
});
}
}
const paystack = new Paystack("secret_key");
express
middleware