-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
110 lines (94 loc) · 3.58 KB
/
index.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
<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Define configuration variables
$createURL = "https://checkout.pay.bka.sh/v1.2.0-beta/checkout/payment/create";
$executeURL = "https://checkout.pay.bka.sh/v1.2.0-beta/checkout/payment/execute/";
$tokenURL = "https://checkout.pay.bka.sh/v1.2.0-beta/checkout/token/grant";
$scriptURL = "https://scripts.pay.bka.sh/versions/1.2.0-beta/checkout/bKash-checkout.js";
$proxy = "";
$app_key = "";
$app_secret = "";
$username = "";
$password = "";
$intent = "sale";
// Function to get bKash token
function bkash_Get_Token() {
global $tokenURL, $app_key, $app_secret, $username, $password, $proxy;
$post_token = array(
'app_key' => $app_key,
'app_secret' => $app_secret
);
$url = curl_init($tokenURL);
$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);
if (!empty($proxy)) {
curl_setopt($url, CURLOPT_PROXY, $proxy);
}
$resultdata = curl_exec($url);
curl_close($url);
return json_decode($resultdata, true);
}
// Generate token and store it in session and config file
$request_token = bkash_Get_Token();
$idtoken = $request_token['id_token'];
$_SESSION['token'] = $idtoken;
// Create payment
if(isset($_GET['createpayment'])) {
global $createURL, $app_key, $proxy, $intent;
$amount = $_GET['amount'];
$invoice = $_GET['invoice'];
$createpaybody = array('amount' => $amount, 'currency' => 'BDT', 'merchantInvoiceNumber' => $invoice, 'intent' => $intent);
$url = curl_init($createURL);
$createpaybodyx = json_encode($createpaybody);
$header = array(
'Content-Type:application/json',
'authorization:'.$idtoken,
'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);
if (!empty($proxy)) {
curl_setopt($url, CURLOPT_PROXY, $proxy);
}
$resultdata = curl_exec($url);
curl_close($url);
echo $resultdata;
exit;
}
// Execute payment
if(isset($_GET['executepayment'])) {
global $executeURL, $app_key, $proxy;
$paymentID = $_GET['paymentID'];
$url = curl_init($executeURL . $paymentID);
$header = array(
'Content-Type:application/json',
'authorization:'.$idtoken,
'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);
if (!empty($proxy)) {
curl_setopt($url, CURLOPT_PROXY, $proxy);
}
$resultdatax = curl_exec($url);
curl_close($url);
echo $resultdatax;
exit;
}
}
?>