bkash-webhook-validator

1.0.2 • Public • Published

Contributors Forks Stargazers Issues MIT License LinkedIn


Bkash Webhook Validator

Bkash RPP subscription API webhook data signature validation package!
Explore the docs »

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Installation
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact

About The Project

It's a tiny package that under the hood uses other node packages to validate BKASH subscription API webhook signature validation.

Here's why:

  • Validating Bkash subscription API webhook data signature in nodejs is not as straightforward as in Python or other languages
  • This package helps to minimize the complexity of resolving Bkash signature validation for NodeJs Applications

(back to top)

Built With

  • Javascript
  • NodeJs

(back to top)

Installation

Install NPM packages

npm install bkash-webhook-validator

(back to top)

Usage

Validate signature with the validateSignature method

import { validateSignature } from 'bkash-webhook-validator';

const examplePayload = '{"message":null,"timeStamp":"2023-11-08T09:50:30.137987Z","subscriptionRequestId":"abc-request-123","subscriptionId":13757,"subscriptionStatus":"SUCCEEDED","nextPaymentDate":"2023-11-09","amount":5,"trxId":"AK840FVMME","payer":"01725010001","frequency":"DAILY","trxDate":"2023-11-08T09:50:29"}'

const isValid = validateSignature({
 payload: examplePayload,
 apiKey: 'YOUR-BKASH-API-KEY',
 signature: 'SIGNATURE-EXTRACTED-FROM-REQUEST' // req.header('X-Signature')
})

isValid will return boolean

[!IMPORTANT] Bkash sends a webhook payload where the number includes two trailing zeros, ex: 50.00. But Javascript by default ignores trailing zero from numbers. In such case, directly passing the string data to validateSignature method will return false. You can resolve the issue by updating the string in the following hacky way:

examplePayload.replace(`"amount":${amount}`, `"amount":${amount.toFixed(2)}`)

You need to update Webhook Bkash amount value with two trailing zeros before passing to the validationSignature method

(back to top)

Roadmap

  • [ ] Add typescript support
  • [ ] Add unit tests

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what makes the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Sabbir Ahmed Siddiquee - sabbirprince39@gmail.com

Project Link: https://github.com/prince3339/bkash-webhook-validator

(back to top)

Package Sidebar

Install

npm i bkash-webhook-validator

Weekly Downloads

1

Version

1.0.2

License

ISC

Unpacked Size

12.6 kB

Total Files

5

Last publish

Collaborators

  • prince3339