1.0.2 • Published 4 months ago

bkash-webhook-validator v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months ago

Contributors Forks Stargazers Issues MIT License LinkedIn

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

Built With

  • Javascript
  • NodeJs

Installation

Install NPM packages

npm install bkash-webhook-validator

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

Roadmap

  • Add typescript support
  • Add unit tests

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

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

License

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

Contact

Sabbir Ahmed Siddiquee - sabbirprince39@gmail.com

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

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago