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

Commit 4e5b4b4

Browse files
authored
Merge pull request #55 from jemerick-stripe/master
Add Create Setup Intent Endpoint
2 parents 5354ebd + 623ab21 commit 4e5b4b4

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ gem 'dotenv', '2.7.2'
66
gem 'encrypted_cookie', '0.0.5'
77
gem 'json', '2.2.0'
88
gem 'sinatra', '2.0.5'
9-
gem 'stripe', '4.12.0'
9+
gem 'stripe', '4.21.0'

Gemfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ GEM
88
faraday (0.15.4)
99
multipart-post (>= 1.2, < 3)
1010
json (2.2.0)
11-
multipart-post (2.0.0)
11+
multipart-post (2.1.1)
1212
mustermann (1.0.3)
13-
net-http-persistent (3.0.0)
13+
net-http-persistent (3.0.1)
1414
connection_pool (~> 2.2)
1515
rack (2.0.7)
1616
rack-protection (2.0.5)
@@ -20,7 +20,7 @@ GEM
2020
rack (~> 2.0)
2121
rack-protection (= 2.0.5)
2222
tilt (~> 2.0)
23-
stripe (4.12.0)
23+
stripe (4.21.0)
2424
faraday (~> 0.13)
2525
net-http-persistent (~> 3.0)
2626
tilt (2.0.9)
@@ -33,7 +33,7 @@ DEPENDENCIES
3333
encrypted_cookie (= 0.0.5)
3434
json (= 2.2.0)
3535
sinatra (= 2.0.5)
36-
stripe (= 4.12.0)
36+
stripe (= 4.21.0)
3737

3838
RUBY VERSION
3939
ruby 2.5.3p105

web.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,29 @@ def authenticate!
120120
@customer
121121
end
122122

123+
# This endpoint is used by the mobile example apps to create a SetupIntent.
124+
# https://stripe.com/docs/api/setup_intents/create
125+
# Just like the `/capture_payment` endpoint, a real implementation would include controls
126+
# to prevent misuse
127+
post '/create_setup_intent' do
128+
begin
129+
setup_intent = Stripe::SetupIntent.create({
130+
payment_method_types: ['card'],
131+
})
132+
rescue Stripe::StripeError => e
133+
status 402
134+
return log_info("Error creating SetupIntent: #{e.message}")
135+
end
136+
137+
log_info("SetupIntent successfully created: #{setup_intent.id}")
138+
status 200
139+
return {
140+
:intent => setup_intent.id,
141+
:secret => setup_intent.client_secret,
142+
:status => setup_intent.status
143+
}.to_json
144+
end
145+
123146
# This endpoint is used by the mobile example apps to create a PaymentIntent.
124147
# https://stripe.com/docs/api/payment_intents/create
125148
# Just like the `/capture_payment` endpoint, a real implementation would include controls

0 commit comments

Comments
 (0)