forked from OpenNeo/impress
36 lines
1,002 B
JavaScript
36 lines
1,002 B
JavaScript
(function() {
|
|
var donationForm = document.getElementById('donation-form');
|
|
|
|
function field(name) {
|
|
return donationForm.querySelector(
|
|
'input[name=donation\\[' + name + '\\]]');
|
|
}
|
|
|
|
var checkout = StripeCheckout.configure({
|
|
key: donationForm.getAttribute('data-checkout-publishable-key'),
|
|
image: donationForm.getAttribute('data-checkout-image'),
|
|
token: function(token) {
|
|
field('stripe_token').value = token.id;
|
|
field('stripe_token_type').value = token.type;
|
|
field('donor_email').value = token.email;
|
|
donationForm.submit();
|
|
},
|
|
bitcoin: true
|
|
});
|
|
|
|
donationForm.addEventListener('submit', function(e) {
|
|
if (!field('stripe_token').value) {
|
|
e.preventDefault();
|
|
|
|
var amount = Math.floor(parseFloat(field('amount').value) * 100);
|
|
|
|
if (!isNaN(amount)) {
|
|
checkout.open({
|
|
name: 'Dress to Impress',
|
|
description: 'Donation (thank you!)',
|
|
amount: amount
|
|
});
|
|
}
|
|
}
|
|
});
|
|
})();
|