|
| 1 | +<?php |
| 2 | + |
| 3 | +// # # # # Route # # # # |
| 4 | + |
| 5 | +Route::PUT('bkash-payment', 'BkashController@bkash'); |
| 6 | + |
| 7 | + |
| 8 | +// # # # # Controller # # # # |
| 9 | + |
| 10 | + |
| 11 | +public function bkash() |
| 12 | + { |
| 13 | + |
| 14 | + // Merchant Info |
| 15 | + |
| 16 | + $msisdn = "01200000000"; // bKash Merchant Number. |
| 17 | + |
| 18 | + $user = "Xyz"; // bKash Merchant Username. |
| 19 | + |
| 20 | + $pass = "123"; // bKash Merchant Password. |
| 21 | + |
| 22 | + $url = "https://www.bkashcluster.com:9081"; // bKash API URL with Port Number. |
| 23 | + |
| 24 | + $trxid = "66666AAAAA"; // bKash Transaction ID : TrxID. |
| 25 | + |
| 26 | + |
| 27 | +// Final URL for getting response from bKash. |
| 28 | + |
| 29 | + $bkash_url = $url.'/dreamwave/merchant/trxcheck/sendmsg?user='.$user.'&pass='.$pass.'&msisdn='.$msisdn.'&trxid='.$trxid; |
| 30 | + |
| 31 | + |
| 32 | + $curl = curl_init(); |
| 33 | + |
| 34 | + curl_setopt_array($curl, array( |
| 35 | + |
| 36 | + CURLOPT_PORT => 9081, |
| 37 | + |
| 38 | + CURLOPT_URL => $bkash_url, |
| 39 | + |
| 40 | + CURLOPT_RETURNTRANSFER => true, |
| 41 | + |
| 42 | + CURLOPT_ENCODING => "", |
| 43 | + |
| 44 | + CURLOPT_MAXREDIRS => 10, |
| 45 | + |
| 46 | + CURLOPT_TIMEOUT => 30, |
| 47 | + |
| 48 | + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
| 49 | + |
| 50 | + CURLOPT_CUSTOMREQUEST => "GET", |
| 51 | + |
| 52 | + CURLOPT_HTTPHEADER => array( |
| 53 | + |
| 54 | + "cache-control: no-cache", |
| 55 | + |
| 56 | + "content-type: application/json" |
| 57 | + |
| 58 | + ), |
| 59 | + |
| 60 | + )); |
| 61 | + |
| 62 | + |
| 63 | + $response = curl_exec($curl); |
| 64 | + |
| 65 | + $err = curl_error($curl); |
| 66 | + |
| 67 | + $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
| 68 | + |
| 69 | + curl_close($curl); |
| 70 | + |
| 71 | + if ($err) { |
| 72 | + echo $err; |
| 73 | + } |
| 74 | + else |
| 75 | + { |
| 76 | + $api_response = json_decode ($response, true); // Getting Response from bKash API. |
| 77 | + |
| 78 | + //print_r($response); // For Getting all Response Data. |
| 79 | + |
| 80 | +// Assign Transaction Information |
| 81 | + |
| 82 | + $transaction_status = $api_response['transaction']['trxStatus']; // Transaction Status Codes. |
| 83 | + |
| 84 | + $transaction_amount = $api_response['transaction']['amount']; // bKash Payment Amount. |
| 85 | + |
| 86 | + $transaction_reference = $api_response['transaction']['reference']; // bKash Reference for Invoice ID. |
| 87 | + |
| 88 | + $transaction_time = $api_response['transaction']['trxTimestamp']; // bKash Transaction Time & Date. |
| 89 | + |
| 90 | + |
| 91 | +// Return Transaction Information into Your Blade Template. |
| 92 | + |
| 93 | + return view('transaction.bkash', compact('transaction_status', 'transaction_amount', 'transaction_reference', 'transaction_time')); |
| 94 | + |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | +// # # # # View # # # # // Laravel Blade File |
| 101 | + |
| 102 | + <div class="panel"> |
| 103 | + <div class="panel-heading"> |
| 104 | + <h3 class="panel-title">bKash Payment Confirmation</h3> |
| 105 | + </div> |
| 106 | + |
| 107 | + <div class="panel-body"> |
| 108 | + |
| 109 | + @php |
| 110 | + |
| 111 | + if($transaction_status == '0000'){ |
| 112 | + echo "<div class='alert alert-success'>Transaction Successful. trxID is valid and transaction is successful.</div>"; |
| 113 | + } |
| 114 | + |
| 115 | + elseif($transaction_status == '0010'){ |
| 116 | + echo "<div class='alert alert-warning'>Transaction Pending... trxID is valid but transaction is in pending state.</div>"; |
| 117 | + } |
| 118 | + |
| 119 | + elseif($transaction_status == '0011'){ |
| 120 | + echo "<div class='alert alert-warning'>Transaction Pending... trxID is valid but transaction is in pending state.</div>"; |
| 121 | + } |
| 122 | + |
| 123 | + elseif($transaction_status == '0100'){ |
| 124 | + echo "<div class='alert alert-danger'>Transaction Reversed ! trxID is valid but transaction has been reversed.</div>"; |
| 125 | + } |
| 126 | + |
| 127 | + elseif($transaction_status == '0111'){ |
| 128 | + echo "<div class='alert alert-danger'>Transaction Failure ! trxID is valid but transaction has failed.</div>"; |
| 129 | + } |
| 130 | + |
| 131 | + elseif($transaction_status == '1001'){ |
| 132 | + echo "<div class='alert alert-danger'>Format Error ! Invalid MSISDN input. Try with correct mobile no.</div>"; |
| 133 | + } |
| 134 | + |
| 135 | + elseif($transaction_status == '1002'){ |
| 136 | + echo "<div class='alert alert-danger'>Invalid Reference ! Invalid trxID, it does not exist.</div>"; |
| 137 | + } |
| 138 | + |
| 139 | + elseif($transaction_status == '1003'){ |
| 140 | + echo "<div class='alert alert-danger'>Authorization Error ! Access denied. Username or Password is incorrect.</div>"; |
| 141 | + } |
| 142 | + |
| 143 | + elseif($transaction_status == '1004'){ |
| 144 | + echo "<div class='alert alert-danger'>Authorization Error ! Access denied. trxID is not related to this username.</div>"; |
| 145 | + } |
| 146 | + |
| 147 | + elseif($transaction_status == '9999'){ |
| 148 | + echo "<div class='alert alert-danger'>System Error ! Could not process request.</div>"; |
| 149 | + } |
| 150 | + |
| 151 | + else{ |
| 152 | + echo "<div class='alert alert-danger'>Unknown ERROR !</div>"; |
| 153 | + } |
| 154 | + |
| 155 | + @endphp |
| 156 | + |
| 157 | + // Print Transaction Information |
| 158 | + |
| 159 | + <b>Amount :</b> {{ $transaction_amount }} <br><br> |
| 160 | + |
| 161 | + <b>Reference :</b> {{ $transaction_reference }} <br><br> |
| 162 | + |
| 163 | + <b>Time :</b> {{ $transaction_time }} <br><br><br> |
| 164 | + |
| 165 | + // Invoice Generate |
| 166 | + |
| 167 | + <a href="{{ url('get-invoice') }}" class="btn btn-primary">{{ 'Click Here to Get Invoice' }}</a> |
| 168 | + </div> |
| 169 | + </div> |
| 170 | +?> |
0 commit comments