Bkash RPP subscription API webhook data signature validation package!
Explore the docs »
Report Bug
·
Request Feature
Table of Contents
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
Install NPM packages
npm install bkash-webhook-validator
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
- Add typescript support
- Add unit tests
See the open issues for a full list of proposed features (and known issues).
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!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.
Sabbir Ahmed Siddiquee - sabbirprince39@gmail.com
Project Link: https://github.com/prince3339/bkash-webhook-validator