forked from razorpay/razorpay-woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
61 lines (55 loc) · 1.79 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
(function() {
var data = razorpay_wc_checkout_vars;
if(data === 'checkoutForm') {
document.getElementById("checkoutForm").submit();
} else {
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);
},
};
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);
}
if (document.readyState === 'complete') {
addEvent(document.getElementById('btn-razorpay'), 'click', openCheckout);
openCheckout();
} else {
document.addEventListener('DOMContentLoaded', function() {
addEvent(document.getElementById('btn-razorpay'), 'click', openCheckout);
openCheckout();
});
}
}
})();