diff --git a/app/assets/javascripts/static/donate.js b/app/assets/javascripts/static/donate.js new file mode 100644 index 00000000..66abc8f7 --- /dev/null +++ b/app/assets/javascripts/static/donate.js @@ -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 + }); + } + } + }); +})(); diff --git a/app/helpers/static_helper.rb b/app/helpers/static_helper.rb index 91476a7c..8cfc9af4 100644 --- a/app/helpers/static_helper.rb +++ b/app/helpers/static_helper.rb @@ -1,22 +1,2 @@ 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 - diff --git a/app/views/static/donate.html.haml b/app/views/static/donate.html.haml index dc6b93c9..30a8822a 100644 --- a/app/views/static/donate.html.haml +++ b/app/views/static/donate.html.haml @@ -6,7 +6,8 @@ %span.campaign-raised 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 %p#donation-form-title Thanks for supporting Dress to Impress! @@ -14,7 +15,7 @@ All donations go directly to our hosting costs. Thanks for your help! %div = precede '$' do - = pledgie_amount_field_tag('10.00') + = text_field_tag 'amount', '10.00' %button{:type => 'submit'} Donate now! #description @@ -104,3 +105,7 @@ in order to better handle bad-faith donors and unexpected circumstances.** Huh. That was way simpler. 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'