Class: Pay::Stripe::Webhooks::SubscriptionTrialWillEnd

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

Instance Method Summary collapse

Instance Method Details

#call(event) ⇒ Object



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

def call(event)
  object = event.data.object

  pay_subscription = Pay::Subscription.find_by_processor_and_id(:stripe, object.id)
  return if pay_subscription.nil?

  pay_subscription.sync!(stripe_account: event.try(:account))

  pay_user_mailer = Pay.mailer.with(pay_customer: pay_subscription.customer, pay_subscription: pay_subscription)

  if Pay.send_email?(:subscription_trial_will_end, pay_subscription) && pay_subscription.on_trial?
    pay_user_mailer.subscription_trial_will_end.deliver_later
  elsif Pay.send_email?(:subscription_trial_ended, pay_subscription) && pay_subscription.trial_ended?
    pay_user_mailer.subscription_trial_ended.deliver_later
  end
end