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

Commit 3c368f8

Browse files
Adds support for confirming SetupIntent on backend (#61)
* Adds conditional SetupIntent confirmation on create and new confirm_setup_intent endpoint * Remove authenticate. * Fix typo * Don't need separate confirm.
1 parent 4597d50 commit 3c368f8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

web.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,17 @@ def authenticate!
129129
# Just like the `/capture_payment` endpoint, a real implementation would include controls
130130
# to prevent misuse
131131
post '/create_setup_intent' do
132+
payload = params
133+
if request.content_type.include? 'application/json' and params.empty?
134+
payload = Sinatra::IndifferentHash[JSON.parse(request.body.read)]
135+
end
132136
begin
133137
setup_intent = Stripe::SetupIntent.create({
134138
payment_method_types: ['card'],
139+
payment_method: payload[:payment_method],
140+
return_url: payload[:return_url],
141+
confirm: payload[:payment_method] != nil,
142+
use_stripe_sdk: payload[:payment_method] != nil ? true : nil,
135143
})
136144
rescue Stripe::StripeError => e
137145
status 402

0 commit comments

Comments
 (0)