Giter Site home page Giter Site logo

sadhin555 / bkash-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from arif98741/bkash-php

0.0 0.0 0.0 34 KB

Bkash PHP SDK for tokenized payment. You can easily integrate bkash php gateway in your web application using this package

Home Page: https://sadhin555.github.io/bkash-php/

License: MIT License

PHP 100.00%

bkash-php's Introduction

xenon/bkash-php is a Bkash PHP SDK for integrating bkash api in website easily. Follow below steps for better understanding.

Step 1: Installation

composer require xenon/bkash-php

Step 2: Format Configuration

Create your credentials (array) to use along with Xenon\BkashPhp\BkashPhp class

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

Step 3: Set Environment

create object from BkashPhp Class

use 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",
    ]
];
$bkash = new BkashPhp($configuration);
$bkash->setEnvironment('sandbox'); //sandbox|production

Step 4: Exception

Exception Handling

use Xenon\BkashPhp\Handler\Exception\RenderBkashPHPException

Always call below methods under try block. After any of this method failed or exception occurs then it will throw RenderBkashPHPException

createTokenizedPayment()
executePayment()
searchTransaction()

Create Payment Url

Bkash payment gateway allows you to create payment url based on different parameters. Follow below code sample

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
}

If everything goes well then it will return below object. After that redirect to bkashURL from below object

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://http://127.0.0.1/bkash-project/bkash-payment
    [successCallbackURL] => http://http://127.0.0.1/bkash-project/bkash-payment?paymentID=TR0011DVJQOkh169400XXX&status=success
    [failureCallbackURL] => http://http://127.0.0.1/bkash-project/bkash-payment?paymentID=TR0011DVJQOkh169400XXX&status=failure
    [cancelledCallbackURL] => http://http://127.0.0.1/bkash-project/bkash-payment?paymentID=TR0011DVJQOkh169400XXX&status=cancel
    [amount] => 10
    [intent] => sale
    [currency] => BDT
    [paymentCreateTime] => 2023-09-06T19:35:50:209 GMT+0600
    [transactionStatus] => Initiated
    [merchantInvoiceNumber] => dsf64f8803XXX93
)

Execute Payment

After payment done customer will be redirected to merchant callback url having query string like below
"https://example.com?paymentID=TR0011ZCxlJhC1693137759378&status=success"

Now it's time to call executePayment() method with paymentID

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
)

Query Payment

After successful payment execution, it needs to call searchTransaction() method.

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

try{
    $trxID = request()->trxID; //get trxID from executePayment() method
    $bkash = new BkashPhp($configuration);
    $executePaymentResponse = $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

Stargazers repo roster for @arif98741/bkash-php

Forkers

Forkers repo roster for @arif98741/bkash-php

Contributors



This is a start only. This package will be more enriched in future. If you find any issues or bug , please create an issue in this repository. Any technical suggestion or opinion will be highly appreciated

bkash-php's People

Contributors

arif98741 avatar sim8568x avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.