-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaynow-qr.php
More file actions
84 lines (79 loc) · 2.22 KB
/
paynow-qr.php
File metadata and controls
84 lines (79 loc) · 2.22 KB
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
<?php
require_once("rapyd_utils.php");
require_once("dbcontroller.php");
$db_handle = new DBController();
if(!empty($_GET["action"])) {
switch($_GET["action"]) {
case "showqr":
if(!empty($_POST["quantity"])) {
$body = [
"amount" => $_POST["quantity"],
"currency" => "SGD",
"payment_method" => [
"type"=> "sg_paynow_bank"
]
];
try {
$object = make_request('post', '/v1/payments', $body);
$_SESSION['qr'] = $object['data']['visual_codes']['PayNow QR'];
$_SESSION['payment_id'] = $object['data']['id'];
$_SESSION['param_two'] = $object['data']['original_amount'];
} catch (Exception $e) {
echo "Error: $e";
}
}
break;
case 'complete-payment':
$body = [
"token" => $_POST["payment_id"],
"param2" => $_POST["param_two"]
];
try {
$object = make_request('post', '/v1/payments/completePayment', $body);
$_SESSION['status'] = $object['status']['status'];
} catch (Exception $e) {
echo "Error: $e";
}
break;
}
}
?>
<html>
<head>
<title>Simple PHP Shopping Cart</title>
<link href="style.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div class="product-item">
<form method="post" action="paynow-qr.php?action=showqr">
<div class="product-tile-footer">
<div class="product-title">Enter amount to generate PayNow QR</div>
<div class="cart-action" style="float: none;"><input type="number" class="product-quantity" name="quantity" value="1" size="8" /><input type="submit" value="Generate QR" class="btnAddAction" /></div>
</div>
</form>
<?php
if(isset($_SESSION["qr"])){
?>
<div id="show-qr" style="text-align: center;">
<img src="<?php echo $_SESSION["qr"]; ?>" />
<form method="post" action="paynow-qr.php?action=complete-payment">
<input type="hidden" name="payment_id" value="<?php echo $_SESSION["payment_id"]; ?>"/>
<input type="hidden" name="param_two" value="<?php echo $_SESSION["param_two"]; ?>"/>
<div class="product-tile-footer">
<input type="submit" value="Complete Payment" class="btnAddAction" />
</div>
</form>
</div>
<?php
}
?>
<?php
if(isset($_SESSION["status"])){
?>
<div id="status" class="product-tile-footer">Payment completion : <?php echo $_SESSION["status"]; ?></div>
<?php
}
?>
</div>
</body>
</html>