1.0.0 • Published 1 year ago

billplz-rest v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

billplz-rest

billplz-rest provides a minimal higher-level wrapper around BillPlz's API.. Currently only support stable version API v3 with Typescript.

Installation

billplz-rest is available from npm.

npm i billplz-rest

Setup

  1. Register for Billplz account at Billplz
  2. Fetch your BillPlz Secret - String and Billplz XSignature - String
  3. Prepare your callback URL and redirect callback endpoint for redirect and webhook. You can use Webhook to test webhook.
  4. Import and initialize billplz module using these information.

Usage

// Get Collection By Collection ID

import Billpz from 'billplz-rest'

const GetCollectionById = async () => {

    const billplz = new Billpz({
        isProduction: false,
        secretKey: 'secret-key-from-billplz-account',
        signature: 'signature-from-billplz-account',
        redirectUrl: 'https://mywebsite.com/payment-page',
        callbackUrl: ' 	https://webhook.site/8b4c6eb5-5977-4ba1-beea-abcd12345',
    });

    const res = await billplz
        .collection()
        .getById('abcd123')

    if (res?.fetchSucess) {
        console.info(res);
    }
}

GetCollectionById();
// Verify webhook

import Billpz from 'billplz-rest'
import { BplzCallback } from './node_modules/billplz-rest/dist/lib/type'

const VerifyCallback = async (payload: BplzCallback) => {

    const billplz = new Billpz({
        isProduction: false,
        secretKey: 'secret-key-from-billplz-account',
        signature: 'signature-from-billplz-account',
        redirectUrl: 'https://mywebsite.com/payment-page',
        callbackUrl: ' 	https://webhook.site/8b4c6eb5-5977-4ba1-beea-abcd12345',
    });

    const res = await billplz
        .callback()
        .verify(payload)

    if (res) {
        console.info(res);
    }
}

VerifyCallback({
    // billplz webhook payload
});
1.0.0

1 year ago