Class: Effective::WebhooksController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Effective::WebhooksController
- Defined in:
- app/controllers/effective/webhooks_controller.rb
Instance Method Summary collapse
-
#stripe ⇒ Object
Webhook from stripe.
Instance Method Details
#stripe ⇒ Object
Webhook from stripe
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/effective/webhooks_controller.rb', line 7 def stripe (head(:ok) and return) if (params[:livemode] == false && Rails.env.production?) || params[:object] != 'event' || params[:id].blank? # Dont trust the POST, and instead request the actual event from Stripe @event = Stripe::Event.retrieve(params[:id]) rescue (head(:ok) and return) Effective::Customer.transaction do begin case @event.type when 'customer.created' ; stripe_customer_created(@event) when 'customer.deleted' ; stripe_customer_deleted(@event) when 'customer.subscription.created' ; stripe_subscription_created(@event) when 'customer.subscription.deleted' ; stripe_subscription_deleted(@event) end rescue => e Rails.logger.info "Stripe Webhook Error: #{e.}" raise ActiveRecord::Rollback end end head :ok # Always return success end |