defexample_function(params)beginStripe::PaymentIntent.create(params)rescueStripe::CardError=> e
puts "A payment error occurred: #{e.error.message}"rescueStripe::InvalidRequestError=> e
puts "An invalid request occurred."rescueStripe::StripeError=> e
puts "Another problem occurred, maybe unrelated to Stripe."else
puts "No error."endend
require'stripe'require'sinatra'
post '/webhook'do
payload = request.body.read
data =JSON.parse(payload, symbolize_names:true)# Get the event object
event =Stripe::Event.construct_from(data)# Use the event type to find out what happenedcase event.type
when'payment_intent.payment_failed'# Get the object affected
payment_intent = event.data.object
# Use stored information to get an error object
e = payment_intent.last_payment_error
# Use its type to choose a responsecase e.type
when'card_error'
puts "A payment error occurred: #{e.message}"when'invalid_request'
puts "An invalid request occurred."else
puts "Another problem occurred, maybe unrelated to Stripe."endend
content_type 'application/json'{
status:'success'}.to_json
end
Welcome to the Stripe Shell!
Stripe Shell is a browser-based shell with the Stripe CLI pre-installed. Log in to your
Stripe account and press Control + Backtick (`) on your keyboard to start managing your Stripe
resources in test mode.
- View supported Stripe commands:
- Find webhook events:
- Listen for webhook events:
- Call Stripe APIs: stripe [api resource] [operation] (e.g., )