Before you start
You will set up three small pieces. Only one of them ever sees your bKash credentials.
| Piece | Where it runs | What it does |
|---|---|---|
| Checkout | GitHub Pages (your fork) | blogger.js, the popup and config.js. Public files, no secrets. |
| Worker | Cloudflare Workers | Holds your bKash credentials and calls the bKash API. |
| Button | Your Blogger post, page, gadget or theme | Two lines of HTML that open the checkout. |
No credentials yet? Do steps 1 and 5 now. Until the Worker is connected, the checkout runs in demo mode: the whole flow works, but no money moves. You can finish your post while you wait for bKash.
1. Fork and publish the checkout
- Fork the repositoryOpen amirulsizan/bkash-blogger-payment and press Fork. Keep the name
bkash-blogger-payment. - Turn on GitHub PagesIn your fork go to Settings → Pages. Under Build and deployment choose Deploy from a branch, branch
main, folder/ (root), then Save. - Check it worksAfter a minute, open the checkout with a test amount. You should see the pink checkout with a Demo badge.
https://YOUR-GITHUB-NAME.github.io/bkash-blogger-payment/popup.html?amount=10
2. Get your bKash credentials
You need a bKash merchant account with Payment Gateway (Tokenized Checkout) access. bKash issues two sets of the same four values: sandbox for testing and live once your account is approved.
usernameandpasswordapp_keyandapp_secret
Request them through the bKash developer portal or your bKash account manager. Sandbox access also comes with test wallet numbers and their OTP and PIN.
Never paste these into Blogger, config.js or any file in your fork. Everything on GitHub Pages and Blogger is public. Anyone with your app secret and password can act as your merchant account. They belong only in the Worker's secrets.
3. Deploy the Worker
The Worker is one file, worker/src/index.js. Cloudflare's free plan (100,000 requests a day) is far more than a blog needs. Pick either option.
Option A: Cloudflare dashboard (no terminal)
- Create the WorkerSign in at dash.cloudflare.com, open Workers & Pages → Create → Create Worker, name it
bkash-bloggerand press Deploy. - Paste the codePress Edit code, replace everything with the contents of
worker/src/index.jsand press Deploy. - Add secrets and settingsGo to Settings → Variables and Secrets and add these. Use type Secret for the four bKash values.
Name Type Value BKASH_USERNAMESecret From bKash BKASH_PASSWORDSecret From bKash BKASH_APP_KEYSecret From bKash BKASH_APP_SECRETSecret From bKash POPUP_URLText https://YOUR-GITHUB-NAME.github.io/bkash-blogger-payment/popup.htmlBKASH_MODEText sandbox(laterlive) - Check itOpen your Worker's URL, for example
https://bkash-blogger.YOUR-NAME.workers.dev. You should see"configured": true. If not,missinglists what's left.
Option B: Wrangler CLI
Edit POPUP_URL in worker/wrangler.toml, then:
cd worker
npx wrangler login
npx wrangler secret put BKASH_USERNAME
npx wrangler secret put BKASH_PASSWORD
npx wrangler secret put BKASH_APP_KEY
npx wrangler secret put BKASH_APP_SECRET
npx wrangler deploy
Optional settings such as PRICES (server-enforced prices) and ALLOWED_ORIGINS are described in the reference.
4. Connect the checkout to your Worker
In your fork on GitHub, open config.js, press the pencil icon and set your Worker URL and shop name:
window.BKASH_CONFIG = {
apiBase: 'https://bkash-blogger.YOUR-NAME.workers.dev',
merchantName: 'Your Shop Name',
};
Commit the change. After GitHub Pages redeploys (about a minute), the checkout loses its Demo badge and sends customers to bKash.
5. Add the button to Blogger
Build your snippet with the snippet builder, or start from this:
<script src="https://YOUR-GITHUB-NAME.github.io/bkash-blogger-payment/blogger.js"></script>
<button data-bkash-amount="500" data-bkash-product="Premium eBook">Pay with bKash</button>
In a post or page
- Open HTML viewIn the post editor, click the pencil icon at the top left and choose HTML view.
- Paste and publishPaste the snippet where the button should appear and publish. Stay in HTML view until you publish, because switching back to Compose view can reformat custom HTML.
In a sidebar gadget
Layout → Add a Gadget → HTML/JavaScript, paste the snippet and save. This works well for a “Support this blog” donation button.
Once for the whole blog (theme)
Load the script once in Theme → Edit HTML, just before </body>. After that, posts only need the <button> line.
<script src='https://YOUR-GITHUB-NAME.github.io/bkash-blogger-payment/blogger.js' defer='defer'></script>
Blogger themes are XML. Write defer='defer' rather than a bare defer, and always close the tag with </script>, or the theme editor refuses to save.
6. Test in the sandbox
- Open your published postClick the button. The checkout popup opens with your shop name and the price.
- Pay with a test walletPress Pay. On bKash's sandbox page, use a sandbox wallet number with the OTP and PIN bKash gave you.
- See the resultThe popup shows the transaction ID, and your post shows “Payment successful”.
- Double-check on the serverAsk the Worker for the authoritative status:
curl "https://bkash-blogger.YOUR-NAME.workers.dev/verify?paymentID=TR0011..."
Something off? Cloudflare's Workers → bkash-blogger → Logs shows every request, and the troubleshooting table covers the usual suspects.
7. Go live
- Replace the four secrets with your live credentials and set
BKASH_MODEtolive. - Set
PRICESon the Worker so nobody can pay ৳1 for a ৳500 product by editing your page. - Make a small real payment and confirm it appears in your bKash merchant portal.
- Before delivering anything valuable, confirm the transaction ID in the merchant portal or with
/verify. Events on your blog are for a smooth experience, not proof of payment.
bKash may ask which website and callback domain you use during merchant approval. Your callback is your Worker's domain (for example bkash-blogger.YOUR-NAME.workers.dev). You can put the Worker on a custom domain if bKash prefers one.
Troubleshooting
| What you see | What to check |
|---|---|
| The button does nothing and looks unstyled | Open the blogger.js URL from your snippet in a new tab. It must load. Check that you pasted in HTML view. |
| The checkout still shows Demo | apiBase in config.js is empty, or GitHub Pages hasn't redeployed yet. Wait a minute and hard-refresh. |
| “Could not reach the payment server” | apiBase is wrong, the Worker isn't deployed, or your GitHub Pages origin isn't in ALLOWED_ORIGINS. |
| “The payment server is missing: …” | Add the listed secrets in the Worker's Variables and Secrets. |
| bKash says “Invalid App Key” or similar | Credentials are wrong, or you mixed sandbox credentials with BKASH_MODE=live (or the reverse). |
| “The price of … is … BDT” | The button's amount doesn't match PRICES on the Worker. Update one of them. |
| The popup is blocked | Nothing to do: checkout continues in the same tab and returns to the post afterwards. |
| Paid, but the post didn't update | The customer closed the popup before the result page loaded. Check the transaction in your merchant portal or with /verify. |
Still stuck? Open an issue with what you tried and what the browser console says.