Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.3.5
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source 'https://rubygems.org'
ruby '2.2.1'
ruby '2.3.5'

gem 'sinatra'
gem 'stripe'
Expand All @@ -13,4 +13,4 @@ group :development do
gem 'shotgun'
gem 'tux'
gem 'pry'
end
end
23 changes: 5 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -181,7 +168,7 @@ DEPENDENCIES
tux

RUBY VERSION
ruby 2.2.1p85
ruby 2.3.5p376

BUNDLED WITH
1.15.0
2.2.9
143 changes: 74 additions & 69 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <ryan@goattrips.org>'
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 "<p>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.</p>

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

<p>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 <b>2017christmas</b> 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!</p>

<p>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!</p>

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

<p>Merry Christmas!</p>

<p>Ryan & The GOAT Team</p>

<p>PS - You can keep up with the progress at http://www.goatchristmas.com/goal</p><br /><br /><br />"
end
end
end


get '/' do
@donations = Donation.all
@done = Donation.all(:paid => 'true')
Expand All @@ -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 <ryan@goattrips.org>'
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 "<p>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.</p>

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

<p>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 <b>2017christmas</b> 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!</p>

<p>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!</p>

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

<p>Merry Christmas!</p>

<p>Ryan & The GOAT Team</p>

<p>PS - You can keep up with the progress at http://www.goatchristmas.com/goal</p><br /><br /><br />"
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
Expand All @@ -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
Expand Down
60 changes: 29 additions & 31 deletions views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
<% else %>
<div class="giftbox">
<div class="vertical-aligned">
<form action="/charge" method="post">
<button type="submit" class="donation-button" style="visibility: visible;" data-amount="<%= donation.amount*100 %>" data-id="<%= donation.id %>">$<%= donation.amount %></button>
</form>
<button id="donation-button-<%= donation.id %>" class="donation-button" style="visibility: visible;" data-amount="<%= donation.amount*100 %>" data-id="<%= donation.id %>">$<%= donation.amount %></button>
</div>
</div>
<% end %>
Expand All @@ -37,33 +35,33 @@
</div>
</div>

<script>
$('.giftbox').on('click', 'button', function(e) {
e.preventDefault();
$this = $(this);
<script type="text/javascript">
var stripe = Stripe('<%= settings.publishable_key %>');
var donationButtons = document.getElementsByClassName("donation-button");

var handler = StripeCheckout.configure({
key: '<%= settings.publishable_key %>',
name: "Great Outdoor Adventure Trips",
image: 'img/160x160.jpg',
allowRememberMe: 'false',
billingAddress: 'true',
amount: $this.data('amount'),
closed: function() {
},
token: function(token) {
$.post( "/charge", {
token_id: token.id,
donation_id: $this.data('id'),
email: token.email
}).done(function() {
window.location.href = "/thanks";
}).fail(function() {
alert( "Sorry! There was an error processing your donation." );
for(var i = 0; i < donationButtons.length; i++) {
donationButtons[i].addEventListener('click', function() {
var url = `/checkout?donation_id=${this.dataset.id}`;
fetch(url, {
method: 'POST'
})
.then(function(response) {
return response.json();
})
.then(function(session) {
return stripe.redirectToCheckout({ sessionId: session.id });
})
.then(function(result) {
// If `redirectToCheckout` fails due to a browser or network
// error, you should display the localized error message to your
// customer using `error.message`.
if (result.error) {
alert(result.error.message);
}
})
.catch(function(error) {
console.error('Error:', error);
});
}
});

handler.open();
});
</script>
});
}
</script>
3 changes: 1 addition & 2 deletions views/layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel='stylesheet' type='text/css' href='css/main.css'/>
<link rel='icon' type='image/png' href='img/favicon.ico' />
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://checkout.stripe.com/checkout.js"></script>
<script src="https://js.stripe.com/v3/"></script>
<meta property="og:image" content="http://christmas.goattrips.org/img/400x400.jpg" />
<meta property="og:image:secure_url" content="https://christmas.goattrips.org/img/400x400.jpg" />
<meta property="og:description" content="I participated in GOAT Christmas and you should too! If one person gives each of the values below from $1-200 we will raise just over $20,000 to kickstart our programs for 2016. GOAT would never happen without passionate people giving generously to changing lives in Greenville." />
Expand Down