Class: Pay::Stripe::Webhooks::SubscriptionRenewing

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

Instance Method Summary collapse

Instance Method Details

#call(event) ⇒ Object



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

def call(event)
  # Event is of type "invoice" see:
  # https://stripe.com/docs/api/invoices/object
  subscription = Pay.subscription_model.find_by(
    processor: :stripe,
    processor_id: event.data.object.subscription
  )
  date = Time.zone.at(event.data.object.next_payment_attempt)
  notify_user(subscription.owner, subscription, date) if subscription.present?
end

#notify_user(billable, subscription, date) ⇒ Object



16
17
18
19
20
# File 'lib/pay/stripe/webhooks/subscription_renewing.rb', line 16

def notify_user(billable, subscription, date)
  if Pay.send_emails
    Pay::UserMailer.with(billable: billable, subscription: subscription, date: date).subscription_renewing.deliver_later
  end
end