diff --git a/Gemfile b/Gemfile index 95a00a1..f49f812 100644 --- a/Gemfile +++ b/Gemfile @@ -6,4 +6,4 @@ gem 'dotenv', '2.2.1' gem 'encrypted_cookie', '0.0.5' gem 'json', '2.1.0' gem 'sinatra', '2.0.2' -gem 'stripe', '3.11.0' +gem 'stripe', '3.17.0' diff --git a/Gemfile.lock b/Gemfile.lock index 24fde7e..cf506b3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,7 +17,7 @@ GEM rack (~> 2.0) rack-protection (= 2.0.2) tilt (~> 2.0) - stripe (3.11.0) + stripe (3.17.0) faraday (~> 0.10) tilt (2.0.8) @@ -29,7 +29,7 @@ DEPENDENCIES encrypted_cookie (= 0.0.5) json (= 2.1.0) sinatra (= 2.0.2) - stripe (= 3.11.0) + stripe (= 3.17.0) RUBY VERSION ruby 2.5.0p0 diff --git a/web.rb b/web.rb index 4ff66c4..727d649 100644 --- a/web.rb +++ b/web.rb @@ -105,6 +105,29 @@ def authenticate! return log_info("Charge successfully created") end +# This endpoint is used by the mobile example apps to create a PaymentIntent. +# https://stripe.com/docs/api#create_payment_intent +# Just like the `/create_charge` endpoint, a real implementation would include controls +# to prevent misuse +post '/create_intent' do + begin + intent = Stripe::PaymentIntent.create( + :allowed_source_types => ['card'], + :amount => params[:amount], + :currency => params[:currency] || 'usd', + :description => params[:description] || 'Example PaymentIntent charge', + :return_url => params[:return_url], + ) + rescue Stripe::StripeError => e + status 402 + return log_info("Error creating payment intent: #{e.message}") + end + + log_info("Payment Intent successfully created") + status 200 + return {:intent => intent.id, :secret => intent.client_secret}.to_json +end + # This endpoint responds to webhooks sent by Stripe. To use it, you'll need # to add its URL (https://{your-app-name}.herokuapp.com/stripe-webhook) # in the webhook settings section of the Dashboard.