Class: Pay::Stripe::Webhooks::SubscriptionDeleted

Inherits:
Object
  • Object
show all
Defined in:
lib/pay/stripe/webhooks/subscription_deleted.rb

Instance Method Summary collapse

Instance Method Details

#call(event) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/pay/stripe/webhooks/subscription_deleted.rb', line 5

def call(event)
  object = event.data.object
  subscription = Pay.subscription_model.find_by(processor: :stripe, processor_id: object.id)

  # We couldn't find the subscription for some reason, maybe it's from another service
  return if subscription.nil?

  # User canceled subscriptions have an ends_at
  # Automatically canceled subscriptions need this value set
  subscription.update!(ends_at: Time.at(object.ended_at)) if subscription.ends_at.blank? && object.ended_at.present?
end