bkash-webhook-validator
v1.0.2
Published
Bkash webhook signature validation package
Downloads
13
Maintainers
Readme
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
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 returnfalse
. 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!
- 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
License
Distributed under the MIT License. See LICENSE.txt
for more information.
Contact
Sabbir Ahmed Siddiquee - [email protected]
Project Link: https://github.com/prince3339/bkash-webhook-validator