1
0
Fork 0
forked from OpenNeo/impress

stripe checkout; tokens not yet passed anywhere

This commit is contained in:
Emi Matchu 2014-09-09 20:24:27 -05:00
parent 1d7ca7cec2
commit 0afc8ddb2b
3 changed files with 37 additions and 22 deletions

View file

@ -0,0 +1,30 @@
(function() {
var donationForm = document.getElementById('donation-form');
var amountField = donationForm.amount;
var tokenField = donationForm.stripe_token;
var checkout = StripeCheckout.configure({
key: 'pk_test_wEvgn4baD9W5ld5C9JCS9Ahf', // TODO
//image: '/square-image.png', // TODO
token: function(token) {
stripe_token.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
});
}
}
});
})();

View file

@ -1,22 +1,2 @@
module StaticHelper module StaticHelper
def pledgie_amount_label_tag(content)
label_tag 'pledge[amount]', content
end
def pledgie_amount_field_tag(amount)
text_field_tag 'pledge[amount]', amount, :id => 'pledge_amount'
end
def pledgie_confirm_url
"http://pledgie.com/campaigns/#{PLEDGIE_CAMPAIGN_ID}/pledge/confirm"
end
def pledgie_form_tag(*args, &block)
form_tag(pledgie_confirm_url, *args, &block)
end
def pledgie_url
"http://pledgie.com/campaigns/#{PLEDGIE_CAMPAIGN_ID}"
end
end end

View file

@ -6,7 +6,8 @@
%span.campaign-raised %span.campaign-raised
toward our hosting costs this year. Thanks so much! toward our hosting costs this year. Thanks so much!
= pledgie_form_tag id: 'donation-form' do = form_tag 'TODO', id: 'donation-form' do
= hidden_field_tag 'stripe_token'
%header %header
%p#donation-form-title %p#donation-form-title
Thanks for supporting Dress to Impress! Thanks for supporting Dress to Impress!
@ -14,7 +15,7 @@
All donations go directly to our hosting costs. Thanks for your help! All donations go directly to our hosting costs. Thanks for your help!
%div %div
= precede '$' do = precede '$' do
= pledgie_amount_field_tag('10.00') = text_field_tag 'amount', '10.00'
%button{:type => 'submit'} Donate now! %button{:type => 'submit'} Donate now!
#description #description
@ -104,3 +105,7 @@
in order to better handle bad-faith donors and unexpected circumstances.** in order to better handle bad-faith donors and unexpected circumstances.**
Huh. That was way simpler. Huh. That was way simpler.
Maybe I should've just written that in the first place. Maybe I should've just written that in the first place.
- content_for :javascripts do
= javascript_include_tag 'https://checkout.stripe.com/checkout.js',
'static/donate.js'