-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaymentProcess.php
More file actions
96 lines (71 loc) · 2.15 KB
/
paymentProcess.php
File metadata and controls
96 lines (71 loc) · 2.15 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
85
86
87
88
89
90
91
92
93
94
95
96
<?php
include "connection.php";
session_start();
$user = $_SESSION["u"];
$stockList = array();
$qtyList = array();
if (isset($_POST["cart"]) && $_POST["cart"] == "true") {
//From Cart
$rs = Database::search("SELECT * FROM `cart` WHERE `user_email`='".$user["email"]."'");
$num = $rs->num_rows;
for ($i=0; $i < $num; $i++) {
$d = $rs->fetch_assoc();
$stockList[] = $d["stock_stock_id"];
$qtyList[] = $d["cart_qty"];
}
} else {
//From Buy Now
$stockList[] = $_POST["stockId"];
$qtyList[] = $_POST["qty"];
}
$merchantId = "1226990";
$merchantSecret = "MjIyMzI5NDE3OTIzODk1MTU1MDUyNzE0MDM5NzMyMTMxMzAxNTQ0NQ==";
$items = "";
$netTotal = 0;
$currency = "LKR";
$orderId = uniqid();
for ($i=0; $i < sizeof($stockList); $i++) {
$rs2 = Database::search("SELECT * FROM `stock` INNER JOIN `product` ON `stock`.`product_id`=`product`.`id`
WHERE `stock`.`stock_id`='".$stockList[$i]."'");
$d2 = $rs2->fetch_assoc();
$stockQty = $d2["qty"];
if ($stockQty >= $qtyList[$i]) {
$items .= $d2["name"];
if ($i != sizeof($stockList) - 1) {
$items .= ", ";
}
$netTotal += (intval($d2["price"]) * intval($qtyList[$i]));
} else {
echo("Product has no available stock.");
}
}
$netTotal += 219;
$hash = strtoupper(
md5(
$merchantId .
$orderId .
number_format($netTotal, 2, '.', '') .
$currency .
strtoupper(md5($merchantSecret))
)
);
$payment = array();
$payment["sandbox"] = true;
$payment["merchant_id"] = $merchantId;
$payment["first_name"] = $user["fname"];
$payment["last_name"] = $user["lname"];
$payment["email"] = $user["email"];
$payment["phone"] = $user["mobile"];
$payment["address"] = $user["add_line1"];
$payment["city"] = $user["add_line2"];
$payment["country"] = "Sri Lanka";
$payment["order_id"] = $orderId;
$payment["items"] = $items;
$payment["currency"] = $currency;
$payment["amount"] = number_format($netTotal, 2, '.', '');
$payment["hash"] = $hash;
$payment["return_url"] = "";
$payment["cancel_url"] = "";
$payment["notify_url"] = "";
echo json_encode($payment);
?>