1
0
Fork 0
forked from OpenNeo/impress
impress/app/assets/javascripts/static/donate.js

33 lines
911 B
JavaScript
Raw Normal View History

(function() {
var donationForm = document.getElementById('donation-form');
2014-09-09 19:06:38 -07:00
var amountField = donationForm.querySelector(
'[name=donation\\[amount\\]]');
var tokenField = donationForm.querySelector(
'[name=donation\\[stripe_token\\]]');
var checkout = StripeCheckout.configure({
2014-09-09 19:06:38 -07:00
key: donationForm.getAttribute('data-checkout-publishable-key'),
image: donationForm.getAttribute('data-checkout-image'),
token: function(token) {
tokenField.value = token.id;
donationForm.submit();
}
});
donationForm.addEventListener('submit', function(e) {
if (!tokenField.value) {
e.preventDefault();
var amount = Math.floor(parseFloat(amountField.value) * 100);
if (!isNaN(amount)) {
checkout.open({
name: 'Dress to Impress',
description: 'Donation (thank you!)',
amount: amount
});
}
}
});
})();