-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreatepayment.php
49 lines (32 loc) · 1.05 KB
/
createpayment.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
<?php
use Sadiq\BkashMerchantAPI\BkashMerchantAPI;
use Sadiq\BkashMerchantAPI\Exception\BkashMerchantAPIException;
require_once __DIR__ . '/config.php';
session_start();
// token genarate & refresh
require_once __DIR__. '/token.php';
header('Content-Type: application/json');
$requires = [
'amount', 'ref'
];
foreach ($requires as $req) {
if (empty($_POST[$req])) {
exit(json_encode(['message' => $req.' is missing']));
}
}
$token = $_SESSION['token'];
$amount = $_POST['amount'];
$invoice = strtoupper(uniqid());
$_SESSION['invoice'] = $invoice;
$reference = strlen($_POST['ref']) > 50 ? substr($_POST['ref'], 0, 50) : $_POST['ref'];
try {
$bkash = new BkashMerchantAPI;
$bkash->setGrantToken($token);
if ($resp = $bkash->createPayment($amount, $invoice, $reference)) {
// log create payment resp
prependFileLog(log_file, "\n\n- Create Payment\n{$resp->getResponse()}\n\n");
$bkash->redirectToPayment($resp);
}
} catch (BkashMerchantAPIException $e) {
die ($e->getMessage());
}