Class: Pay::Stripe::Webhooks::SubscriptionRenewing
- Inherits:
-
Object
- Object
- Pay::Stripe::Webhooks::SubscriptionRenewing
- Defined in:
- lib/pay/stripe/webhooks/subscription_renewing.rb
Instance Method Summary collapse
-
#call(event) ⇒ Object
Handles ‘invoice.upcoming` webhook from Stripe Occurs X number of days before a subscription is scheduled to create an invoice that is automatically charged—where X is determined by your subscriptions settings.
- #notify_user(billable, subscription, date) ⇒ Object
Instance Method Details
#call(event) ⇒ Object
Handles ‘invoice.upcoming` webhook from Stripe Occurs X number of days before a subscription is scheduled to create an invoice that is automatically charged—where X is determined by your subscriptions settings. Note: The received Invoice object will not have an invoice ID.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/pay/stripe/webhooks/subscription_renewing.rb', line 8 def call(event) # Event is of type "invoice" see: # https://stripe.com/docs/api/invoices/object subscription = Pay::Subscription.find_by_processor_and_id(:stripe, event.data.object.subscription) return unless subscription # Stripe subscription items all have the same interval price = event.data.object.lines.data.first.price return unless price.type == "recurring" interval = price.recurring.interval return unless interval == "year" notify_user(subscription.customer.owner, subscription, Time.zone.at(event.data.object.next_payment_attempt)) end |
#notify_user(billable, subscription, date) ⇒ Object
24 25 26 27 28 |
# File 'lib/pay/stripe/webhooks/subscription_renewing.rb', line 24 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 |