Nodejs API wrapper for Paystack.
npm install paystack
// Require the library
var paystack = require('paystack')('secret_key');The resource methods accepts are promisified, but can receive optional callback as the last argument.
// First Option (with callback)
// paystack.{resource}.{method}(callback)
paystack.customer.list(function(error, body) {
console.log(error);
console.log(body);
});// Second Option (as promise)
// paystack.{resource}.{method}.then().catch()
paystack.customer.list()
.then(function(body) {
console.log(body);
})
.catch(function(error) {
console.log(error);
});For GET endpoints with url path parameters (e.g. https://api.paystack.co/plan/{id_or_plan_code}), pass path parameter as string or number Separate path parameter values by comma if more than 1 path parameter and place them in order as they appear in the url path.
paystack.plan.get(90)
.then(function(error, body) {
console.log(error);
console.log(body);
});For GET endpoints with query string parameters (e.g. https://api.paystack.co/bank/resolve?account_number=0022728151&bank_code=063), pass paramaters as object.
paystack.bank.resolve_account_number({account_number: '0022778151', bank_code: '063'})
.then(function(error, body) {
console.log(error);
console.log(body);
});For POST or PUT endpoints, the JSON body should be passed as the first argument.
paystack.plan.create({
name: 'API demo',
amount: 10000,
interval: 'monthly'
})
.then(function(error, body) {
console.log(error);
console.log(body);
});For POST or PUT endpoints, if the endpoint also has path parameters (e.g. https://api.paystack.co/customer/{id_or_customer_code}), pass the path parameters as explained above, before passing the JSON body object.
var customer_id = 100;
paystack.customer.update(customer_id, {last_name: 'Kehers'})
.then(function(error, body) {
console.log(error);
console.log(body);
});- customer
- create
- get
- list
- update
- transaction
- initialize
- charge
- get
- list
- totals
- verify
- plan
- create
- get
- list
- update
- page
- create
- get
- list
- update
- subscription
- create
- disable
- enable
- get
- list
- subaccount
- create
- get
- list
- listBanks
- update
- bank
- list
- resolveAccountNumber
- resolveBin
- Miscellanous
- list_banks
- resolve_bin
To use any endpoint, call
//using callback function
paystack.{resource}.{method}(function(err, body){
console.log(error);
console.log(body);
});
//or as promise
paystack.{resource}.{method}
.then(function(body) {
console.log(body);
})
.catch(function(error) {
console.log(error);
});- To ensure consistent code style, please follow the editorconfig rules in .editorconfig
To run tests, add your Paystack test secret key to package.json. (The test line should look something like this: env KEY=sk_test_1a68ac96a0171fb72111a24295d8d31d41c28eed ./node_modules/.bin/mocha...). Now run:
npm test
If you are contributing to the repo, kindly update the necessary test file in /test or add a new one and ensure all tests are passed before sending a PR.
- Proper resource examples
- ES6 support