-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
59 lines (53 loc) · 2 KB
/
script.js
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
function paymentGateWay(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
alert(xhttp.responseText);
JSON.parse(xhttp.responseText);
var obj = JSON.parse(xhttp.responseText);
// Payment completed. It can be a successful failure.
payhere.onCompleted = function onCompleted(orderId) {
console.log("Payment completed. OrderID:" + orderId);
// Note: validate the payment and show success or failure page to the customer
};
// Payment window closed
payhere.onDismissed = function onDismissed() {
// Note: Prompt user to pay again or show an error page
console.log("Payment dismissed");
};
// Error occurred
payhere.onError = function onError(error) {
// Note: show an error page
console.log("Error:" + error);
};
// Put the payment variables here
var payment = {
"sandbox": true,
"merchant_id": "1223171", // Replace your Merchant ID
"return_url": "http://localhost/payhere/", // Important
"cancel_url": "http://localhost/payhere/", // Important
"notify_url": "http://sample.com/notify",
"order_id": obj["order_id"],
"items": obj["items"],
"amount": obj["amount"],
"currency": obj["currency"],
"hash": obj["hash"], // *Replace with generated hash retrieved from backend
"first_name": obj["first_name"],
"last_name": obj["last_name"],
"email": obj["email"],
"phone": obj["phone"],
"address": obj["address"],
"city": obj["city"],
"country": "Sri Lanka",
"delivery_address": "No. 46, Galle road, Kalutara South",
"delivery_city": "Kalutara",
"delivery_country": "Sri Lanka",
"custom_1": "",
"custom_2": ""
};
payhere.startPayment(payment);
}
}
xhttp.open("GET", "payherprocess.php", true);
xhttp.send();
}