Class: Pay::Braintree::Webhooks::SubscriptionCanceled

Inherits:
Object
  • Object
show all
Defined in:
lib/pay/braintree/webhooks/subscription_canceled.rb

Instance Method Summary collapse

Instance Method Details

#call(event) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pay/braintree/webhooks/subscription_canceled.rb', line 7

def call(event)
  subscription = event.subscription
  return if subscription.nil?

  pay_subscription = Pay::Subscription.find_by_processor_and_id(:braintree, subscription.id)
  return unless pay_subscription.present?

  ends_at = Time.current
  pay_subscription.update!(
    status: :canceled,
    trial_ends_at: (ends_at if pay_subscription.trial_ends_at?),
    ends_at: ends_at
  )
end