Skip to content

Commit a0f8150

Browse files
committed
Ignore subscription renewing webhooks when subscription is set to send_invoice.
Stripe will email the customer the invoice with payment instructions so we don't need to send an additional email. Fixes #1138
1 parent e1e0b04 commit a0f8150

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/pay/stripe/webhooks/subscription_renewing.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ def call(event)
1414
# Stripe subscription items all have the same interval
1515
price = event.data.object.lines.data.first.price
1616

17-
if Pay.send_email?(:subscription_renewing, pay_subscription, price)
17+
# For collection_method=send_invoice, Stripe will send an email and next_payment_attempt will be null
18+
# https://docs.stripe.com/api/invoices/object#invoice_object-collection_method
19+
if Pay.send_email?(:subscription_renewing, pay_subscription, price) && (next_payment_attempt = event.data.object.next_payment_attempt)
1820
Pay.mailer.with(
1921
pay_customer: pay_subscription.customer,
2022
pay_subscription: pay_subscription,
21-
date: Time.zone.at(event.data.object.next_payment_attempt)
23+
date: Time.zone.at(next_payment_attempt)
2224
).subscription_renewing.deliver_later
2325
end
2426
end

0 commit comments

Comments
 (0)