impress/app/assets/javascripts/static/donate.js

37 lines
1,002 B
JavaScript
Raw Normal View History

(function() {
var donationForm = document.getElementById('donation-form');
2014-12-23 20:22:15 -08:00
function field(name) {
return donationForm.querySelector(
'input[name=donation\\[' + name + '\\]]');
}
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) {
2014-12-23 20:22:15 -08:00
field('stripe_token').value = token.id;
field('stripe_token_type').value = token.type;
field('donor_email').value = token.email;
donationForm.submit();
2014-12-23 20:22:15 -08:00
},
bitcoin: true
});
donationForm.addEventListener('submit', function(e) {
2014-12-23 20:22:15 -08:00
if (!field('stripe_token').value) {
e.preventDefault();
2014-12-23 20:22:15 -08:00
var amount = Math.floor(parseFloat(field('amount').value) * 100);
if (!isNaN(amount)) {
checkout.open({
name: 'Dress to Impress',
description: 'Donation (thank you!)',
amount: amount
});
}
}
});
})();