Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

Commit 5ce4c5f

Browse files
authored
Merge pull request #18 from stripe/bg-ephemeral-keys
Add support for ephemeral keys
2 parents 2c1187d + 93d42b4 commit 5ce4c5f

File tree

3 files changed

+28
-63
lines changed

3 files changed

+28
-63
lines changed

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
source "https://rubygems.org"
2-
ruby "2.2.7"
2+
ruby "2.3.1"
33
gem 'sinatra', '1.4.7'
4-
gem 'stripe', '1.58.0'
4+
gem 'stripe', '2.12.0'
55
gem 'dotenv', '1.0.2'
66
gem 'json', '1.8.6'
77
gem 'encrypted_cookie', '0.0.4'

Gemfile.lock

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,22 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
domain_name (0.5.20170404)
5-
unf (>= 0.0.5, < 1.0.0)
64
dotenv (1.0.2)
75
encrypted_cookie (0.0.4)
8-
http-cookie (1.0.3)
9-
domain_name (~> 0.5)
6+
faraday (0.12.1)
7+
multipart-post (>= 1.2, < 3)
108
json (1.8.6)
11-
mime-types (3.1)
12-
mime-types-data (~> 3.2015)
13-
mime-types-data (3.2016.0521)
14-
netrc (0.11.0)
9+
multipart-post (2.0.0)
1510
rack (1.6.6)
1611
rack-protection (1.5.3)
1712
rack
18-
rest-client (2.0.2)
19-
http-cookie (>= 1.0.2, < 2.0)
20-
mime-types (>= 1.16, < 4.0)
21-
netrc (~> 0.8)
2213
sinatra (1.4.7)
2314
rack (~> 1.5)
2415
rack-protection (~> 1.4)
2516
tilt (>= 1.3, < 3)
26-
stripe (1.58.0)
27-
rest-client (>= 1.4, < 4.0)
17+
stripe (2.12.0)
18+
faraday (~> 0.9)
2819
tilt (2.0.7)
29-
unf (0.1.4)
30-
unf_ext
31-
unf_ext (0.0.7.4)
3220

3321
PLATFORMS
3422
ruby
@@ -38,10 +26,10 @@ DEPENDENCIES
3826
encrypted_cookie (= 0.0.4)
3927
json (= 1.8.6)
4028
sinatra (= 1.4.7)
41-
stripe (= 1.58.0)
29+
stripe (= 2.12.0)
4230

4331
RUBY VERSION
44-
ruby 2.2.7p470
32+
ruby 2.3.1p112
4533

4634
BUNDLED WITH
47-
1.14.6
35+
1.15.0

web.rb

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@
1515
return "Great, your backend is set up. Now you can configure the Stripe example apps to point here."
1616
end
1717

18+
post '/ephemeral_keys' do
19+
authenticate!
20+
begin
21+
key = Stripe::EphemeralKey.create(
22+
{customer: @customer.id},
23+
{stripe_version: params["api_version"]}
24+
)
25+
rescue Stripe::StripeError => e
26+
status 402
27+
return "Error creating ephemeral key: #{e.message}"
28+
end
29+
30+
status 200
31+
key.to_json
32+
end
33+
1834
post '/charge' do
1935
authenticate!
2036
# Get the credit card details submitted by the form
@@ -27,7 +43,8 @@
2743
:currency => "usd",
2844
:customer => @customer.id,
2945
:source => source,
30-
:description => "Example Charge"
46+
:description => "Example Charge",
47+
:shipping => params[:shipping],
3148
)
3249
rescue Stripe::StripeError => e
3350
status 402
@@ -38,46 +55,6 @@
3855
return "Charge successfully created"
3956
end
4057

41-
get '/customer' do
42-
authenticate!
43-
status 200
44-
content_type :json
45-
@customer.to_json
46-
end
47-
48-
post '/customer/sources' do
49-
authenticate!
50-
source = params[:source]
51-
52-
# Adds the token to the customer's sources
53-
begin
54-
@customer.sources.create({:source => source})
55-
rescue Stripe::StripeError => e
56-
status 402
57-
return "Error adding token to customer: #{e.message}"
58-
end
59-
60-
status 200
61-
return "Successfully added source."
62-
end
63-
64-
post '/customer/default_source' do
65-
authenticate!
66-
source = params[:source]
67-
68-
# Sets the customer's default source
69-
begin
70-
@customer.default_source = source
71-
@customer.save
72-
rescue Stripe::StripeError => e
73-
status 402
74-
return "Error selecting default source: #{e.message}"
75-
end
76-
77-
status 200
78-
return "Successfully selected default source."
79-
end
80-
8158
def authenticate!
8259
# This code simulates "loading the Stripe customer for your current session".
8360
# Your own logic will likely look very different.

0 commit comments

Comments
 (0)