bkash payment getway

By ukmodak | March 31st 2024 10:38:02 AM | viewed 276 times

bkash payment getway

After adding data in the following table call bkash payment getway
CREATE TABLE `ec_orders` (
  `id` bigint(20) NOT NULL,
  `order_no` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `user_meta_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `guest_id` bigint(20) DEFAULT NULL,
  `member_type_id` bigint(20) DEFAULT NULL,
  `coupon_id` bigint(20) DEFAULT NULL,
  `payment_type_meta_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `order_date` datetime DEFAULT NULL,
  `is_delevery` varchar(255) COLLATE utf8_unicode_ci DEFAULT 'pending',
  `is_paid` varchar(255) COLLATE utf8_unicode_ci DEFAULT '0',
  `transaction_voucher` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `create_by` bigint(20) DEFAULT NULL,
  `update_by` bigint(20) DEFAULT NULL,
  `create_date` date DEFAULT NULL,
  `update_date` date DEFAULT NULL,
  `process_date` datetime DEFAULT NULL,
  `process_by` bigint(20) DEFAULT NULL,
  `total` double DEFAULT NULL,
  `subtotal` float NOT NULL,
  `delivery_point_meta_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `total_in_kg` float DEFAULT NULL,
  `shipping_id` bigint(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Add view that provide by bkash
ecommerce.bkash.index =>

<?php $rp = URL::to('/').'/';?>
<!DOCTYPE html>
<html> 
<head>
<script>
    var rpath ="<?php echo $rp; ?>";
</script>       
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="{{asset('public/images/favicon.ico')}}" type="image/x-icon">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link href="{{asset('public/font-awesome-4.7.0/css/font-awesome.min.css')}}" rel="stylesheet" type="text/css" >
<link rel="stylesheet" href="{{asset('public/lte/css/adminlte.css')}}" />
<link href="{{URL::asset('public/css/custom.css')}}" rel="stylesheet" type="text/css" >
  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script id="myScript" src="https://scripts.pay.bka.sh/versions/1.2.0-beta/checkout/bKash-checkout.js"></script>
<script src="{{URL::asset('public/js/bscript.js')}}"></script>

<style>
    .bg{
        background-color:#E1E1E1;
        margin:0;
        padding:0;
        width:100%;
        height:100%;
    }
    
    .bbutton{
        width: 46%;
        margin: 20% 27%;
    }
    
    #bKash_button{
        background-color:#D62267;
        color:white;
        border:1px solid red;
        cursor: pointer;
    }
</style>

</head>

<body class="bg">  
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 cls">
   
    <div class="bbutton" align="center">
        <input type="hidden" name="_token" id="ktn" value="{{csrf_token()}}">
			@if(@$is_order)
			   <button id="bKash_button">Pay With bKash</button>
			@endif
    </div>
     
</div>
    
 <script type="text/javascript">
 
    var accessToken='';
    var gtoken =$("#ktn").val();
    
    $(document).ready(function(){
        $.ajax({
            url: "<?php echo $rp ?>bpay/tokalize",
            type: 'POST',
            headers: {'X-CSRF-TOKEN': gtoken },
            contentType: 'application/json',
            success: function (data) {
                 //alert('[Token] data : ' + JSON.stringify(data));
                console.log('got data from token  ..');
		console.log(JSON.stringify(data));
				
                accessToken=JSON.stringify(data);
            },
			error: function(){
			console.log('error');
                        
            }
        });

        var paymentConfig={
            createCheckoutURL:"bpay/createPayment",
            executeCheckoutURL:"bpay/executePayment",
        };

		
        var paymentRequest;
        var amt ="<?php echo @$amount; ?>";
        paymentRequest = { amount:amt,intent:'sale'};
		console.log(JSON.stringify(paymentRequest));

        bKash.init({
            paymentMode: 'checkout',
            paymentRequest: paymentRequest,
            createRequest: function(request){
                console.log('=> createRequest (request) :: ');
                console.log(request);
                
                $.ajax({
                    url: paymentConfig.createCheckoutURL+"?amt="+paymentRequest.amount,
                    type:'POST',
                    headers: {'X-CSRF-TOKEN': gtoken },
                    contentType: 'application/json',
                    success: function(data) {
                        console.log('got data from create  ..');
                        console.log('data ::=>');
                        console.log(JSON.stringify(data));
                         //alert('[createPayment] data : ' + JSON.stringify(data));
                        var obj = JSON.parse(data);
                        
                        if(data && obj.paymentID != null){
                            paymentID = obj.paymentID;
                            bKash.create().onSuccess(obj);
                        }
                        else {
			                console.log('error');
                            bKash.create().onError();
                        }
                    },
                    error: function(){
			            console.log('error');
                        bKash.create().onError();
                    }
                });
            },
            
            executeRequestOnAuthorization: function(){
                console.log('=> executeRequestOnAuthorization');
                $.ajax({
                    url: paymentConfig.executeCheckoutURL+"?pid="+paymentID,
                    type: 'POST',
                    headers: {'X-CSRF-TOKEN': gtoken},
                    contentType:'application/json',
                    success: function(data){
                        console.log('got data from execute  ..');
                        console.log('data ::=>');
                        console.log(JSON.stringify(data));
                        
                        data = JSON.parse(data);
                        //alert('[executePayment] data : ' + JSON.stringify(data));

                        if(data && data.trxID != null){
                            window.location.href = "ordermanage/orderSuc"; 
                        }else{
                            onUkError(data);
                             
                        }
                        /*else {
                            bKash.execute().onError();
                        }*/
                    },
                    error: function(){
                        bKash.execute().onError();
                    }
                });
            }
 
        });
        
		console.log("Right after init ");
    
        
    });
	
	function callReconfigure(val){
        bKash.reconfigure(val);
    }

    function clickPayButton(){
        $("#bKash_button").trigger('click');
    }


</script>
 @include('public_lte_template.bikash_message')
 
</body>
</html>

Add view for popup messae
public_lte_template.bikash_message =>

<div id="bkashMsg" class="modal fade" role="dialog" style="z-index:999999;">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close ukmsgclose" data-dismiss="modal"><i class="fa fa-remove btn-lg"></i></button>
        <h5  class="align">Alert Message</h5>
      </div>
      <div class="modal-body">
          <div class="content contentPadding contentBg">
                <div class="container-fluid">
                        <div class="row">
                                <div class="col-xs-12 colsm-12 col-md-12 col-lg-12">
                                        <div class=""> 
                                                <div class="panel-body">
                                                        <div class="col-xs-12 colsm-12 col-md-12 col-lg-12 nopadding" align="center">    
                                                                 <p class="alert_msg"></p> 
                                                         </div>
                                                </div>
                                        </div>
                                </div>
                        </div>
                </div>
           </div>
      </div>
    </div>
  </div>
</div>
Add script
js/bscript =>

var baseurl =rpath;
jQuery("document").ready(function(){   
      jQuery(".ukmsgclose").click(function(){
           window.location.href = baseurl;
      });      
       jQuery("#yes_button").click(function(){
           window.location.href = baseurl;
       });     
});

 function onUkError(data){
     var msg="";
     if(data.errorCode=='2001'){
         msg = data.errorMessage;
     }else if(data.errorCode=='2002'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2003'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2004'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2005'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2006'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2007'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2008'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2009'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2010'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2011'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2012'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2013'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2014'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2015'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2016'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2017'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2018'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2019'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2020'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2021'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2022'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2023'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2024'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2025'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2026'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2027'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2028'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2029'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2030'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2031'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2032'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2033'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2034'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2035'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2036'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2037'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2038'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2039'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2040'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2041'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2042'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2043'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2044'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2045'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2046'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2047'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2048'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2049'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2050'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2051'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2052'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2053'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2054'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2055'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2056'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2057'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2058'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2059'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2060'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2061'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2062'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2063'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2064'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2065'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2066'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2067'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2068'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='2069'){
        msg = data.errorMessage; 
     }else if(data.errorCode=='503'){
        msg = data.errorMessage; 
     }
    
     jQuery(".text-center").css("display","none");
     jQuery(".bbutton").css("display","none");
     
     jQuery("#bkashMsg").modal("show");
     jQuery(".alert_msg").html(msg);
       return true;
 }

Add Router

Route::get('bpay','BikashController@index');     /* first call */ 
Route::post('bpay/tokalize','BikashController@tokalize');     /* second call when click on bkash payment button */
Route::post('bpay/createPayment','BikashController@createPayment');  /* third call for mobile verification */
Route::post('bpay/executePayment','BikashController@executePayment'); /* forth call for pin verification */
Route::post('bpay/queryPayment','BikashController@queryPayment');     /* fifth call for payment */

Route::get('bpay/searchTran',['uses'=>'BikashController@searchTran', 'as'=>'bpay/searchTran']);   /* admin query for payment status */
Route::post('bpay/bkashTransactionQuery','BikashController@bkashTransactionQuery');   /* admin query for payment status */
Route::post('bpay/tranChecktokalize','BikashController@tranChecktokalize');            /* admin token varification */

Route::post('bpay/success','BikashController@success');
Route::get('bpay/fail','BikashController@fail');
Route::post('bpay/cancel','BikashController@cancel');

Add a controller
<?php namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use DB;
use Session;
use App\User;
use App\Models\Ecommerce\EcGuest;
use App\Models\Ecommerce\EcWishlistProduct;
use App\Models\Ecommerce\EcProdAmtPrice;
use App\Models\Ecommerce\EcLocation;
use Carbon\Carbon;
use App\Models\Ecommerce\EcOrder;
use App\Models\Ecommerce\EcAddrese;
use App\Models\Ecommerce\EcBkash;

class BikashController extends Controller {
        
public function tokalize(Request $request){
         
        $app_key ="2skad45dr91pci7d114_XXXXXXXX";
        $app_secret ="mlpk9mhceciire8qauul07saffn81d_XXXXXXXXXXXXXXXXX";
        $username ="XXXX";
        $password ="XXXXXXXXXXXXXXX";
        $tokenURL = "https://checkout.pay.bka.sh/v1.2.0-beta/checkout/token/g_XXXXXXXX";
     
      $post_token = array(
        'app_key'=>$app_key,                                              
        'app_secret'=>$app_secret                  
	);	
    
     $url = curl_init($tokenURL);
    
	$proxy ="";
	$posttoken = json_encode($post_token);
	$header = array(
		'Content-Type:application/json',
		'password:'.$password,                                                               
                'username:'.$username                                                          
        );				
    
    curl_setopt($url,CURLOPT_HTTPHEADER, $header);
    curl_setopt($url,CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($url,CURLOPT_RETURNTRANSFER, true);
    curl_setopt($url,CURLOPT_POSTFIELDS, $posttoken);
    curl_setopt($url,CURLOPT_FOLLOWLOCATION, 1);
    $resultdata = curl_exec($url);
    curl_close($url);

     $resultdata =  json_decode($resultdata, true);
     
     $tokenNizeArray = array();
     
     $tokenNizeArray['token']= $resultdata['id_token'];
     $tokenNizeArray['refresh_token']= $resultdata['refresh_token'];
     
     Session::put("service_token",@$tokenNizeArray);
     
     
     //return response()->json($resultdata['id_token']); 
     return response()->json($resultdata); 

    }
    
    public function tranChecktokalize(){
         
        $app_key ="2skad45dr91pci7d114_XXXXXXXX";
        $app_secret ="mlpk9mhceciire8qauul07saffn81d_XXXXXXXXXXXXXXXXX";
        $username ="XXXX";
        $password ="XXXXXXXXXXXXXXX";
        $tokenURL = "https://checkout.pay.bka.sh/v1.2.0-beta/checkout/token/g_XXXXXXXX";
     
      $post_token = array(
        'app_key'=>$app_key,                                              
        'app_secret'=>$app_secret                  
	);	
    
     $url = curl_init($tokenURL);
    
	$proxy ="";
	$posttoken = json_encode($post_token);
	$header = array(
		'Content-Type:application/json',
		'password:'.$password,                                                               
                'username:'.$username                                                          
        );				
    
    curl_setopt($url,CURLOPT_HTTPHEADER, $header);
    curl_setopt($url,CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($url,CURLOPT_RETURNTRANSFER, true);
    curl_setopt($url,CURLOPT_POSTFIELDS, $posttoken);
    curl_setopt($url,CURLOPT_FOLLOWLOCATION, 1);
    $resultdata = curl_exec($url);
    curl_close($url);

     return $resultdata;

    }
        
        
    public function createPayment(Request $request){
            
            
            $amt = null;
            $amt = $request->input('amt');
            
            $token_id = null;
            $refresh_token = null;
            $amount = null;
            $invoice = null;
            $currency = null;
            $intent = null;
            $proxy = null;
            
            $service_token = Session::get('service_token');
            //$dataList = Session::get('testArray');
            $dataList = Session::get('post_data');
            
            $createURL ="https://checkout.pay.bka.sh/v1.2.0-beta/checkout/payment/cXXXXXXX";
            $app_key ="2skad45dr91pci7d114_XXXXXXXX";
       
          
            
            
           if($service_token){
                
            $token_id = $service_token['token'];
            $refresh_token = $service_token['refresh_token'];

            $amount = $dataList['total_amount'];
            $invoice = $dataList['orderNo'];
            $currency = $dataList['currency'];
            $intent = $dataList['intent'];
            $proxy = $dataList['proxy'];
            
           }
          
   
           $createpaybody = array(
                           'amount'=>$amount,
                           'currency'=>$currency,
                           'merchantInvoiceNumber'=>$invoice,
                           'intent'=>$intent
                         ); 
    
            $url = curl_init($createURL);

            $createpaybodyx = json_encode($createpaybody);

            $header=array(
                'Content-Type:application/json',
                'authorization:'.$token_id,
                'x-app-key:'.$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, $createpaybodyx);
            curl_setopt($url,CURLOPT_FOLLOWLOCATION, 1);
            //curl_setopt($url, CURLOPT_PROXY, $proxy);
             curl_setopt($url, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);

            $resultdata = curl_exec($url);
            
             
            curl_close($url);
            
            $resultdata = json_decode($resultdata);

              if($resultdata){
                   
                   $ecBkashIns = new EcBkash();
                   $ecBkashIns->total_amount = @$amount;
                   $ecBkashIns->invoice_no = @$invoice;
                   $ecBkashIns->payment_id = @$resultdata->paymentID;
                   $ecBkashIns->payment_status = @$resultdata->transactionStatus;
                   $ecBkashIns->org_name = @$resultdata->orgName;
                   $ecBkashIns->create_date = Carbon::now();
                   $ecBkashIns->token = @$token_id;
                   $ecBkashIns->refresh_token = @$refresh_token;
                   
                   $ecBkashIns->save();

              }
              $resultdata = json_encode($resultdata);

                return response()->json($resultdata);

        }
        
        public function executePayment(Request $request){
          
         $resultdatax = null;
         $objResult = null;
         $service_token = Session::get('service_token');
         $dataList = Session::get('post_data');
         $executeURL ="https://checkout.pay.bka.sh/v1.2.0-beta/checkout/payment/exeXXXXXXXX/";
         $app_key ="2skad45dr91pci7d114_XXXXXXXX";
        

         $pamentId = $request->input('pid');
         
         $url = curl_init($executeURL.$pamentId);

         $header=array(
            'Content-Type:application/json',
            'authorization:'.$service_token['token'],
            'x-app-key:'.$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);
            $objResult = json_decode($resultdatax);
            
             if(@$objResult->transactionStatus =='Completed' && @$objResult->trxID){
                  $ecBkashIns = EcBkash::where('payment_id',$pamentId)->where('invoice_no',$dataList['orderNo'])->first();
                  
                  $ecBkashIns->transaction_id = @$objResult->trxID;
                  $ecBkashIns->payment_status = @$objResult->transactionStatus;
                  $ecBkashIns->after_total_amount = @$objResult->amount;
                  $ecBkashIns->save();
                  
                   Session::forget('service_token');
                   Session::forget('post_data');
                   
             }elseif(@$objResult->transactionStatus =='Initiated'){
                   sleep(30);  // 30 seconds
                    $resultdatax2 = $this->queryPayment($service_token['token'],$app_key,$pamentId);
                    $objResult2 = json_decode($resultdatax2);
                   
                    if(@$objResult2->transactionStatus =='Completed'){
                        
                         $ecBkashIns = EcBkash::where('payment_id',$pamentId)->where('invoice_no',$dataList['orderNo'])->first();
                         $ecBkashIns->transaction_id = @$objResult2->trxID;
                         $ecBkashIns->payment_status = @$objResult2->transactionStatus;
                         $ecBkashIns->after_total_amount = @$objResult2->amount;
                         $ecBkashIns->save();
                         $resultdatax = $resultdatax2;
                         
                         Session::forget('service_token');
                         Session::forget('post_data');
                        
                    }
                 
             }else{
                    Session::forget('service_token');
                    Session::forget('post_data');
                    
                    Session::forget('list');  
                    Session::forget('sucOrderArray'); 
                    Session::forget('storeCodeArray');  
             }

            return response()->json($resultdatax);
         
        }
        
      public function queryPayment($token,$app_key,$pamentId){
            
         $queryPaymentURL ="https://checkout.pay.bka.sh/v1.2.0-beta/checkout/payment/quXXXXXX/";

         $url = curl_init($queryPaymentURL.$pamentId);

         $header=array(
            'Content-Type:application/json',
            'authorization:'.$token,
            'x-app-key:'.$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);
            
            return $resultdatax;
         
        }
        
        public function searchTran(Request $request){
            
            @$trxID = $request->input('transaction_id');
            $resultdatax = null;

            if(@$trxID && @$request->input('trns')){               
                $tokenIns = $this->tranChecktokalize();
                $tokenIns = json_decode($tokenIns);               
                $resultdatax = $this->bkashTransactionQuery(trim($trxID),@$tokenIns->id_token);
            }
            
            return view('ecommerce.bkash.search_payment',['resultdatax'=>$resultdatax]);
            
        }
        
        public function bkashTransactionQuery($trxID,$token){
            
           $app_key ="2skad45dr91pci7d114_XXXXXXX";
           $searchTransactionURL ="https://checkout.pay.bka.sh/v1.2.0-beta/checkout/payment/seXXXXXX/";

           $url = curl_init($searchTransactionURL.$trxID);

            $header=array(
               'Content-Type:application/json',
               'authorization:'.$token,
               'x-app-key:'.$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);

            return $resultdatax;
        }


	
	public function index(Request $request){
            
            $response  = null;
            $paymentResponse  = null;
            $executeResponse  = null;
            //$refresh_token = $_GET['refresh_token'];
            $refresh_token = null;
            
            
            $userIns = null;
            $guestIns = null;
            $amount = null;
            $dataList = Session::get('list');
            $sucOrderArray = Session::get('sucOrderArray');
            $post_data = array();
            
            if(!empty($dataList)){
                
                    $post_data['total_amount'] = @$dataList['grantTotal']; 

                    $priceUnitIns = EcOrder::select('ec_price_units.meta_name')
                                    ->join('ec_order_product_dtls','ec_order_product_dtls.order_id','=','ec_orders.id')
                                    ->join('ec_prod_amt_prices','ec_prod_amt_prices.meta_name','=','ec_order_product_dtls.prod_amt_price_meta_name')
                                    ->join('ec_price_units','ec_price_units.meta_name','=','ec_prod_amt_prices.price_unit_meta_name')
                                    ->where('ec_orders.order_no','=',$sucOrderArray['Order No'])
                                    ->first();

                    $post_data['currency'] = (@$priceUnitIns->meta_name =='tk')? 'BDT':"USD";
                    $post_data['orderNo'] = @$sucOrderArray['Order No'];
                    $post_data['intent'] = 'sale';
                    $post_data['proxy'] = '';

                Session::put("post_data",@$post_data);
            }
            
             if(empty(Session::get('post_data')['orderNo'])){
                return redirect('/');  
             }
             
            // print_r(Session::get('post_data'));
   
        return view('ecommerce.bkash.index',['amount'=>Session::get("post_data")['total_amount'],'is_order'=>Session::get("post_data")['orderNo']]);
        
        
                      
	}
	
	public function success(Request $request)               
	{
                      
	}
	
	public function fail(Request $request)               
	{
            
            Session::forget('list');  
            Session::forget('sucOrderArray'); 
            Session::forget('storeCodeArray'); 
            
            return view('ecommerce.bkash.fail'); 
           
	}
	
	public function cancel(Request $request)               
	{
                      
	}             
}
When call bpay/createPayment and bpay/executePayment then create and update data in the following table
$ecBkashIns = new EcBkash();
$ecBkashIns->total_amount = @$amount;
$ecBkashIns->invoice_no = @$invoice;
$ecBkashIns->payment_id = @$resultdata->paymentID;
$ecBkashIns->payment_status = @$resultdata->transactionStatus;
$ecBkashIns->org_name = @$resultdata->orgName;
$ecBkashIns->create_date = Carbon::now();
$ecBkashIns->token = @$token_id;
$ecBkashIns->refresh_token = @$refresh_token;
$ecBkashIns->save();
bONEandALL
Visitor

Total : 20166

Today :13

Today Visit Country :

  • China
  • United States
  • United Kingdom
  • Portugal
  • Canada