-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpgResponse.php
146 lines (132 loc) · 5.55 KB
/
pgResponse.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
<html>
<body>
<?php
header("Pragma: no-cache");
header("Cache-Control: no-cache");
header("Expires: 0");
// following files need to be included
require_once("./lib/config_paytm.php");
require_once("./lib/encdec_paytm.php");
$paytmChecksum = "";
$paramList = array();
$isValidChecksum = "FALSE";
$paramList = $_POST;
$paytmChecksum = isset($_POST["CHECKSUMHASH"]) ? $_POST["CHECKSUMHASH"] : ""; //Sent by Paytm pg
//Verify all parameters received from Paytm pg to your application. Like MID received from paytm pg is same as your application�s MID, TXN_AMOUNT and ORDER_ID are same as what was sent by you to Paytm PG for initiating transaction etc.
$isValidChecksum = verifychecksum_e($paramList, PAYTM_MERCHANT_KEY, $paytmChecksum); //will return TRUE or FALSE string.
if($isValidChecksum == "TRUE") {
echo "<b>Checksum matched and following are the transaction details:</b>" . "<br/>";
if ($_POST["STATUS"] == "TXN_SUCCESS") {
echo "<b>Transaction status is success</b>" . "<br/>";
?>
<script src="https://www.gstatic.com/firebasejs/7.6.1/firebase.js"></script>
<script>
var firebaseConfig = {
apiKey: "AIzaSyBw4RVlD1ZdnNNn4ow5hahtxPxBSpL_tpA",
authDomain: "website-e1c2c.firebaseapp.com",
databaseURL: "https://website-e1c2c.firebaseio.com",
projectId: "website-e1c2c",
storageBucket: "website-e1c2c.appspot.com",
messagingSenderId: "640557542653",
appId: "1:640557542653:web:215d1a31f7ace2f72fe294"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
</script>
<script>
function genOrderId() {
return "ORDER" + Math.floor(100000000 + Math.random() * 900000000);
}
firebase.database().ref().child("Users").child(localStorage.getItem("Username")).child("cart").orderByChild("name").on("value", function(snapshot1) {
if(snapshot1.exists())
{
snapshot1.forEach(function(childSnapshot) {
var orderaddress={
address: localStorage.getItem("address"),
phone: localStorage.getItem("phone"),
postalCode: localStorage.getItem("postcode")
};
var today = new Date();
var date = today.getFullYear()+"/"+(today.getMonth()+1)+"/"+today.getDate();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var dateTime = date+" "+time;
var stage1={
date:dateTime,
messege:"Order placed successfully",
orderStatus:"COMPLETED",
orderStatusno:1
};
var stage2={
date:dateTime,
messege:"Order Confirming",
orderStatus:"ACTIVE",
orderStatusno:2
};
var stage3={
date:dateTime,
messege:"Order Shipped",
orderStatus:"INACTIVE",
orderStatusno:3
};
var stage4={
date:dateTime,
messege:"Order out for delivery",
orderStatus:"INACTIVE",
orderStatusno:4
};
var stage5={
date:dateTime,
messege:"Order Successfully Deliverd",
orderStatus:"INACTIVE",
orderStatusno:5
};
var orderstatus={
Stage1:stage1,
Stage2:stage2,
Stage3:stage3,
Stage4:stage4,
Stage5:stage5
};
var order={
ordid:genOrderId(),
orderstatus:orderstatus,
orderaddress:orderaddress,
Delivery:"Pending",
catagory:childSnapshot.val().catagory,
customer:localStorage.getItem("Username"),
image:childSnapshot.val().image,
name:childSnapshot.val().name,
payment:"Done",
price:childSnapshot.val().price,
qty:childSnapshot.val().qty,
totalprice:parseInt(childSnapshot.val().price)*parseInt(childSnapshot.val().qty),
seller:childSnapshot.val().seller
};
firebase.database().ref().child("Users").child(localStorage.getItem("Username")).child("orders").child(order.ordid).set(order);
firebase.database().ref().child("Users").child(order.seller).child("delivery").child(order.ordid).set(order);
});
firebase.database().ref().child("Users").child(localStorage.getItem("Username")).child("cart").remove();
}
});
</script>
<?php
//Process your transaction here as success transaction.
//Verify amount & order id received from Payment gateway with your application's order id and amount.
}
else {
echo "<b>Transaction status is failure</b>" . "<br/>";
}
if (isset($_POST) && count($_POST)>0 )
{
foreach($_POST as $paramName => $paramValue) {
echo "<br/>" . $paramName . " = " . $paramValue;
}
}
}
else {
echo "<b>Checksum mismatched.</b>";
//Process transaction as suspicious.
}
?>
</body>
</html>