npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@aizon/node-paystack

v1.3.3

Published

A Node.JS API wrapper for paystack

Downloads

75

Readme

@aizon/node-paystack 💫

npm version GitHub last commit (by committer) Workflow status Repo Views

This is a simple Paystack API wrapper for Node.js designed to be easy to use. Use this npm package in your Node.js backend servers to seamlessly integrate paystack payments. View all supported routes here

Features

  • Full support for all Paystack API routes as at 2023/06/23 🚀
  • VSCode intellisense support for all routes 🚀
  • Built with TypeScript for improved type safety 🚀

Getting started

Installation

To install, simply run the command npm i @aizon/node-paystack in your terminal

Usage


Quick tips

To use this package, you simply use any of the provided methods, e.g:

  • transaction.initialize(): Initialize a transaction
  • customer.list(): List customers
  • product.fetch(): Fetch a product

All methods in this library will always return a JSON response containing the following fields

  • status (boolean, always present)
  • message (string, always present)
  • data (object, only present on a SUCCESSFUL response)
  • httpStatus (objedt, only present on an UNSUCCESSFUL response

Initializing and verifying transactions

Let's take a quick example to see the package in action

  • Import the package:
//Firstly import the installed library into your project

//CommonJS
const paystack = require("@aizon/node-paystack")("<api-key>")
//or alternatively
const node_paystack = require("@aizon/node-paystack")
const paystack = node_paystack("<api-key">)

//EJS
import node_paystack from "@aizon/node-paystack";
const paystack = node_paystack("<api-key>");

//TS
import node_paystack from "@aizon/node-paystack";
  • (optional) Configure the package:

    Because this package uses axios under the hood, two(2) configuration options useful for debugging have been provided, which are:

    • showRaw (boolean)
    • hideHttpErrorStatus (boolean)

    Note: all config options are set to false by default

    You can use them like so:

const node_paystack = require("@aizon/node-paystack")("<api-key>", {showRaw: true})
// By default, the axios reponse is transformed to display just the data from the server.
// `showRaw` config option displays the raw, unaltered axios response


const node_paystack = require("@aizon/node-paystack")("<api-key>", {hideHttpErrorStatus: true})
// By default, when an error is received from the server, its HTTP status is displayed.
// `hideHttpErrorStatus` config option, hides this, and displays just the server's response
  • Make transaction:

    To complete transactions, you will first need to initialize a transaction, then verify the transaction using the referencereturned

    1. With async/await
async function makePayment() {

  // Initializing a transaction using the `transaction.initialize()` method and passing the transaction information
  let result = await paystack.transaction.initialize({
    email: "[email protected]",
    amount: 100000 // Amount should be in kobo if currency is NGN, pesewas, if currency is GHS, and cents, if currency is ZAR
  })

  // Getting the transaction reference from the JSON data
  let reference = result.data.reference

  // Verifying the transaction using the `transaction.verify()` method and passing the `reference`
  let verification = await paystack.transaction.verify(reference)

  // The transaction is successful if the `status` of `verification` is true
  let isSuccessful = verification.status
  if(isSuccessful){
    console.log("Yay, transaction successful")
  }
}
  1. Without async/await
paystack.transaction.initialize({
  email: "[email protected]",
  amount: 100000
}).then( result => {
    let reference = result.data.reference;
    paystack.transaction.verify(reference).then( result => {  
      if(status == true) {
        console.log("Transaction verified")
      }      
  })  
})
  • Full Code sample
const paystack = require("@aizon/node-paystack")("<api-key>")

async function makePayment() {
  let result = await paystack.transaction.initialize({
    email: "[email protected]",
    amount: 100000
  })
  let reference = result.data.reference;

  let verification = await paystack.transaction.verify(reference)

  let isSuccessful = verification.status;
  if(isSuccessful){
    console.log("Yay, transaction successful")
  }
}

makePayment();

Routes:

Below are all the paystack routes supported by this package hyperlinked to their section on the official Paystack API documentation: