-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Uses wp_enqueue_script and wp_localize_script
- Loading branch information
Nemo
committed
Jun 5, 2017
1 parent
5fc6148
commit d15c95a
Showing
2 changed files
with
72 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
(function() { | ||
var data = razorpay_wc_checkout_vars; | ||
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(); | ||
}; | ||
|
||
console.log(data); | ||
|
||
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 | ||
window.onload = function() { | ||
addEvent(document.getElementById('btn-razorpay'), 'click', openCheckout); | ||
openCheckout(); | ||
}; | ||
})(); |