xenon/bkash-php

这是一个易于集成到您的PHP应用程序中的PHP SDK

此包的规范存储库似乎已消失,因此该包已被冻结。

v1.0.3 2023-10-25 21:40 UTC

This package is auto-updated.

Last update: 2024-06-25 23:19:28 UTC


README

xenon/bkash-php 是一个用于在网站上轻松集成 Bkash API 的 Bkash PHP SDK。按照以下步骤进行,以获得更好的理解。

步骤 1:安装

composer require xenon/bkash-php

步骤 2:格式配置

创建您的凭据(数组)以配合使用 Xenon\BkashPhp\BkashPhp

$configuration = [
        'config' => [
            "app_key" => "app key goes here",
            "app_secret" => "app secret goes here",
        ],
        'headers' => [
            "username" => "username goes here",
            "password" => "password goes here",
        ]
    ];

步骤 3:异常

异常处理

use Xenon\BkashPhp\Handler\Exception\RenderBkashPHPException

始终在 try 块下调用以下方法。如果在这些方法中的任何一个失败或发生异常,则将抛出 RenderBkashPHPException

createTokenizedPayment()
executePayment()
searchTransaction()

创建支付 URL

Bkash 支付网关允许您根据不同的参数创建支付 URL。请按照以下代码示例进行操作

use Xenon\BkashPhp\Handler\Exception\RenderBkashPHPException
use Xenon\BkashPhp\BkashPhp;

try{
   $paymentData = [ 
        'mode' => '0011', //fixed
        'payerReference' => '017AAXXYYZZ',
        'callbackURL' => 'http://example.com/callback',
        'merchantAssociationInfo' => 'xxxxxxxxxx',
        'amount' => 10,
        'currency' => 'BDT', //fixed
        'intent' => 'sale', //fixed
        'merchantInvoiceNumber' => "invoice number goes here",
    ];
    $createTokenizedPaymentResponse = $bkash->createTokenizedPayment($paymentData);

}catch(RenderBkashPHPException $e){
    //do whatever you want
}

如果一切顺利,它将返回以下对象。然后从以下对象重定向到 bkashURL

stdClass Object
(
    [statusCode] => 0000
    [statusMessage] => Successful
    [paymentID] => TR0011DVJQOkh169400XXX
    [bkashURL] => https://sandbox.payment.bkash.com/redirect/tokenized/?paymentID=TR0011DVJQOkh1694007349990&hash=yaJMHgVb_BW_pJuxErXXXdf8-QFyHHG0bqkwBdUU(NLFwI(-ltH8z36kpnxtxa5Xs5tJxFxW5KoyKN5nWPisXXXXXXXXXXX50209&mode=0011&apiVersion=v1.2.0-beta
    [callbackURL] => http://example.com/callback
    [successCallbackURL] => http://example.com/callback?paymentID=TR0011DVJQOkh169400XXX&status=success
    [failureCallbackURL] => http://example.com/callback?paymentID=TR0011DVJQOkh169400XXX&status=failure
    [cancelledCallbackURL] => http://example.com/callback?paymentID=TR0011DVJQOkh169400XXX&status=cancel
    [amount] => 10
    [intent] => sale
    [currency] => BDT
    [paymentCreateTime] => 2023-09-06T19:35:50:209 GMT+0600
    [transactionStatus] => Initiated
    [merchantInvoiceNumber] => dsf64f8803XXX93
)

执行支付

支付完成后,客户将被重定向到具有类似以下查询字符串的商家回调 URL
"https://example.com?paymentID=TR0011ZCxlJhC1693137759378&status=success"

现在是时候使用 paymentID 调用 executePayment() 方法了

use Xenon\BkashPhp\Handler\Exception\RenderBkashPHPException
use Xenon\BkashPhp\BkashPhp;

try{
    $bkash = new BkashPhp($configuration);
    $executePaymentResponse = $bkash->executePayment($paymentId);

}catch(RenderBkashPHPException $e){
    //do whatever you want
}

stdClass Object
(
    [statusCode] => 0000
    [statusMessage] => Successful
    [paymentID] => TR0011DVJQOkh169400XXX
    [payerReference] => 017AAXXYYZZ
    [customerMsisdn] => 01877722345
    [trxID] => AI620D4DVQ
    [amount] => 10
    [transactionStatus] => Completed
    [paymentExecuteTime] => 2023-09-06T19:11:01:698 GMT+0600
    [currency] => BDT
    [intent] => sale
    [merchantInvoiceNumber] => dsf64f8803XXX93
)

查询支付

在成功执行支付后,需要调用 searchTransaction() 方法。

use Xenon\BkashPhp\Handler\Exception\RenderBkashPHPException
use Xenon\BkashPhp\BkashPhp;

try{
    $trxID = request()->trxID; //get trxID from executePayment() method
    $bkash = new BkashPhp($configuration);
    $searchPaymentResponse = $bkash->searchTransaction($trxID);
}catch(RenderBkashPHPException $e){
    //do whatever you want
}

This will match trxID with bkash database. After getting response object you will do further according to your web application requirements.
stdClass Object
(
    [trxID] => AI620D4DVQ
    [initiationTime] => 2023-09-06T22:15:34:000 GMT+0600
    [completedTime] => 2023-09-06T22:15:34:000 GMT+0600
    [transactionType] => bKash Tokenized Checkout via API
    [customerMsisdn] => 01877722345
    [transactionStatus] => Completed
    [amount] => 10
    [currency] => BDT
    [organizationShortCode] => 50022
    [statusCode] => 0000
    [statusMessage] => Successful
)

星标者

Stargazers repo roster for @arif98741/bkash-php

分支者

Forkers repo roster for @arif98741/bkash-php

贡献者



这只是开始。本包将在未来得到更多丰富。如果您在此存储库中发现任何问题或错误,请创建一个问题。任何技术建议或意见都将非常受赞赏