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.
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 23 24 25 26 27 28 29 |
# File 'lib/pay/stripe/webhooks/subscription_renewing.rb', line 8 def call(event) invoice = event.data.object subscription_id = invoice.parent.try(:subscription_details).try(:subscription) # Event is of type "invoice" see: # https://stripe.com/docs/api/invoices/object pay_subscription = Pay::Subscription.find_by_processor_and_id(:stripe, subscription_id) return unless pay_subscription # Stripe subscription items all have the same interval price = ::Stripe::Price.retrieve(invoice.lines.first.pricing.price_details.price) # For collection_method=send_invoice, Stripe will send an email and next_payment_attempt will be null # https://docs.stripe.com/api/invoices/object#invoice_object-collection_method if Pay.send_email?(:subscription_renewing, pay_subscription, price) && (next_payment_attempt = invoice.next_payment_attempt) Pay.mailer.with( pay_customer: pay_subscription.customer, pay_subscription: pay_subscription, date: Time.zone.at(next_payment_attempt) ).subscription_renewing.deliver_later end end |