forked from razorpay/razorpay-gravity-forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
67 lines (50 loc) · 1.71 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
60
61
62
63
64
65
66
67
function invokeRZP() {
var data = razorpay_script_vars.data;
var setDisabled = function(id, state) {
if (typeof state === 'undefined') {
state = true;
}
var elem = document.getElementById(id);
if (state === false) {
elem.removeAttribute('disabled');
} else {
elem.setAttribute('disabled', state);
}
};
// Payment was closed without handler getting called
data.modal = {
ondismiss: function() {
setDisabled('btn-razorpay', false);
document.getElementById('razorpayform').action = '';
document.razorpayform.submit();
}
};
data.handler = function(payment) {
setDisabled('btn-razorpay-cancel');
var successMsg = document.getElementById('msg-razorpay-success');
successMsg.style.display = 'block';
document.getElementById('razorpay_payment_id').value =
payment.razorpay_payment_id;
document.getElementById('razorpay_signature').value =
payment.razorpay_signature;
document.razorpayform.submit();
};
var razorpayCheckout = new Razorpay(data);
// global method
function openCheckout() {
// Disable the pay button
setDisabled('btn-razorpay');
razorpayCheckout.open();
}
function addEvent(element, evnt, funct) {
if (element.attachEvent) {
return element.attachEvent('on' + evnt, funct);
} else {
return element.addEventListener(evnt, funct, false);
}
}
// Attach event listener
addEvent(document.getElementById('btn-razorpay'), 'click', openCheckout);
setTimeout(openCheckout);
}
invokeRZP();