Search code examples
ruby-on-rails-5stripe-payments

Rails: Stripe webhooks for `invoice.payment_action_required` & `invoice.payment_failed`


I am sending customer emails when i get the events invoice.payment_action_required & invoice.payment_failed.

this causes a email to be sent to the user when they are subscribing for the first time and are on_session.

How do i ensure that the emails are not getting sent the user is subscribing the first time but are only sent when the events happen for recurring payments.

Any help on this would be really great.

Thanks.


Solution

  • You can check the billing_reason of the Invoice in the Event so you can identify and ignore events relating to to the first payment of a subscription(they'd have subscription_create).

    https://stripe.com/docs/api/invoices/object#invoice_object-billing_reason