netpay-lib
TypeScript icon, indicating that this package has built-in type declarations

0.0.31 • Public • Published

Netpay Library

The netpay library is a helpful library for launching netpay on websites and webapps

Getting started

First import the script to your project

<!-- For use from a cdn -->
<script src="https://unpkg.com/netpay-lib@latest/umd/netpay.min.js"></script>

or in a javascript project, first install the netpay library in your project

yarn add netpay-lib
// or
npm install netpay-lib

then include the library in your project

// in an ES6 environment
import Netpay from 'netpay-lib';
 
// or in a CommonJs environment
const Netpay = require('netpay-lib');

Using Netpay

To use netpay, you simply call the createPayment method on the netpay library passing in the payment options object. This returns an instance of a payment. To open the netpay window, call the open method on the payment object

// Create the payment instance
 
const payment = Netpay.createPayment({
  amount: 400000,
  
  reference: 'SFSE552VB',
  
  email: 'email@email.com',
  
  merchantKey: 'Your-Merchant-Key',
  
  callback: function(response){
   alert(`The payment with reference ${response.reference} was successful`);
  },
  
  onClose: function() {
    alert(`The payment attempt failed`);
  }
  // You can find the rest of the payment options in the definition file below
});
payment.open();

The PaymentOptions object looks like this

  interface PaymentOptions {
    /**
     * The amount in lower denominations. e.g if you want to send `₦1,560` the amount to send is `156000`
     */
    amount: number,
 
    /**
     * A unique string to identify the transaction.
     */
    reference: string,
 
    /**
     * The email of the client. This serves as a user id for your customer
     */
    email: string,
 
    /**
     * The merchant key. This can be obtained from the netpay dashboard
     */
    merchantKey: string,
 
    /**
     * The currency with which the client would be charged
     * 
     * @default 'NGN'
     */
    currencyCode?: string,
 
    /**
     * The ID of the DOM Element or the actual DOM Element with which the 
     * payment gateway would be mounted. Note that the style of the 
     * specified element would be modified  while the payment gateway
     * is active. The original styles would be reverted once the gateway
     * is closed
     */
    container?: string | HTMLElement,
 
    /**
     * A callback function that is called when a payment is successful
     */
    callback?: () => void,
 
    /**
     * A callback function that is called when a payment is cancelled
     */
    onClose?: () => void,
 
    meta?: object,
 
    /**
     * When a color string is provided, it will override the color of the payment gateway
     * It can be any valid css color e.g `blue`, `#45eeff`, `rgba(235,23,123)`
     */
    color?: string,
 
    /**
     * Sets the mode of payment
     *
     * - **live**: transactions done in this mode would be would actuated in the real world
     * - **test**: Transactions done in this mode would make api calls, but moneys are never moved
     * - **demo**: Transactions done in this mode are all mocked. No api calls just simulations
     */
    mode?: Netpay.PaymentModes,
 
    /**
     * When in Demo mode, You can specify custom info for the demo
     */
    demoOptions?: Netpay.DemoOptions
  }

Readme

Keywords

none

Package Sidebar

Install

npm i netpay-lib

Weekly Downloads

1

Version

0.0.31

License

MIT

Unpacked Size

14.3 kB

Total Files

6

Last publish

Collaborators

  • nonsocode