From 6f605e4a91f73317fe8008916aaa88038bdcfdc8 Mon Sep 17 00:00:00 2001 From: Rob Wright Date: Fri, 26 Feb 2021 11:39:45 -0500 Subject: [PATCH 1/3] Update to 2.3.5 --- .ruby-version | 1 + Gemfile | 4 ++-- Gemfile.lock | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 .ruby-version 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..b05b035 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -181,7 +181,7 @@ DEPENDENCIES tux RUBY VERSION - ruby 2.2.1p85 + ruby 2.3.5p376 BUNDLED WITH - 1.15.0 + 2.2.9 From 8e011f4fdc07f5f52b4e0ea249045cd7654d524f Mon Sep 17 00:00:00 2001 From: Rob Wright Date: Tue, 30 Mar 2021 21:25:53 -0400 Subject: [PATCH 2/3] progress with Stripe Checkout --- Gemfile.lock | 19 ++-------- app.rb | 25 +++++++++++++ views/index.erb | 94 ++++++++++++++++++++++++++++++++---------------- views/layout.erb | 3 +- 4 files changed, 93 insertions(+), 48 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index b05b035..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 diff --git a/app.rb b/app.rb index 91b0552..a577d60 100644 --- a/app.rb +++ b/app.rb @@ -52,6 +52,31 @@ def markpaid(amount) erb :goal end +post '/checkout' do + @donation = Donation.get(params[:donation_id]) + donation = @donation + + session = Stripe::Checkout::Session.create({ + payment_method_types: ['card'], + line_items: [{ + price_data: { + currency: 'usd', + product_data: { + name: 'Grow NCS', + }, + unit_amount: 2000, + }, + quantity: 1, + }], + mode: 'payment', + # These placeholder URLs will be replaced in a following step. + success_url: 'http://grow-ncs.test:4567/thanks', + cancel_url: 'http://grow-ncs.test:4567/', + }) + + { id: session.id }.to_json +end + post '/charge' do @donation = Donation.get(params[:donation_id]) donation = @donation diff --git a/views/index.erb b/views/index.erb index f19c0a2..ce57710 100644 --- a/views/index.erb +++ b/views/index.erb @@ -18,9 +18,7 @@ <% else %>
-
- -
+
<% end %> @@ -37,33 +35,69 @@ - - handler.open(); - }); - + # 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 @@ - - + From cc2f23d6b5cd4cfc33081fe0b7270537c1f30d93 Mon Sep 17 00:00:00 2001 From: Rob Wright Date: Mon, 5 Apr 2021 20:20:08 -0400 Subject: [PATCH 3/3] working with Stripe Checkout --- app.rb | 138 +++++++++++++++++++++--------------------------- views/index.erb | 42 ++------------- 2 files changed, 62 insertions(+), 118 deletions(-) diff --git a/app.rb b/app.rb index a577d60..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') @@ -56,7 +107,7 @@ def markpaid(amount) @donation = Donation.get(params[:donation_id]) donation = @donation - session = Stripe::Checkout::Session.create({ + stripe_session = Stripe::Checkout::Session.create({ payment_method_types: ['card'], line_items: [{ price_data: { @@ -64,90 +115,18 @@ def markpaid(amount) product_data: { name: 'Grow NCS', }, - unit_amount: 2000, + unit_amount: @donation.amount*100, }, quantity: 1, }], mode: 'payment', - # These placeholder URLs will be replaced in a following step. - success_url: 'http://grow-ncs.test:4567/thanks', - cancel_url: 'http://grow-ncs.test:4567/', + success_url: settings.success_url, # /thanks + cancel_url: settings.cancel_url # / }) - { id: session.id }.to_json -end - -post '/charge' 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 + session[:donation_id] = @donation.id - halt 200 + { id: stripe_session.id }.to_json end get '/thanks' do @@ -156,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 ce57710..34e18c8 100644 --- a/views/index.erb +++ b/views/index.erb @@ -18,7 +18,7 @@ <% else %>
- +
<% end %> @@ -40,11 +40,8 @@ var donationButtons = document.getElementsByClassName("donation-button"); for(var i = 0; i < donationButtons.length; i++) { - var button = donationButtons[i]; - var url = `/checkout?donation_id=${button.dataset.id}`; - console.log("url = " + url); - - button.addEventListener('click', function() { + donationButtons[i].addEventListener('click', function() { + var url = `/checkout?donation_id=${this.dataset.id}`; fetch(url, { method: 'POST' }) @@ -68,36 +65,3 @@ }); } - - #