diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..cc6c9a4 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.3.5 diff --git a/Gemfile b/Gemfile index 4d6061f..07b7806 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -ruby '2.2.1' +ruby '2.3.5' gem 'sinatra' gem 'stripe' @@ -13,4 +13,4 @@ group :development do gem 'shotgun' gem 'tux' gem 'pry' -end \ No newline at end of file +end diff --git a/Gemfile.lock b/Gemfile.lock index d8dd0a8..21097c6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -76,16 +76,12 @@ GEM dm-core (~> 1.2.0) do_postgres (0.10.17) data_objects (= 0.10.17) - domain_name (0.5.20161021) - unf (>= 0.0.5, < 1.0.0) dotenv (2.1.1) dotenv-rails (2.1.1) dotenv (= 2.1.1) railties (>= 4.0, < 5.1) erubis (2.7.0) fastercsv (1.5.5) - http-cookie (1.0.3) - domain_name (~> 0.5) i18n (0.7.0) json (1.8.3) json_pure (1.8.3) @@ -94,13 +90,12 @@ GEM mail (2.6.4) mime-types (>= 1.16, < 4) method_source (0.8.2) - mime-types (3.1) + mime-types (3.3.1) mime-types-data (~> 3.2015) - mime-types-data (3.2016.0521) + mime-types-data (3.2021.0225) mini_portile2 (2.1.0) minitest (5.9.1) multi_json (1.12.1) - netrc (0.11.0) nokogiri (1.6.8.1) mini_portile2 (~> 2.1.0) pg (0.19.0) @@ -128,10 +123,6 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (11.3.0) - rest-client (2.0.0) - http-cookie (>= 1.0.2, < 2.0) - mime-types (>= 1.16, < 4.0) - netrc (~> 0.8) ripl (0.7.1) bond (~> 0.5.1) ripl-multi_line (0.3.1) @@ -148,8 +139,7 @@ GEM tilt (>= 1.3, < 3) slop (3.6.0) stringex (1.5.1) - stripe (1.56.0) - rest-client (>= 1.4, < 4.0) + stripe (5.30.0) thor (0.19.1) thread_safe (0.3.5) tilt (2.0.5) @@ -160,9 +150,6 @@ GEM sinatra (>= 1.2.1) tzinfo (1.2.2) thread_safe (~> 0.1) - unf (0.1.4) - unf_ext - unf_ext (0.0.7.2) uuidtools (2.1.5) PLATFORMS @@ -181,7 +168,7 @@ DEPENDENCIES tux RUBY VERSION - ruby 2.2.1p85 + ruby 2.3.5p376 BUNDLED WITH - 1.15.0 + 2.2.9 diff --git a/app.rb b/app.rb index 91b0552..d7d77c9 100644 --- a/app.rb +++ b/app.rb @@ -12,6 +12,8 @@ set :publishable_key, ENV['PUBLISHABLE_KEY'] set :secret_key, ENV['SECRET_KEY'] +set :success_url, ENV['SUCCESS_URL'] +set :cancel_url, ENV['CANCEL_URL'] enable :sessions Stripe.api_key = settings.secret_key @@ -33,6 +35,55 @@ def markpaid(amount) pay.save end +def send_thanks + mail = Mail.deliver do + + # fix this... need to get the customer.email + to customer.email + from 'Ryan McCrary ' + subject 'Grow NCS!' + text_part do + body "Thank you so much for participating in GOAT Christmas! We're constantly amazed at the generosity of each of you who make GOAT possible for the kids that we serve. + + We hope you'll share this with your friends and family and help us finish this fundraiser out before the end of the year. + + As a way of saying thanks, we'd love for you to pick out something you like in the GOAT shop (http://goattrips.org/shop) and use the coupon 2017christmas so we can send it free. Don't feel bad about it - we actually pay our GOAT students to help ship orders, so you're helping them out by ordering free stuff! + + You'll also recieve a tax receipt first thing next year! + + Thanks again so much, and please let us know if you have any questions about GOAT or GOAT Christmas! + + Merry Christmas! + + Ryan & The GOAT Team + + PS - You can keep up with the progress at http://www.goatchristmas.com/goal + + + " + end + html_part do + content_type 'text/html; charset=UTF-8' + body "

Thank you so much for participating in GOAT Christmas! We're constantly amazed at the generosity of each of you who make GOAT possible for the kids that we serve.

+ +

We hope you'll share this with your friends and family and help us finish this fundraiser out before the end of the year.

+ +

