begin
# Use Stripe's library to make requests...
rescue Stripe::CardError => e
puts "Status is: #{e.http_status}"
puts "Type is: #{e.error.type}"
puts "Charge ID is: #{e.error.charge}"
# The following fields are optional
puts "Code is: #{e.error.code}" if e.error.code
puts "Decline code is: #{e.error.decline_code}" if e.error.decline_code
puts "Param is: #{e.error.param}" if e.error.param
puts "Message is: #{e.error.message}" if e.error.message
rescue Stripe::RateLimitError => e
# Too many requests made to the API too quickly
rescue Stripe::InvalidRequestError => e
# Invalid parameters were supplied to Stripe's API
rescue Stripe::AuthenticationError => e
# Authentication with Stripe's API failed
# (maybe you changed API keys recently)
rescue Stripe::APIConnectionError => e
# Network communication with Stripe failed
rescue Stripe::StripeError => e
# Display a very generic error to the user, and maybe send
# yourself an email
rescue => e
# Something else happened, completely unrelated to Stripe
end