Skip to content

Instantly share code, notes, and snippets.

@MittalPatel-BTC
Created August 25, 2019 16:39
Show Gist options
  • Save MittalPatel-BTC/a33563b92c0b93bd70bf042cba2984fa to your computer and use it in GitHub Desktop.
Save MittalPatel-BTC/a33563b92c0b93bd70bf042cba2984fa to your computer and use it in GitHub Desktop.
Stripe event handler service
# app/services/stripe/event_handler.rb
# Stripe module
module Stripe
# stripe main class EventHandler
class EventHandler
def call(event)
method = 'handle_' + event.type.tr('.', '_')
send method, event
rescue JSON::ParserError => e
render json: { status: 400, error: 'Invalid payload' }
Raven.capture_exception(e)
rescue Stripe::SignatureVerificationError => e
render json: { status: 400, error: 'Invalid signature' }
Raven.capture_exception(e)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment