PHP code example of wmsn-web / bkash-php-client

1. Go to this page and download the library: Download wmsn-web/bkash-php-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wmsn-web / bkash-php-client example snippets


use WmsnWeb\BkashPhpClient\BkashPhpClient;

$bkash = new BkashPhpClient([
    "base_url" => "https://tokenized.sandbox.bka.sh/v1.2.0-beta/tokenized",
    "username" => "YOU_BKASH_USERNAME",
    "password" => "BKASH_PASSWORD",
    "app_key" => "BKASH_APP_KEY",
    "app_secret" => "BKASH_APP_SECRET_KEY",
    "type"      =>"sandbox" // or 'prod'
]);

$credentials = array(
    "base_url" => "https://tokenized.sandbox.bka.sh/v1.2.0-beta/tokenized",
    "username" => "YOU_BKASH_USERNAME",
    "password" => "BKASH_PASSWORD",
    "app_key" => "BKASH_APP_KEY",
    "app_secret" => "BKASH_APP_SECRET_KEY",
    "type"      =>"sandbox" // or 'prod'
);

$bkash = new BkashPhpClient($credentials);

$response = $bkash->GrantToken();

[
  "token_type"=> "Bearer",
  "id_token"=> "test_id_token_value",
  "expires_in"=> 3600,
  "refresh_token"=> "test_refresh_token_value"
]

$response = $bkash->refreshToken($refresh_token);

$postArray = [
    'mode'                  => '0011',
    'amount'                => 100,
    'payerReference'        =>"11",
    'callbackURL'           => Your callback URL
    'currency'              => 'BDT',
    'intent'                => 'sale',
    'merchantInvoiceNumber' => INVOICE NUMBER
];
$response = $bkash->createPayment($token, $postArray);

[
    "statusCode"                => "0000", 
    "statusMessage"             => "Successful", 
    "paymentID"                 => "TR0001VK1565072365492", //Timespan 24 hours
    "bkashURL"                  =>"URL TO CHECKOUT THE PAYMENT",
    "callbackURL"               => "https://yourdomain.com/callback?version=v1.2.0-beta&product=tokenized-checkout",
    "successCallbackURL"        => "https://yourdomain.com/callback?version=v1.2.0-beta&product=tokenized-checkout&paymentID=TR0011dQPHnuY1720518383420&status=success&signature=cm8HBfl65A",
    "failureCallbackURL"        => "https://yourdomain.com/callback?version=v1.2.0-beta&product=tokenized-checkout&paymentID=TR0011dQPHnuY1720518383420&status=failure&signature=cm8HBfl65A",
    "cancelledCallbackURL"      => "https://yourdomain.com/callback?version=v1.2.0-beta&product=tokenized-checkout&paymentID=TR0011dQPHnuY1720518383420&status=cancel&signature=cm8HBfl65A",
    "amount"                    => "500", 
    "intent"                    => "sale", 
    "currency"                  => "BDT", 
    "agreementID"               => "TokenizedMerchant01L3IKB6H1565072174986", 
    "paymentCreateTime"         => "2019-08-06T12:19:25:593 GMT+0600", 
    "transactionStatus"         => "Initiated", 
    "merchantInvoiceNumber"     => "Inv0124" 
]

$response = $bkash->executePayment($token, $response['paymentID']);

[ 
    "statusCode"                => "0000", 
    "statusMessage"             => "Successful", 
    "paymentID"                 => "TR0001VK1565072365492", 
    "agreementID"               => "TokenizedMerchant01L3IKB6H1565072174986", 
    "payerReference"            => "01770618575", 
    "customerMsisdn"            => "01770618575", 
    "trxID"                     => "6H6201QDIY", 
    "amount"                    => "12", 
    "transactionStatus"         => "Completed", 
    "paymentExecuteTime"        => "2019-08-06T12:22:41:428 GMT+0600", 
    "currency"                  => "BDT", 
    "intent"                    => "sale", 
    "merchantInvoiceNumber"     => "TestForOnmobile" 
]

$paymentID = 'PAYMENT_ID_FROM_CREATE';
$token = 'from your database'.
$response = $bkash->paymentStatus($token, $paymentID);