As a way of saying thanks, we'd love for you to pick out something you like in the GOAT shop (http://goattrips.org/shop) and use the coupon 2017christmas so we can send it free. Don't feel bad about it - we actually pay our GOAT students to help ship orders, so you're helping them out by ordering free stuff!

+ +

We'll also be sending you a small thank you in the following weeks, so keep an eye on your mailbox. You'll also recieve a tax receipt first thing next year!

+ +

Thanks again so much, and please let us know if you have any questions about GOAT or GOAT Christmas!

+ +

Merry Christmas!

+ +

Ryan & The GOAT Team

+ +

PS - You can keep up with the progress at http://www.goatchristmas.com/goal




" + end + end +end + + get '/' do @donations = Donation.all @done = Donation.all(:paid => 'true') @@ -52,77 +103,30 @@ def markpaid(amount) erb :goal end -post '/charge' do +post '/checkout' do @donation = Donation.get(params[:donation_id]) donation = @donation - customer = Stripe::Customer.create( - email: params[:email], - card: params[:token_id] - ) - - begin - Stripe::Charge.create( - amount: @donation.amount*100, - description: "200 Donors", - currency: 'usd', - customer: customer.id - ) - - @donation.update(paid: 'true') - session[:id] = @donation.id - rescue Stripe::CardError => e - body = e.json_body - session[:error] = body[:error][:message] - halt 500 - end - - mail = Mail.deliver do - - to customer.email - from 'Ryan McCrary ' - subject 'GOAT Christmas!' - text_part do - body "Thank you so much for participating in GOAT Christmas! We're constantly amazed at the generosity of each of you who make GOAT possible for the kids that we serve. - - We hope you'll share this with your friends and family and help us finish this fundraiser out before the end of the year. - - As a way of saying thanks, we'd love for you to pick out something you like in the GOAT shop (http://goattrips.org/shop) and use the coupon 2017christmas so we can send it free. Don't feel bad about it - we actually pay our GOAT students to help ship orders, so you're helping them out by ordering free stuff! - - You'll also recieve a tax receipt first thing next year! - - Thanks again so much, and please let us know if you have any questions about GOAT or GOAT Christmas! - - Merry Christmas! - - Ryan & The GOAT Team - - PS - You can keep up with the progress at http://www.goatchristmas.com/goal - - - " - end - html_part do - content_type 'text/html; charset=UTF-8' - body "

Thank you so much for participating in GOAT Christmas! We're constantly amazed at the generosity of each of you who make GOAT possible for the kids that we serve.

- -

We hope you'll share this with your friends and family and help us finish this fundraiser out before the end of the year.

- -

As a way of saying thanks, we'd love for you to pick out something you like in the GOAT shop (http://goattrips.org/shop) and use the coupon 2017christmas so we can send it free. Don't feel bad about it - we actually pay our GOAT students to help ship orders, so you're helping them out by ordering free stuff!

- -

We'll also be sending you a small thank you in the following weeks, so keep an eye on your mailbox. You'll also recieve a tax receipt first thing next year!

- -

Thanks again so much, and please let us know if you have any questions about GOAT or GOAT Christmas!

- -

Merry Christmas!

- -

Ryan & The GOAT Team

- -

PS - You can keep up with the progress at http://www.goatchristmas.com/goal




" - end - end - - halt 200 + stripe_session = Stripe::Checkout::Session.create({ + payment_method_types: ['card'], + line_items: [{ + price_data: { + currency: 'usd', + product_data: { + name: 'Grow NCS', + }, + unit_amount: @donation.amount*100, + }, + quantity: 1, + }], + mode: 'payment', + success_url: settings.success_url, # /thanks + cancel_url: settings.cancel_url # / + }) + + session[:donation_id] = @donation.id + + { id: stripe_session.id }.to_json end get '/thanks' do @@ -131,7 +135,8 @@ def markpaid(amount) halt erb(:thanks) end - @donation = Donation.get(session[:id]) + @donation = Donation.get(session[:donation_id]) + @donation.update(paid: 'true') paid_donations = Donation.all(paid: 'true') @total = 0 diff --git a/views/index.erb b/views/index.erb index f19c0a2..34e18c8 100644 --- a/views/index.erb +++ b/views/index.erb @@ -18,9 +18,7 @@ <% else %>
-
- -
+
<% end %> @@ -37,33 +35,33 @@ - + }); + } + diff --git a/views/layout.erb b/views/layout.erb index b7891a0..6f30df7 100644 --- a/views/layout.erb +++ b/views/layout.erb @@ -5,8 +5,7 @@ - - +