### Search Payment Transaction (HTTP Request Example) Source: https://developer.bka.sh/docs/search-transaction-2 This snippet illustrates the structure of an HTTP GET request to search for a payment transaction. It includes necessary headers like Host, Accept, authorization, and x-app-key. ```http GET checkout/payment/search/6H7XXXX1XS HTTP/1.1 Host: {base_URL} Accept: application/json authorization: id_token x-app-key: x-app-key ``` -------------------------------- ### Token Refresh Response Example - JSON Source: https://developer.bka.sh/docs/refresh-token-1 Demonstrates a JSON formatted response after successfully refreshing a token. The response includes the token type, the new id token, an expiration time, and the new refresh token. This example is indicative of a successful request and provides details of the new token values. ```json { "token_type": "Bearer", "id_token": "test_id_token_value" "expires_in": "3600", "refresh_token": "test_refresh_token_value" } ``` -------------------------------- ### Query Organizational Balance API Sample Request (cURL) Source: https://developer.bka.sh/docs/query-organizational-balance-1 This cURL command demonstrates how to make a GET request to the Query Organizational Balance API. It shows the initialization of the cURL session, setting HTTP headers, and executing the request. ```curl $url=curl_init('{base_URL}/checkout/payment/organizationBalance'); $header=array( 'Content-Type:application/json', 'authorization:'.$_SESSION['token'], 'x-app-key:shared_appKey'); curl_setopt($url,CURLOPT_HTTPHEADER, $header); curl_setopt($url,CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($url,CURLOPT_RETURNTRANSFER, true); curl_setopt($url,CURLOPT_FOLLOWLOCATION, 1); $resultdatax=curl_exec($url); curl_close($url); echo $resultdatax; ``` -------------------------------- ### Grant Token Request - cURL Example Source: https://developer.bka.sh/docs/grant-token-2 Demonstrates how to obtain a grant token using cURL. It shows setting up the request data, URL, headers, and executing the POST request to the bKash API. ```curl $request_data = array( 'app_key'=>'app_key_value', 'app_secret'=>'app_secret_value’ ); $url = curl_init('{base_URL}/checkout/token/grant'); $request_data_json=json_encode($request_data); $header = array( 'Content-Type:application/json', 'username:username_value, 'password:password_value' ); curl_setopt($url,CURLOPT_HTTPHEADER, $header); curl_setopt($url,CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($url,CURLOPT_RETURNTRANSFER, true); curl_setopt($url,CURLOPT_POSTFIELDS, $request_data_json); curl_setopt($url,CURLOPT_FOLLOWLOCATION, 1); curl_setopt($url, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); curl_exec($url); curl_close($url); ``` -------------------------------- ### Grant Token via cURL Request Source: https://developer.bka.sh/docs/grant-token-1 This example demonstrates how to make a POST request to the token grant endpoint using cURL. It includes setting headers, request method, and the JSON payload. The response is captured for further processing. ```php $request_data = array( 'app_key'=>'app_key_value', 'app_secret'=>'app_secret_value’ ); $url = curl_init('{base_URL}/tokenized/checkout/token/grant'); $request_data_json=json_encode($request_data); $header = array( 'Content-Type:application/json', 'username:username_value, 'password:password_value' ); curl_setopt($url,CURLOPT_HTTPHEADER, $header); curl_setopt($url,CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($url,CURLOPT_RETURNTRANSFER, true); curl_setopt($url,CURLOPT_POSTFIELDS, $request_data_json); curl_setopt($url,CURLOPT_FOLLOWLOCATION, 1); curl_setopt($url, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); curl_exec($url); curl_close($url); ``` -------------------------------- ### Token Refresh Request Example - JSON Source: https://developer.bka.sh/docs/refresh-token-1 Demonstrates a JSON formatted request to refresh a token. This request utilizes a POST method to the /tokenized/checkout/token/refresh endpoint, including headers for content type, and authentication. It provides the necessary credentials such as app key, app secret, and the refresh token. ```json { "app_key": "test_app_key", "app_secret": "test_app_secret", "refresh_token": "test_refresh_token" } ``` -------------------------------- ### POST /tokenized/checkout/execute Source: https://developer.bka.sh/docs/execute-agreement Finalizes the agreement creation process. After successful execution, customers can make payments using their wallet PIN. ```APIDOC ## POST /tokenized/checkout/execute ### Description This API finalizes an agreement creation request. Once an agreement is created, a customer can perform subsequent payments using only their wallet PIN. ### Method POST ### Endpoint `{base_URL}/tokenized/checkout/execute` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **paymentID** (String) - Mandatory - The PaymentID returned in the response of the Create Agreement API. This ID is valid for 24 hours and for a single execution only. ### Request Example ```json { "paymentID": "YOUR_PAYMENT_ID" } ``` ### Headers - **Accept**: "application/json" - **Authorization**: `id_token` value from Grant Token and Refresh Token API. - **X-App-Key**: Application Key provided by bKash during onboarding. ### Response #### Success Response (200) - **paymentID** (String) - bKash generated payment ID for this agreement creation request. - **agreementID** (String) - Agreement ID generated against the agreement creation request. - **customerMsisdn** (String) - MSISDN of the customer for whom the agreement was created. - **payerReference** (String) - The payer reference value provided during the Create Agreement API call. - **agreementExecuteTime** (String) - The time when the agreement was executed (Format: "yyyy-MM-dd'T'HH:mm:ss 'GMT'Z"). - **agreementStatus** (String) - Status of the agreement being created. - **statusCode** (String) - Unique code assigned to the API call status. - **statusMessage** (String) - Message associated with the status, explaining the status. #### Response Example ```json { "paymentID": "YOUR_PAYMENT_ID", "agreementID": "AGREEMENT_ID_GENERATED", "customerMsisdn": "CUSTOMER_MSISDN", "payerReference": "PAYER_REFERENCE_VALUE", "agreementExecuteTime": "2023-10-27T10:00:00 GMT+06:00", "agreementStatus": "SUCCESS", "statusCode": "200", "statusMessage": "Success" } ``` #### Error Response - **errorCode** (String) - Unique code assigned to the occurred error. - **errorMessage** (String) - Message associated with the error, explaining the error reason. #### Error Response Example ```json { "errorCode": "ERROR_CODE_HERE", "errorMessage": "Error message explaining the reason." } ``` ``` -------------------------------- ### PHP cURL Example for Executing Payment Source: https://developer.bka.sh/docs/execute-payment This PHP code snippet utilizes cURL to execute a payment transaction. It dynamically fetches the `paymentID` from GET parameters and constructs the request with appropriate headers and options. The script then executes the request, captures the result, and closes the cURL session. ```php $paymentID=$_GET['paymentID']; $url=curl_init('$baseURL/checkout/payment/execute/'.$paymentID); $header=array( 'Content-Type:application/json', 'authorization:'.$_SESSION['token'], 'x-app-key:shared_app_key'); curl_setopt($url,CURLOPT_HTTPHEADER, $header); curl_setopt($url,CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($url,CURLOPT_RETURNTRANSFER, true); curl_setopt($url,CURLOPT_FOLLOWLOCATION, 1); $resultdatax=curl_exec($url); curl_close($url); echo $resultdatax; ``` -------------------------------- ### Sample POST Request for Tokenized Checkout Source: https://developer.bka.sh/docs/execute-payment This snippet shows a sample HTTP POST request to execute a tokenized checkout payment. It includes essential headers like `Host`, `Accept`, `authorization`, and `x-app-key`. Ensure you replace `{base_URL}` with the actual base URL of the API. ```http POST /tokenized/checkout/execute/UO0CX661558594922927 HTTP/1.1 Host: {base_URL} Accept: application/json authorization: id_token x-app-key: x-app-key ``` -------------------------------- ### Intra Account Transfer API Request Example (cURL/PHP) Source: https://developer.bka.sh/docs/intra-account-transfer-1 This cURL implementation in PHP shows how to make an intra-account transfer request. It dynamically fetches the amount and transfer type from GET parameters and constructs the necessary headers and JSON body. It requires session token and app key to be set. ```php $amount=$_GET['amount']; $transferType = $_GET['transferType']; $requestBody=array( 'amount'=>$amount, 'currency'=>'BDT', 'transferType'=>$transferType ); $url=curl_init('$baseURL/checkout/payment/intraAccountTransfer'); $requestBodyjson=json_encode($requestBody); $header=array( 'Content-Type:application/json', 'authorization:'.$_SESSION['token'], 'x-app-key:'.$array["app_key"]); curl_setopt($url,CURLOPT_HTTPHEADER, $header); curl_setopt($url,CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($url,CURLOPT_RETURNTRANSFER, true); curl_setopt($url,CURLOPT_POSTFIELDS, $requestBodyjson); curl_setopt($url,CURLOPT_FOLLOWLOCATION, 1); curl_setopt($url, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); $resultdatax=curl_exec($url); curl_close($url); echo $resultdatax ``` -------------------------------- ### Get Payment Status (cURL) Source: https://developer.bka.sh/docs/query-payment-2 This cURL script demonstrates how to programmatically fetch the payment status using the provided payment ID. It sets up the necessary headers and makes a GET request to the payment query endpoint. ```PHP $paymentID=$_GET['paymentID']; $url=curl_init('$baseURL/checkout/payment/query/'.$paymentID); $header=array( 'Content-Type:application/json', 'authorization:'.$_SESSION['token'], 'x-app-key:shared_app_key'); curl_setopt($url,CURLOPT_HTTPHEADER, $header); curl_setopt($url,CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($url,CURLOPT_RETURNTRANSFER, true); curl_setopt($url,CURLOPT_FOLLOWLOCATION, 1); $resultdatax=curl_exec($url); curl_close($url); echo $resultdatax; ``` -------------------------------- ### POST /tokenized/checkout/create Source: https://developer.bka.sh/docs/create-payment-2 Initiates a payment creation request with bKash. This endpoint receives necessary payment information and, after validating customer wallet details, confirms the request, paving the way for an Execute Payment call. ```APIDOC ## POST /tokenized/checkout/create ### Description This API will receive a payment creation request with necessary information. Upon validation of customer's wallet information, the create payment request will be confirmed by the [Execute Payment](https://developer.bka.sh/docs/execute-payment-2) request. ### Method POST ### Endpoint `{base_URL}/tokenized/checkout/create` *Note: `base_URL` will be shared during onboarding.* ### Parameters #### Request Headers - **Content-Type** (string) - Required - `"application/json"` - **Accept** (string) - Required - `"application/json"` - **Authorization** (string) - Required - `id_token value found from the Grant Token and Refresh Token API.` - **X-App-Key** (string) - Required - `Application Key value shared by bKash during on-boarding.` ### Request Example ```json { "example": "Request body not provided in the input text, but would typically include payment details like amount, intent, currency, etc." } ``` ### Response #### Success Response (200) - **example** (object) - Description of the success response structure is not provided in the input text, but would typically include confirmation details and potentially a payment ID. #### Response Example ```json { "example": "Response body not provided in the input text." } ``` ``` -------------------------------- ### Grant Token Request - JavaScript Example Source: https://developer.bka.sh/docs/grant-token-2 Example of requesting a grant token using jQuery's AJAX method in JavaScript. It includes setting request headers, content type, and handling the success response to store the id_token. ```javascript var id_token = ''; $.ajax({ url: '{base_URL}/checkout/token/grant', type: 'POST', contentType: 'application/json', beforeSend: function(tokenRequest) { tokenRequest.setRequestHeader("username", "shared_name"); tokenRequest.setRequestHeader("password", "shared_password"); }, data: JSON.stringify( { "app_key": "shared_app_key", "app_secret": "shared_app_secret" } ), success: function(data) { if (data && data.id_token != null) { id_token = data.id_token; $('#bKash_button').removeAttr('disabled'); } } }); ``` -------------------------------- ### Create Agreement API Source: https://developer.bka.sh/docs/tokenized-checkout-process Initiates the agreement creation process with bKash. Requires a '0000' mode parameter and provides callback URLs for the user to enter wallet information. ```APIDOC ## POST /api/create-agreement ### Description Initiates the agreement creation process with bKash. This endpoint is called when a customer clicks an 'Add bKash Account' button. ### Method POST ### Endpoint /api/create-agreement ### Parameters #### Query Parameters - **mode** (string) - Required - Should be set to '0000' for agreement creation. #### Request Body - **successCallbackURL** (string) - Required - URL to redirect to on successful agreement creation. - **failureCallbackURL** (string) - Required - URL to redirect to on failed agreement creation. - **cancelledCallbackURL** (string) - Required - URL to redirect to on cancelled agreement creation. ### Request Example ```json { "successCallbackURL": "https://yourdomain.com/success", "failureCallbackURL": "https://yourdomain.com/failure", "cancelledCallbackURL": "https://yourdomain.com/cancelled" } ``` ### Response #### Success Response (200) - **bKashURL** (string) - The URL where the customer will enter their bKash wallet information. - **intent** (string) - The intent of the operation (e.g., 'create_account'). #### Response Example ```json { "bKashURL": "https://sandbox.bka.sh/payment/create?paymentID=...", "intent": "create_account" } ``` ``` -------------------------------- ### Execute Agreement API Source: https://developer.bka.sh/docs/tokenized-checkout-process Completes the agreement creation process after the customer has successfully entered their bKash wallet information and OTP. ```APIDOC ## POST /api/execute-agreement ### Description Completes the agreement creation process after the customer has successfully entered their bKash wallet information and OTP via the bKash URL. ### Method POST ### Endpoint /api/execute-agreement ### Parameters #### Request Body - **paymentID** (string) - Required - The unique identifier for the payment transaction, received from the Create Agreement API response. ### Request Example ```json { "paymentID": "YOUR_PAYMENT_ID" } ``` ### Response #### Success Response (200) - **status** (string) - The status of the agreement creation (e.g., 'success'). - **agreementID** (string) - The unique identifier for the created agreement. #### Response Example ```json { "status": "success", "agreementID": "AGREEMENT_12345" } ``` ``` -------------------------------- ### GET /checkout/payment/search/{trxID} Source: https://developer.bka.sh/docs/search-transaction-2 Retrieves the status of a payment transaction using its transaction ID. ```APIDOC ## GET /checkout/payment/search/{trxID} ### Description Retrieves the status of a payment transaction using its transaction ID. ### Method GET ### Endpoint `/checkout/payment/search/{trxID}` ### Parameters #### Path Parameters - **trxID** (String) - Required - The unique transaction ID of the payment. #### Query Parameters None #### Request Body None ### Request Example ```http GET checkout/payment/search/6H7XXXX1XS HTTP/1.1 Host: {base_URL} Accept: application/json authorization: id_token x-app-key: x-app-key ``` ### Request Example (cURL) ```curl $trxID=$_GET['trxID']; $url=curl_init('$baseURL/v1.2.0-beta/checkout/payment/search/'.$trxID); $header=array( 'Content-Type:application/json', 'authorization:'.$_SESSION['token'], 'x-app-key:'.$array["app_key"]); curl_setopt($url,CURLOPT_HTTPHEADER, $header); curl_setopt($url,CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($url,CURLOPT_RETURNTRANSFER, true); curl_setopt($url,CURLOPT_FOLLOWLOCATION, 1); $resultdatax=curl_exec($url); curl_close($url); echo $resultdatax; ``` ### Response #### Success Response (200) - **amount** (String) - Amount of the payment transaction. - **completedTime** (String) - The transaction completion time. Format is "yyyy-MM-dd'T'HH:mm:ss 'GMT'Z". - **currency** (String) - Currency of the mentioned amount. Currently only "BDT" value is supported. - **customerMsisdn** (String) - MSISDN i.e. mobile number of the customer. - **initiationTime** (String) - The transaction request initiation time. Format is "yyyy-MM-dd'T'HH:mm:ss 'GMT'Z". - **organizationShortCode** (String) - Short code assigned in bKash system for the merchant. - **transactionReference** (String) - Reference value sent by the customer during transaction from bKash App or USSD. - **transactionStatus** (String) - Final status of the transaction. For a successful payment, this status should be "Completed". - **transactionType** (String) - Type of the channel using which the transaction was initiated. - **trxID** (String) - The transaction ID created after the successful completion of this payment request. #### Response Example ```json { "amount": "100.00", "completedTime": "2023-10-27T10:30:00 GMT+0600", "currency": "BDT", "customerMsisdn": "017XXXXXXXX", "initiationTime": "2023-10-27T10:29:55 GMT+0600", "organizationShortCode": "ORGCODE", "transactionReference": "REF123", "transactionStatus": "Completed", "transactionType": "Checkout", "trxID": "6H7XXXX1XS" } ``` #### Error Response (4xx/5xx) - **errorCode** (String) - Unique code assigned to the occurred error. - **errorMessage** (String) - Message associated with the error, explaining the error reason. #### Error Response Example ```json { "errorCode": "SOME_ERROR_CODE", "errorMessage": "The requested transaction could not be found." } ``` ``` -------------------------------- ### Create Payment API Source: https://developer.bka.sh/docs/tokenized-checkout-process Initiates the payment process with bKash. Requires a '0001' mode parameter and provides callback URLs for the user to enter payment details. ```APIDOC ## POST /api/create-payment ### Description Initiates the payment process with bKash. This endpoint is called when a customer clicks a 'Payment with bKash' button. ### Method POST ### Endpoint /api/create-payment ### Parameters #### Query Parameters - **mode** (string) - Required - Should be set to '0001' for payment creation. #### Request Body - **amount** (string) - Required - The amount to be paid. - **currency** (string) - Required - The currency of the amount (e.g., 'BDT'). - **intent** (string) - Required - The intent of the payment (e.g., 'sale'). - **callbackURL** (string) - Required - URL to redirect to on successful payment. ### Request Example ```json { "amount": "100.00", "currency": "BDT", "intent": "sale", "callbackURL": "https://yourdomain.com/payment/callback" } ``` ### Response #### Success Response (200) - **bKashURL** (string) - The URL where the customer will enter their bKash wallet PIN. - **paymentID** (string) - The unique identifier for the payment transaction. #### Response Example ```json { "bKashURL": "https://sandbox.bka.sh/payment/create?paymentID=...", "paymentID": "PAYMENT_67890" } ``` ``` -------------------------------- ### Sample Success Response for Organization Balance Source: https://developer.bka.sh/docs/query-organizational-balance This snippet presents a sample successful HTTP response (200 OK) for a request to retrieve the organization's balance. It includes the Content-Type header and a JSON body detailing the organization's balance information, such as account type, status, and balances. ```json HTTP/1.1 200 OK Content-Type: application/json { "organizationBalance": [ { "accountTypeName": "Organization eMoney Account", "accountStatus": "Active", "accountHolderName": "50011 - testOST Merchant", "currency": "BDT", "currentBalance": "242677.22", "availableBalance": "242677.22", "updateTime": "2019-07-14T09:46:45:112 GMT+0000" }, { "accountTypeName": "Organization Disbursement eMoney Account", "accountStatus": "Active", "accountHolderName": "50011 - testOST Merchant", "currency": "BDT", "currentBalance": "6255.96", "availableBalance": "6255.96", "updateTime": "2019-07-14T09:46:45:112 GMT+0000" } ] } ``` -------------------------------- ### GET /tokenized/checkout/payment/status Source: https://developer.bka.sh/docs/query-payment-2 Retrieves the status of a payment transaction. Requires a payment ID to be provided. ```APIDOC ## GET /tokenized/checkout/payment/status ### Description Retrieves the status of a payment transaction using its unique payment ID. ### Method GET ### Endpoint /tokenized/checkout/payment/status ### Parameters #### Query Parameters - **paymentID** (string) - Required - The unique identifier for the payment transaction. ### Request Example ```curl $paymentID=$_GET['paymentID']; $url=curl_init('$baseURL/checkout/payment/query/'.$paymentID); $header=array( 'Content-Type:application/json', 'authorization:'.$_SESSION['token'], 'x-app-key:shared_app_key'); curl_setopt($url,CURLOPT_HTTPHEADER, $header); curl_setopt($url,CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($url,CURLOPT_RETURNTRANSFER, true); curl_setopt($url,CURLOPT_FOLLOWLOCATION, 1); $resultdatax=curl_exec($url); curl_close($url); echo $resultdatax; ``` ### Response #### Success Response (200) - **paymentId** (string) - The unique identifier for the payment. - **mode** (string) - The mode of the payment. - **paymentCreateTime** (string) - The timestamp when the payment was created. - **updateTime** (string) - The timestamp when the payment was last updated. - **trxID** (string) - The transaction ID. - **transactionStatus** (string) - The current status of the transaction. - **amount** (string) - The payment amount. - **currency** (string) - The currency of the payment. - **intent** (string) - The intent of the payment. - **merchantInvoice** (string) - The merchant's invoice number. - **verificationStatus** (string) - The verification status of the payment. - **payerReference** (string) - The reference provided by the payer. #### Response Example ```json { "paymentId": "UO0CX661558594922927", "mode": "0001", "paymentCreateTime": "2019-08-06T16:05:42:731 GMT+0600", "updateTime": "2019-05-23T07:03:03:089 GMT+0000", "trxID": "6ZN1019BV9", "transactionStatus": "Completed", "amount": "500", "currency": "BDT", "intent": "authorization", "merchantInvoice": "merchant101", "transactionStatus": "Initiated", "verificationStatus": "Incomplete", "payerReference": "01770618575" } ``` ``` -------------------------------- ### Get Refund Status API Source: https://developer.bka.sh/docs/refund-api-overview Retrieves the status of a previously initiated refund transaction. ```APIDOC ## POST /v1/payment/refund ### Description Retrieves the status of a refund by providing the payment ID and transaction ID. ### Method POST ### Endpoint /v1/payment/refund ### Parameters #### Request Body - **paymentID** (string) - Required - The unique identifier of the payment. - **trxID** (string) - Required - The unique transaction ID of the payment. - **intent** (string) - Required - Specifies the intent of the operation. Should be "checkStatus". ### Request Example ```json { "paymentID": "YOUR_PAYMENT_ID", "trxID": "YOUR_TRX_ID", "intent": "checkStatus" } ``` ### Response #### Success Response (200) - **statusCode** (string) - The status code of the refund process. - **statusMessage** (string) - The message describing the status of the refund process. - **refundStatus** (string) - The current status of the refund (e.g., "Pending", "Completed", "Failed"). #### Response Example ```json { "statusCode": "200", "statusMessage": "Status retrieved successfully", "refundStatus": "Completed" } ``` ``` -------------------------------- ### Sample Token Refresh Request (cURL) Source: https://developer.bka.sh/docs/refresh-token-3 This cURL command demonstrates how to send a token refresh request. It includes setting headers, the request method, and the JSON payload. ```php $refresh_token = $_GET['refresh_token']; $request_data = array( 'app_key'=>'shared_app_key', 'app_secret'=>'shared_app_secret', 'refresh_token'=>'refresh_token' ); $url = curl_init('{base_URL}/tokenized/checkout/token/refresh'); $request_data_json = json_encode($request_data); $header = array( 'Content-Type:application/json', 'username:shared_name, 'password:shared_password' ); ``` -------------------------------- ### GET /checkout/payment/organizationBalance Source: https://developer.bka.sh/docs/query-organizational-balance Fetches the organization's balance details, including current and available balances for various account types. ```APIDOC ## GET /checkout/payment/organizationBalance ### Description This endpoint retrieves the organization's balance information, detailing current and available balances for different account types. ### Method GET ### Endpoint /checkout/payment/organizationBalance ### Parameters #### Query Parameters None #### Headers - **Accept** (string) - Required - Specifies the expected response format, typically application/json. - **authorization** (string) - Required - The authentication token for accessing the API. - **x-app-key** (string) - Required - The application key for authentication. ### Request Example ```json GET /checkout/payment/organizationBalance HTTP/1.1 Host: {base_URL} Accept: application/json authorization: id_token x-app-key: x-app-key ``` ### Response #### Success Response (200) - **organizationBalance** (array) - An array of account balance objects. - **accountTypeName** (string) - The type of the account (e.g., "Organization eMoney Account"). - **accountStatus** (string) - The status of the account (e.g., "Active"). - **accountHolderName** (string) - The name of the account holder. - **currency** (string) - The currency of the balance (e.g., "BDT"). - **currentBalance** (string) - The current balance of the account. - **availableBalance** (string) - The available balance of the account. - **updateTime** (string) - The timestamp when the balance information was last updated. #### Response Example ```json { "organizationBalance": [ { "accountTypeName": "Organization eMoney Account", "accountStatus": "Active", "accountHolderName": "50011 - testOST Merchant", "currency": "BDT", "currentBalance": "242677.22", "availableBalance": "242677.22", "updateTime": "2019-07-14T09:46:45:112 GMT+0000" }, { "accountTypeName": "Organization Disbursement eMoney Account", "accountStatus": "Active", "accountHolderName": "50011 - testOST Merchant", "currency": "BDT", "currentBalance": "6255.96", "availableBalance": "6255.96", "updateTime": "2019-07-14T09:46:45:112 GMT+0000" } ] } ``` ### Error Response Parameters - **errorCode** (String) - Unique code assigned to the occurred error. - **errorMessage** (String) - Message associated with the error, explaining the error reason. ``` -------------------------------- ### Get Payment Status Request (HTTP) Source: https://developer.bka.sh/docs/query-payment-2 This is a sample HTTP POST request to retrieve the payment status for a tokenized checkout. It requires the base URL, authorization token, and application key in the headers. ```HTTP POST /tokenized/checkout/payment/status HTTP/1.1 Host: {base_URL} Accept: application/json authorization: id_token x-app-key: x-app-key ``` -------------------------------- ### Initiate B2B Payout Request Sample Source: https://developer.bka.sh/docs/b2b-payout-1 This sample demonstrates how to initiate a B2B payout request using the bKash API. It requires a Content-Type, Accept header, authorization token, and an application key. The request body includes the payout type and an optional reference. ```json POST /v1.2.0-beta/tokenized/payout/initiate HTTP/1.1 Host: {base_URL} Content-Type: application/json Accept: application/json authorization: id_token x-app-key: x-app-key { "type": "B2B", "reference": "reference length less or equal to 256" } ``` -------------------------------- ### Add bKash Payment Button Source: https://developer.bka.sh/docs/bkash-checkout-script This HTML snippet demonstrates how to add a 'Pay with bKash' button to your webpage. The button must have the specific ID 'bKash_button' for the bKash script to interact with it. ```html ``` -------------------------------- ### Payment Initiation Source: https://developer.bka.sh/docs/create-payment This endpoint allows you to initiate a payment transaction. It requires several mandatory parameters to define the payment details, including mode, payer reference, callback URL, amount, currency, intent, and merchant invoice number. Optional parameters like merchant association info can also be provided. ```APIDOC ## POST /payment ### Description Initiates a payment transaction with specified details. ### Method POST ### Endpoint /payment ### Parameters #### Request Body - **mode** (String) - Mandatory - Indicates the mode of payment. For Checkout (URL), the value should be "0011". - **payerReference** (String) - Mandatory - Any related reference value for the payment. Max length is 255 characters. Special characters "<", ">" and "&" are not allowed. - **callbackURL** (String) - Mandatory - The base URL of the merchant's platform for receiving transaction verification results. - **amount** (String) - Mandatory - The amount of the payment. - **currency** (String) - Mandatory - The currency of the payment. Currently, only "BDT" is acceptable. - **intent** (String) - Mandatory - The intent of the payment. For authorization & capture transactions, the value should be "authorization". - **merchantInvoiceNumber** (String) - Mandatory - Unique invoice number for the payment. Max length is 255 characters. Special characters "<", ">" and "&" are not allowed. - **merchantAssociationInfo** (String) - Optional - Required only for aggregators and system integrators. Data in TLV format (e.g., MI05MID54RF09123456789). Max length is 255 characters. Special characters "<", ">" and "&" are not allowed. ### Request Example ```json { "mode": "0011", "payerReference": "12345abc", "callbackURL": "https://merchant.com/callback", "amount": "100.00", "currency": "BDT", "intent": "authorization", "merchantInvoiceNumber": "INV-98765" } ``` ### Response #### Success Response (200) - **transactionId** (String) - The unique identifier for the transaction. - **paymentUrl** (String) - The URL to redirect the user for payment completion. #### Response Example ```json { "transactionId": "TXN123456789", "paymentUrl": "https://bkashtrx.com/pay?token=abcdef12345" } ``` ``` -------------------------------- ### Search Payment Transaction (cURL) Source: https://developer.bka.sh/docs/search-transaction-2 This snippet demonstrates how to search for a payment transaction using cURL in PHP. It requires a transaction ID and constructs a GET request to the bKash API. Dependencies include cURL extension and session management for authorization. ```php $trxID=$_GET['trxID']; $url=curl_init('$baseURL/v1.2.0-beta/checkout/payment/search/'.$trxID); $header=array( 'Content-Type:application/json', 'authorization:'.$_SESSION['token'], 'x-app-key:'.$array["app_key"]); curl_setopt($url,CURLOPT_HTTPHEADER, $header); curl_setopt($url,CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($url,CURLOPT_RETURNTRANSFER, true); curl_setopt($url,CURLOPT_FOLLOWLOCATION, 1); $resultdatax=curl_exec($url); curl_close($url); echo $resultdatax; ``` -------------------------------- ### POST /tokenized/checkout/create Source: https://developer.bka.sh/docs/create-payment-1 This API will receive a tokenized payment creation request with necessary information. Upon validation of customer's wallet information, the create payment request will be confirmed by the Execute Payment request. ```APIDOC ## POST /tokenized/checkout/create ### Description This API will receive a tokenized payment creation request with necessary information. Upon validation of customer's wallet information, the create payment request will be confirmed by the [Execute Payment](https://developer.bka.sh/docs/execute-payment-1) request. ### Method POST ### Endpoint {base_URL}/tokenized/checkout/create ### Parameters #### Request Body - **intent** (string) - Required - Payment intent. e.g., "sale" - **payerReference** (string) - Required - Merchant unique transaction ID. - **currency** (string) - Required - Currency code. e.g., "BDT" - **amount** (string) - Required - Payment amount. - **metadata** (string) - Optional - Any relevant information. ### Request Example ```json { "intent": "sale", "payerReference": "merchant_trx_12345", "currency": "BDT", "amount": "100.00", "metadata": "optional_data" } ``` ### Response #### Success Response (200) - **paymentID** (string) - Unique identifier for the payment. - **status** (string) - Current status of the payment. - **payerReference** (string) - Merchant unique transaction ID. #### Response Example ```json { "paymentID": "some_payment_id", "status": "PENDING", "payerReference": "merchant_trx_12345" } ``` ### Request Headers - **Content-Type**: "application/json" - **Accept**: "application/json" - **Authorization**: id_token value found from the Grant Token and Refresh Token API. - **X-App-Key**: Application Key value shared by bKash during on-boarding. ``` -------------------------------- ### Request Token Grant (cURL) Source: https://developer.bka.sh/docs/grant-token-3 Demonstrates how to make a POST request to the Token Grant API using cURL. It shows how to set headers, content type, and post data. ```php $request_data = array( 'app_key'=>'app_key_value', 'app_secret'=>'app_secret_value' ); $url = curl_init('{base_URL}/tokenized/checkout/token/grant'); $request_data_json=json_encode($request_data); $header = array( 'Content-Type:application/json', 'username:username_value, 'password:password_value' ); curl_setopt($url,CURLOPT_HTTPHEADER, $header); curl_setopt($url,CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($url,CURLOPT_RETURNTRANSFER, true); curl_setopt($url,CURLOPT_POSTFIELDS, $request_data_json); curl_setopt($url,CURLOPT_FOLLOWLOCATION, 1); curl_setopt($url, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); curl_exec($url); curl_close($url); ``` -------------------------------- ### Grant Token Response - JSON Example Source: https://developer.bka.sh/docs/grant-token-2 A sample successful response from the bKash Grant Token API. It includes the token type, the ID token for authorization, expiry duration, and the refresh token. ```json HTTP/1.1 200 OK Content-Type: application/json { "token_type": "Bearer", "id_token": "test_id_token_value" "expires_in": 3600, "refresh_token": "test_refresh_token_value" } ``` -------------------------------- ### Create Agreement Source: https://developer.bka.sh/docs/create-agreement This endpoint creates a payment agreement for a specific customer wallet. After successful creation, the customer can pay using only their wallet PIN. ```APIDOC ## POST /tokenized/checkout/create ### Description Creates a payment agreement for a customer's wallet, enabling subsequent payments via wallet PIN. ### Method POST ### Endpoint {base_URL}/tokenized/checkout/create ### Headers - **Content-Type**: "application/json" - **Accept**: "application/json" - **Authorization**: id_token value found from the Grant Token and Refresh Token API. - **X-App-Key**: Application Key value shared by bKash during on-boarding. ### Parameters #### Request Body - **mode** (String) - Mandatory - This parameter indicates the mode of this API. For agreement creation, the value of this parameter should be "0000". - **payerReference** (String) - Mandatory - Any related reference value which can be passed along with the payment request. If the wallet number is passed here, then it will be pre-populated in bKash's wallet number entry page. Max length is 255 characters. Special characters "<", ">" and "&" are not allowed. - **callbackURL** (String) - Mandatory - The base URL of merchant's platform based on which bKash will generate seperate callback URLs for success, failure and cancelled transactions. bKash will send transaction verification result in these URLs based on the the result. - **amount** (String) - Mandatory - Amount of the payment to be made. - **currency** (String) - Mandatory - Currency of the mentioned amount. Currently, only "BDT" value is acceptable. - **intent** (String) - Mandatory - Intent of the payment. For tokenized checkout the value should be "Sale". - **merchantInvoiceNumber** (String) - Optional - Unique invoice number used at merchant side for this specific payment. Max length is 255 characters. Special characters "<", ">" and "&" are not allowed. ### Request Example ```json { "mode": "0000", "payerReference": "01XXXXXX000", "callbackURL": "https://merchant.com/callback", "amount": "100", "currency": "BDT", "intent": "Sale", "merchantInvoiceNumber": "INV-12345" } ``` ### Response #### Success Response (200) - **agreementID** (String) - The unique identifier for the created agreement. - **customerMsisdn** (String) - The MSISDN of the customer. - **amount** (String) - The agreed upon amount. - **currency** (String) - The currency for the agreement. #### Response Example ```json { "agreementID": "AGREEMENT123456789", "customerMsisdn": "01XXXXXX000", "amount": "100", "currency": "BDT" } ``` ``` -------------------------------- ### Grant Token Request - JSON Example Source: https://developer.bka.sh/docs/grant-token-2 A sample JSON payload for requesting a grant token from the bKash API. This includes mandatory application key and secret. The request is sent via HTTP POST. ```json POST /checkout/token/grant HTTP/1.1 Host: {base_URL} Content-Type: application/json Accept: application/json username: username password: password { "app_key": "test_app_key", "app_secret": "test_app_secret" } ``` -------------------------------- ### Sample JSON Request for Intra-Account Transfer Source: https://developer.bka.sh/docs/intra-account-transfer This snippet shows a sample JSON payload for initiating an intra-account transfer. It includes the amount, currency, and transfer type as required parameters. ```json { 'amount': '10', 'currency':'BDT', 'transferType':'Collection2Disbursement' } ``` -------------------------------- ### Include jQuery and bKash Script Dependency Source: https://developer.bka.sh/docs/bkash-checkout-script This snippet shows how to include the jQuery library and the bKash checkout script in the HTML head. The BKASH_SCRIPT_URL will be provided during merchant onboarding. Ensure these are loaded before other bKash-related scripts. ```html
```