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

Commit 4c3d2c8

Browse files
create a setup intent
1 parent e53c285 commit 4c3d2c8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

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)