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