### Refund API Ruby Request Example Source: https://developer.bka.sh/reference/refund Illustrates how to perform a refund operation using Ruby by sending a POST request to the BKA.sh API. This example typically utilizes the 'Net::HTTP' library or a gem like 'httparty' to handle the HTTP communication and request formatting. ```ruby require 'net/http' require 'uri' require 'json' def refund(payment_id, trx_id, amount, reason) uri = URI.parse('https://checkout.sandbox.bka.sh/v1.2.0-beta/checkout/payment/refund') http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Post.new(uri.request_uri) request['accept'] = 'application/json' request['content-type'] = 'application/json' request['Authorization'] = 'YOUR_AUTH_TOKEN' request['X-APP-Key'] = 'YOUR_APP_KEY' body = { paymentId: payment_id, trxID: trx_id, amount: amount, reason: reason }.to_json request.body = body response = http.request(request) if response.code == '200' puts 'Refund successful:' puts JSON.parse(response.body) return JSON.parse(response.body) else puts "Refund failed: #{response.code} - #{response.body}" raise "Refund failed: #{response.code}" end end # Example usage: # refund('some_payment_id', 'some_trx_id', '10.50', 'Customer request') ``` -------------------------------- ### Refund API Node.js Request Example Source: https://developer.bka.sh/reference/refund Provides an example of how to initiate a refund via the BKA.sh API using Node.js. This snippet typically involves using a library like 'axios' or the built-in 'https' module to construct and send the POST request with appropriate parameters and headers. ```javascript const axios = require('axios'); const refund = async (paymentId, trxID, amount, reason) => { const url = 'https://checkout.sandbox.bka.sh/v1.2.0-beta/checkout/payment/refund'; const headers = { 'accept': 'application/json', 'content-type': 'application/json', 'Authorization': 'YOUR_AUTH_TOKEN', 'X-APP-Key': 'YOUR_APP_KEY' }; const body = { paymentId: paymentId, trxID: trxID, amount: amount, reason: reason }; try { const response = await axios.post(url, body, { headers }); console.log('Refund successful:', response.data); return response.data; } catch (error) { console.error('Refund failed:', error.response ? error.response.data : error.message); throw error; } }; // Example usage: // refund('some_payment_id', 'some_trx_id', '10.50', 'Customer request'); ``` -------------------------------- ### Refund API PHP Request Example Source: https://developer.bka.sh/reference/refund Shows how to implement a refund function in PHP using cURL to interact with the BKA.sh API. This example details setting up the cURL request with the correct URL, headers, and JSON payload for the refund details. ```php $paymentId, 'trxID' => $trxID, 'amount' => $amount, 'reason' => $reason ]); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $body); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if (curl_errno($ch)) { echo 'Curl error: ' . curl_error($ch); curl_close($ch); throw new Exception('cURL Error: ' . curl_error($ch)); } curl_close($ch); if ($httpCode == 200) { echo 'Refund successful:\n'; echo $response; return json_decode($response, true); } else { echo "Refund failed: HTTP Code {$httpCode}\n"; echo $response; throw new Exception("Refund failed: HTTP Code {$httpCode}"); } } // Example usage: // try { // refund('some_payment_id', 'some_trx_id', '10.50', 'Customer request'); // } catch (Exception $e) { // // Handle error // } ?> ``` -------------------------------- ### Refund Payment Request (Node.js) Source: https://developer.bka.sh/reference/refund-1 This Node.js example shows how to perform a refund using the 'node-fetch' library. It constructs the request with the refund endpoint URL, specifies JSON content type, and includes placeholder for authorization headers and the request body containing refund details. Ensure you have 'node-fetch' installed. ```javascript // Ensure you have installed node-fetch: npm install node-fetch import fetch from 'node-fetch'; const url = "https://tokenized.sandbox.bka.sh/v1.2.0-beta/tokenized/checkout/payment/refund"; const options = { method: "POST", headers: { accept: "application/json", "content-type": "application/json", "Authorization": "YOUR_AUTHORIZATION_TOKEN", "X-APP-Key": "YOUR_APP_KEY" }, body: JSON.stringify({ amount: "10.00", paymentId: "string", trxID: "string", sku: "string", reason: "string" }) }; fetch(url, options) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error(error)); ``` -------------------------------- ### Refund Payment Request (Python) Source: https://developer.bka.sh/reference/refund-1 This Python example shows how to make a refund request using the 'requests' library. It defines the API endpoint, sets the necessary headers including authentication, and constructs the JSON payload with the refund details. Ensure you have the 'requests' library installed (`pip install requests`). ```python import requests import json url = "https://tokenized.sandbox.bka.sh/v1.2.0-beta/tokenized/checkout/payment/refund" headers = { "accept": "application/json", "content-type": "application/json", "Authorization": "YOUR_AUTHORIZATION_TOKEN", "X-APP-Key": "YOUR_APP_KEY" } payload = { "amount": "10.00", "paymentId": "string", "trxID": "string", "sku": "string", "reason": "string" } response = requests.post(url, headers=headers, data=json.dumps(payload)) print(f"Status Code: {response.status_code}") print(f"Response Body: {response.json()}") ``` -------------------------------- ### Ruby Request - Confirm Payment Source: https://developer.bka.sh/reference/authorized-and-capture-1 Example of how to confirm a payment using Ruby. This snippet demonstrates making a POST request with the required headers and body. ```ruby # Ruby example will be added here ``` -------------------------------- ### Capture Payment using PHP Source: https://developer.bka.sh/reference/authorized-and-capture A PHP example for capturing a payment using cURL. It details setting up the cURL request with the POST method, URL, and headers. ```php ``` -------------------------------- ### PHP Request - Confirm Payment Source: https://developer.bka.sh/reference/authorized-and-capture-1 Example of how to confirm a payment using PHP. This snippet demonstrates making a POST request with the required headers and body. ```php // PHP example will be added here ``` -------------------------------- ### Capture Payment using Node.js Source: https://developer.bka.sh/reference/authorized-and-capture Example of capturing a payment with Node.js, utilizing the 'axios' library for HTTP requests. It shows how to set up the request with the correct URL and headers. ```javascript const axios = require('axios'); const options = { method: 'POST', url: 'https://checkout.sandbox.bka.sh/v1.2.0-beta/checkout/payment/capture/{paymentID}', headers: { 'accept': 'application/json' } }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Create Checkout Token using Python Source: https://developer.bka.sh/reference/agreement Example of creating a checkout token using Python. This code demonstrates making a POST request to the BKA.sh API, specifying headers and request body. ```python # Python example is not provided in the text. ``` -------------------------------- ### Refund API Python Request Example Source: https://developer.bka.sh/reference/refund Demonstrates how to make a refund request using Python's 'requests' library. This code snippet shows how to construct the POST request with the correct URL, headers, and JSON payload for the refund details. ```python import requests import json def refund(payment_id, trx_id, amount, reason): url = 'https://checkout.sandbox.bka.sh/v1.2.0-beta/checkout/payment/refund' headers = { 'accept': 'application/json', 'content-type': 'application/json', 'Authorization': 'YOUR_AUTH_TOKEN', 'X-APP-Key': 'YOUR_APP_KEY' } payload = { 'paymentId': payment_id, 'trxID': trx_id, 'amount': amount, 'reason': reason } try: response = requests.post(url, headers=headers, json=payload) response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx) print('Refund successful:') print(response.json()) return response.json() except requests.exceptions.RequestException as e: print(f'Refund failed: {e}') if hasattr(e, 'response') and e.response is not None: print(f'Response body: {e.response.text}') raise # Example usage: # try: # refund('some_payment_id', 'some_trx_id', '10.50', 'Customer request') # except Exception as e: # # Handle error # pass ``` -------------------------------- ### Python Request - Confirm Payment Source: https://developer.bka.sh/reference/authorized-and-capture-1 Example of how to confirm a payment using Python. This snippet demonstrates making a POST request with the required headers and body. ```python # Python example will be added here ``` -------------------------------- ### Create Checkout Token using Ruby Source: https://developer.bka.sh/reference/agreement Example of creating a checkout token using Ruby. This code illustrates sending a POST request to the BKA.sh API with appropriate request details. ```ruby # Ruby example is not provided in the text. ``` -------------------------------- ### Create Checkout Token using PHP Source: https://developer.bka.sh/reference/agreement Example of creating a checkout token using PHP. This snippet shows how to initiate a POST request to the BKA.sh API, including setting headers and body. ```php // PHP example is not provided in the text. ``` -------------------------------- ### Create Checkout Token using Node.js Source: https://developer.bka.sh/reference/agreement Example of creating a checkout token using Node.js. This snippet demonstrates how to make a POST request to the BKA.sh API with the necessary headers and body parameters. ```javascript // Node.js example is not provided in the text. ``` -------------------------------- ### cURL Request - Confirm Payment Source: https://developer.bka.sh/reference/authorized-and-capture-1 Example of how to confirm a payment using a cURL request. This includes the POST method, URL, and necessary headers like 'accept' and 'content-type'. ```shell curl --request POST \ --url https://tokenized.sandbox.bka.sh/v1.2.0-beta/tokenized/checkout/payment/confirm/confirmationType \ --header 'accept: application/json' \ --header 'content-type: application/json' ``` -------------------------------- ### Node.js Request - Confirm Payment Source: https://developer.bka.sh/reference/authorized-and-capture-1 Example of how to confirm a payment using Node.js. This snippet demonstrates making a POST request with the required headers and body. ```javascript // Node.js example will be added here ``` -------------------------------- ### Refund API cURL Request Example Source: https://developer.bka.sh/reference/refund Demonstrates how to make a POST request to the Refund API endpoint using cURL. This includes setting the request URL, method, and essential headers like 'accept' and 'content-type'. ```Shell curl --request POST \ --url https://checkout.sandbox.bka.sh/v1.2.0-beta/checkout/payment/refund \ --header 'accept: application/json' \ --header 'content-type: application/json' ``` -------------------------------- ### Create Checkout Token using cURL Source: https://developer.bka.sh/reference/agreement Example of creating a checkout token using cURL. This request sends a POST request to the BKA.sh sandbox endpoint with specified headers and a JSON body. ```shell curl --request POST \ --url https://tokenized.sandbox.bka.sh/v1.2.0-beta/tokenized/checkout/create \ --header 'accept: application/json' \ --header 'content-type: application/json' ``` -------------------------------- ### Refund Payment Request (Ruby) Source: https://developer.bka.sh/reference/refund-1 This Ruby script illustrates how to send a refund request using the built-in Net::HTTP library. It configures the request with the refund endpoint, sets the necessary headers, and includes a JSON body with the required refund parameters. This example is useful for Ruby-based integrations. ```ruby require 'net/http' require 'uri' require 'json' uri = URI.parse("https://tokenized.sandbox.bka.sh/v1.2.0-beta/tokenized/checkout/payment/refund") https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true request = Net::HTTP::Post.new(uri.path) request["accept"] = "application/json" request["content-type"] = "application/json" request["Authorization"] = "YOUR_AUTHORIZATION_TOKEN" request["X-APP-Key"] = "YOUR_APP_KEY" request.body = { amount: "10.00", paymentId: "string", trxID: "string", sku: "string", reason: "string" }.to_json response = https.request(request) puts response.code puts response.body ``` -------------------------------- ### Refund Payment Request (cURL) Source: https://developer.bka.sh/reference/refund-1 This cURL command demonstrates how to make a POST request to the refund endpoint. It includes the necessary URL, headers (accept and content-type), and assumes the body parameters will be provided separately. This is a foundational example for initiating a refund. ```shell curl --request POST \ --url https://tokenized.sandbox.bka.sh/v1.2.0-beta/tokenized/checkout/payment/refund \ --header 'accept: application/json' \ --header 'content-type: application/json' ``` -------------------------------- ### Search Transaction Details - Python Request Source: https://developer.bka.sh/reference/supporting-operations-2 Example of how to search for transaction details using Python. This snippet demonstrates making a POST request to the specified API endpoint with required headers. ```python # Python example would go here ``` -------------------------------- ### Query Organization Balance using cURL Source: https://developer.bka.sh/reference/supporting-operations This snippet demonstrates how to make a GET request to the BKA.sh API to query the organization's balance using cURL. It includes the endpoint URL and the necessary 'accept' header. ```shell curl --request GET \ --url https://checkout.sandbox.bka.sh/v1.2.0-beta/checkout/payment/organizationBalance \ --header 'accept: application/json' ``` -------------------------------- ### Capture Payment using Ruby Source: https://developer.bka.sh/reference/authorized-and-capture This Ruby snippet illustrates how to capture a payment using the Net::HTTP library. It constructs the POST request with the appropriate endpoint and headers. ```ruby require 'uri' require 'net/http' url = URI("https://checkout.sandbox.bka.sh/v1.2.0-beta/checkout/payment/capture/{paymentID}") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["accept"] = "application/json" response = http.request(request) puts response.read_body ``` -------------------------------- ### POST Payment Status (cURL) Source: https://developer.bka.sh/reference/payment-1 Example of how to make a POST request to the Payment Status API using cURL. This includes setting the necessary headers for authentication and content type. ```shell curl --request POST \ --url https://tokenized.sandbox.bka.sh/v1.2.0-beta/tokenized/checkout/payment/status \ --header 'accept: application/json' \ --header 'content-type: application/json' ``` -------------------------------- ### POST Payment Status (Python) Source: https://developer.bka.sh/reference/payment-1 Example of how to make a POST request to the Payment Status API using Python. This shows how to use the 'requests' library to send the request with headers. ```python import requests url = "https://tokenized.sandbox.bka.sh/v1.2.0-beta/tokenized/checkout/payment/status" headers = { "accept": "application/json", "content-type": "application/json" } response = requests.post(url, headers=headers) print(response.text) ``` -------------------------------- ### Capture Payment using Python Source: https://developer.bka.sh/reference/authorized-and-capture This Python snippet shows how to capture a payment using the 'requests' library. It configures the POST request with the specified URL and headers. ```python import requests url = "https://checkout.sandbox.bka.sh/v1.2.0-beta/checkout/payment/capture/{paymentID}" headers = { 'accept': 'application/json' } response = requests.post(url, headers=headers) print(response.json()) ``` -------------------------------- ### POST Payment Status (Ruby) Source: https://developer.bka.sh/reference/payment-1 Example of how to make a POST request to the Payment Status API using Ruby. This uses the 'httparty' gem to send the request with specified headers. ```ruby require 'httparty' url = "https://tokenized.sandbox.bka.sh/v1.2.0-beta/tokenized/checkout/payment/status" headers = { "accept" => "application/json", "content-type" => "application/json" } response = HTTParty.post(url, headers: headers) puts response.body ``` -------------------------------- ### Search Transaction Details - PHP Request Source: https://developer.bka.sh/reference/supporting-operations-2 Example of how to search for transaction details using PHP. This snippet demonstrates making a POST request to the specified API endpoint with required headers. ```php // PHP example would go here ``` -------------------------------- ### Search Transaction Details - Ruby Request Source: https://developer.bka.sh/reference/supporting-operations-2 Example of how to search for transaction details using Ruby. This snippet demonstrates making a POST request to the specified API endpoint with required headers. ```ruby # Ruby example would go here ``` -------------------------------- ### POST /tokenized/checkout/create Source: https://developer.bka.sh/reference/post_tokenized-checkout-create Creates a new payment agreement with bKash. This endpoint is used to initiate a payment process, requiring customer details and payment information. ```APIDOC ## POST /tokenized/checkout/create ### Description Creates a new payment agreement with bKash. This endpoint is used to initiate a payment process, requiring customer details and payment information. ### Method POST ### Endpoint /tokenized/checkout/create ### Parameters #### Header Parameters - **Authorization** (string) - Required - Bearer token for authentication. - **X-APP-Key** (string) - Required - Your application's API key. #### Request Body - **callbackURL** (string) - Required - The base URL for callbacks. - **mode** (string) - Required - The tokenization mode. - **payerReference** (string) - Optional - A reference for the payer. - **agreementID** (string) - Optional - An existing agreement ID. - **amount** (string) - Optional - The payment amount. - **currency** (string) - Optional - The currency of the payment. - **intent** (string) - Optional - The payment intent (e.g., 'sale'). - **merchantInvoiceNumber** (string) - Optional - A unique invoice number from the merchant. ### Request Example ```json { "callbackURL": "https://example.com/callback", "mode": "1", "payerReference": "payer123", "amount": "100.00", "currency": "BDT", "intent": "sale", "merchantInvoiceNumber": "INV12345" } ``` ### Response #### Success Response (200) - **paymentID** (string) - The unique identifier for the payment. - **agreementID** (string) - The unique identifier for the payment agreement. - **paymentCreateTime** (string) - The timestamp when the payment was created. - **transactionStatus** (string) - The status of the transaction. - **amount** (string) - The payment amount. - **currency** (string) - The currency of the payment. - **intent** (string) - The payment intent. - **merchantInvoiceNumber** (string) - The merchant's invoice number. - **bkashURL** (string) - The URL to redirect the user for payment authorization. - **callbackURL** (string) - The base callback URL. - **successCallbackURL** (string) - The URL for successful payment callbacks. - **failureCallbackURL** (string) - The URL for failed payment callbacks. - **cancelledCallbackURL** (string) - The URL for cancelled payment callbacks. - **statusCode** (string) - The status code of the response. - **statusMessage** (string) - The status message of the response. #### Response Example ```json { "paymentID": "payment12345", "agreementID": "agreement67890", "paymentCreateTime": "2023-10-27T10:00:00Z", "transactionStatus": "pending", "amount": "100.00", "currency": "BDT", "intent": "sale", "merchantInvoiceNumber": "INV12345", "bkashURL": "https://tokenized.sandbox.bka.sh/v1.2.0-beta/checkout/pay?paymentID=payment12345", "callbackURL": "https://example.com/callback", "successCallbackURL": "https://example.com/success", "failureCallbackURL": "https://example.com/failure", "cancelledCallbackURL": "https://example.com/cancelled", "statusCode": "200", "statusMessage": "Success" } ``` ``` -------------------------------- ### Search Transaction Details - cURL Request Source: https://developer.bka.sh/reference/supporting-operations-2 Example of how to make a POST request to search for transaction details using cURL. It includes the endpoint URL and necessary headers for JSON content. ```shell curl --request POST \ --url https://tokenized.sandbox.bka.sh/v1.2.0-beta/tokenized/checkout/general/searchTransaction \ --header 'accept: application/json' \ --header 'content-type: application/json' ``` -------------------------------- ### Create Payment (Sale or Authorize) Source: https://developer.bka.sh/reference/createpaymentusingpost This endpoint allows you to create a payment transaction, either as a sale or an authorization, for a given amount and currency. ```APIDOC ## POST /checkout/payment/create ### Description Creates a payment transaction, supporting both 'sale' and 'authorization' intents. ### Method POST ### Endpoint /checkout/payment/create ### Parameters #### Header Parameters - **Authorization** (string) - Required - Authentication token. - **X-APP-Key** (string) - Required - Application key for authentication. #### Request Body - **amount** (string) - Required - The payment amount. - **currency** (string) - Required - The currency code (e.g., 'BDT'). - **intent** (string) - Required - The type of transaction intent ('sale' or 'authorization'). - **merchantInvoiceNumber** (string) - Required - Unique invoice number for the merchant. - **merchantAssociationInfo** (string) - Optional - Information related to merchant association. ### Request Example ```json { "amount": "100.00", "currency": "BDT", "intent": "sale", "merchantInvoiceNumber": "INV12345", "merchantAssociationInfo": "" } ``` ### Response #### Success Response (200) - **paymentID** (string) - The unique identifier for the created payment. - **createTime** (string) - The timestamp when the payment was created. - **orgLogo** (string) - The logo of the organization. - **orgName** (string) - The name of the organization. - **transactionStatus** (string) - The status of the payment transaction. - **amount** (string) - The payment amount. - **currency** (string) - The currency code. - **intent** (string) - The transaction intent. - **merchantInvoiceNumber** (string) - The merchant's invoice number. #### Response Example ```json { "paymentID": "pay_5f5e3f8a5d4f3d2c1b0a9876", "createTime": "2023-10-27T10:00:00Z", "orgLogo": "https://example.com/logo.png", "orgName": "Example Merchant", "transactionStatus": "PENDING", "amount": "100.00", "currency": "BDT", "intent": "sale", "merchantInvoiceNumber": "INV12345" } ``` ``` -------------------------------- ### Search Transaction Details - Node.js Request Source: https://developer.bka.sh/reference/supporting-operations-2 Example of how to search for transaction details using Node.js. This snippet demonstrates making a POST request to the specified API endpoint with required headers. ```javascript // Node.js example would go here ``` -------------------------------- ### POST Payment Status (Node.js) Source: https://developer.bka.sh/reference/payment-1 Example of how to make a POST request to the Payment Status API using Node.js. This demonstrates using the 'axios' library to send the request with appropriate headers. ```javascript const axios = require('axios'); const options = { method: 'POST', url: 'https://tokenized.sandbox.bka.sh/v1.2.0-beta/tokenized/checkout/payment/status', headers: { 'accept': 'application/json', 'content-type': 'application/json' } }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### POST Payment Status (PHP) Source: https://developer.bka.sh/reference/payment-1 Example of how to make a POST request to the Payment Status API using PHP. This illustrates using cURL functions to set up and execute the request with necessary headers. ```php ``` -------------------------------- ### POST /tokenized/checkout/payment/refund Source: https://developer.bka.sh/reference/post_tokenized-checkout-payment-refund Initiates a refund for a previously completed payment. Requires authentication and specific payment details. ```APIDOC ## POST /tokenized/checkout/payment/refund ### Description This endpoint allows you to process a refund for a bKash payment. You need to provide the payment ID and transaction ID of the original transaction, along with the refund amount and optionally a SKU and reason for the refund. ### Method POST ### Endpoint /tokenized/checkout/payment/refund ### Parameters #### Header Parameters - **Authorization** (string) - Required - Bearer token for authentication. - **X-APP-Key** (string) - Required - Your application's unique key. #### Request Body - **paymentId** (string) - Required - The ID of the payment to be refunded. - **trxID** (string) - Required - The transaction ID of the original payment. - **amount** (string) - Optional - The amount to be refunded. If not provided, the full payment amount will be refunded. - **sku** (string) - Optional - Stock Keeping Unit associated with the transaction. - **reason** (string) - Optional - The reason for the refund. ### Request Example ```json { "paymentId": "your_payment_id", "trxID": "your_trx_id", "amount": "100.50", "sku": "PRODUCT123", "reason": "Customer returned item" } ``` ### Response #### Success Response (200) - **completedTime** (string) - The timestamp when the refund was completed. - **originalTrxID** (string) - The transaction ID of the original payment. - **refundTrxID** (string) - The transaction ID generated for this refund. - **transactionStatus** (string) - The status of the refund transaction. - **amount** (string) - The amount that was refunded. - **currency** (string) - The currency of the refunded amount. #### Response Example ```json { "completedTime": "2023-10-27T10:30:00Z", "originalTrxID": "your_trx_id", "refundTrxID": "refund_trx_id_12345", "transactionStatus": "SUCCESS", "amount": "100.50", "currency": "BDT" } ``` ``` -------------------------------- ### Capture Payment using cURL Source: https://developer.bka.sh/reference/authorized-and-capture This snippet demonstrates how to capture a payment using a cURL request. It includes the POST method, the endpoint URL, and necessary headers like 'accept'. ```shell curl --request POST \ --url https://checkout.sandbox.bka.sh/v1.2.0-beta/checkout/payment/capture/paymentID \ --header 'accept: application/json' ``` -------------------------------- ### POST /tokenized/checkout/token/grant Source: https://developer.bka.sh/reference/gettokenusingpost-2 This endpoint is used to obtain access tokens for bKash services. It requires authentication credentials and application-specific keys. ```APIDOC ## POST /tokenized/checkout/token/grant ### Description Grants an access token required for authenticating requests to the bKash Tokenized API. This endpoint is part of the token management flow. ### Method POST ### Endpoint /tokenized/checkout/token/grant ### Parameters #### Header Parameters - **username** (string) - Required - The username for authentication. - **password** (string) - Required - The password for authentication. #### Request Body - **app_key** (string) - Required - The application key provided by bKash. - **app_secret** (string) - Required - The application secret provided by bKash. ### Request Example ```json { "app_key": "YOUR_APP_KEY", "app_secret": "YOUR_APP_SECRET" } ``` ### Response #### Success Response (200) - **expires_in** (string) - The expiration time of the token. - **id_token** (string) - The generated access token. - **refresh_token** (string) - The token used to refresh the access token. - **token_type** (string) - The type of token (e.g., Bearer). - **statusCode** (string) - The status code of the response. - **statusMessage** (string) - A message describing the status of the response. #### Response Example ```json { "expires_in": "3600", "id_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "token_type": "Bearer", "statusCode": "200", "statusMessage": "Success" } ``` ``` -------------------------------- ### Grant Token API Request (Ruby) Source: https://developer.bka.sh/reference/token This Ruby snippet demonstrates how to obtain a grant token using the 'net/http' library. It constructs a POST request to the specified BKA.sh endpoint, includes the necessary JSON payload with application credentials, and sets the required headers for authentication and content negotiation. Error handling is included for robustness. ```ruby require 'net/http' require 'uri' require 'json' def grant_token(app_key, app_secret, username, password) uri = URI.parse('https://checkout.sandbox.bka.sh/v1.2.0-beta/checkout/token/grant') http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Post.new(uri.request_uri) request['Content-Type'] = 'application/json' request['Accept'] = 'application/json' request['username'] = username request['password'] = password request.body = JSON.dump({ app_key: app_key, app_secret: app_secret }) response = http.request(request) if response.code == '200' JSON.parse(response.body) else raise "Error granting token: #{response.body}" end end # Example usage: # begin # token_data = grant_token('YOUR_APP_KEY', 'YOUR_APP_SECRET', 'YOUR_USERNAME', 'YOUR_PASSWORD') # puts token_data # rescue => e # puts e.message # end ``` -------------------------------- ### POST /v1.2.0-beta/checkout/payment/create Source: https://developer.bka.sh/reference/index Creates a new payment transaction. This endpoint supports both 'sale' (immediate transfer) and 'authorization' (holding funds for later capture) intents. ```APIDOC ## POST /v1.2.0-beta/checkout/payment/create ### Description Initiates a payment transaction. This endpoint can be used for immediate sales or to authorize funds for later capture. ### Method POST ### Endpoint https://checkout.sandbox.bka.sh/v1.2.0-beta/checkout/payment/create ### Parameters #### Header Parameters - **Authorization** (string) - Required - Authentication token. - **X-APP-Key** (string) - Required - Application key for authentication. #### Request Body - **amount** (string) - Required - The payment amount. - **currency** (string) - Required - The currency of the payment (e.g., BDT). - **intent** (string) - Required - The type of transaction: 'sale' or 'authorization'. - **merchantInvoiceNumber** (string) - Required - Unique identifier for the merchant's invoice. - **merchantAssociationInfo** (string) - Optional - Information related to merchant association. ### Request Example ```json { "amount": "100.50", "currency": "BDT", "intent": "sale", "merchantInvoiceNumber": "INV-12345", "merchantAssociationInfo": "Optional details" } ``` ### Response #### Success Response (200) - **paymentID** (string) - Unique identifier for the created payment. - **createTime** (string) - Timestamp when the payment was created. - **orgLogo** (string) - URL for the organization's logo. - **orgName** (string) - Name of the organization. - **transactionStatus** (string) - The status of the transaction (e.g., 'PENDING', 'COMPLETED'). - **amount** (string) - The payment amount. - **currency** (string) - The currency of the payment. - **intent** (string) - The intent of the transaction ('sale' or 'authorization'). - **merchantInvoiceNumber** (string) - The merchant's invoice number. #### Response Example ```json { "paymentID": "pay_123abc456def", "createTime": "2023-10-27T10:00:00Z", "orgLogo": "https://example.com/logo.png", "orgName": "Example Merchant", "transactionStatus": "PENDING", "amount": "100.50", "currency": "BDT", "intent": "sale", "merchantInvoiceNumber": "INV-12345" } ``` ```