Skip to content

This project demonstrates how to integrate the bKash Tokenized Checkout API using Java Spring Boot with static sandbox credentials and payloads

Notifications You must be signed in to change notification settings

iamkhs/bkash-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧾 bKash Payment Gateway Integration – Java Spring Boot

This project demonstrates how to integrate the bKash Tokenized Checkout API using Java Spring Boot, with static sandbox credentials and payloads.


πŸ“¦ Features

  • βœ… Get access token using app credentials
  • βœ… Create a payment session and get bkashURL for redirect
  • βœ… Handle callback after customer completes payment
  • βœ… Execute the payment to confirm success
  • βœ… Capture and log final transaction info (trxID, amount, etc.)

πŸš€ API Endpoints and Flow

This section explains the available endpoints in the Spring Boot application and how the bKash payment integration works step by step.


1. 🧾 GET /pay – Initiate Payment

  • Purpose: Starts the payment process.
  • How it works:
    • The backend first generates an access token by calling bKash’s /token/grant API.
    • Then it creates a payment session using bKash’s /checkout/create endpoint.
    • The response contains a bkashURL which is returned to the frontend.
    • The frontend should redirect the user to this URL so they can complete the payment in the bKash interface.

πŸ” Example flow:

GET /pay
β†’ Returns bkashURL (example):
  https://sandbox.payment.bkash.com/?paymentId=TR001...&hash=...

2. πŸ” /callback – Handle bKash Payment Redirect

Method: GET
Endpoint: /callback
Purpose: Handles the response from bKash after the customer completes (or cancels) the payment.


πŸ“₯ Query Parameters Received from bKash:

Parameter Type Description
paymentID String The unique ID for this payment
status String Payment status: success, failure, or cancel
signature String Optional bKash-provided signature

βœ… On Success Flow:

If status=success, the flow is:

  1. Extract paymentID from query params.
  2. Call getToken() again to fetch a valid token.
  3. Call executePayment(paymentID, token) to finalize the transaction.
  4. You may store the response (which contains trxID, amount, etc.) in your database.
  5. Return the result to the frontend/user.

Success JSON Example:

{
  "paymentID": "TR0011Pplo8lS1752517035835",
  "trxID": "CGF20N477Q",
  "transactionStatus": "Completed",
  "amount": "100",
  "currency": "BDT",
  "intent": "sale",
  "paymentExecuteTime": "2025-07-15T00:17:41:194 GMT+0600",
  "merchantInvoiceNumber": "Inv123456",
  "payerReference": "017XXXXXXXX",
  "customerMsisdn": "01929918378",
  "statusCode": "0000",
  "statusMessage": "Successful"
}

About

This project demonstrates how to integrate the bKash Tokenized Checkout API using Java Spring Boot with static sandbox credentials and payloads

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages