1

I'm listening for various subscription events to send emails to members. Right now, I'm dealing with subscriptions where a renewal payment fails. I'm specifically listening for EVENT_BEFORE_UPDATE_SUBSCRIPTION.

The problem is it's called twice per attempt (successful or not). Once for the Stripe invoice creation and once for the Stripe transaction attempt. Here's what is might look like:

Day 1: EVENT_BEFORE_UPDATE_SUBSCRIPTION called as the renewal invoice is created. The subscription status is active.
Day 1 (1 hr later): EVENT_BEFORE_UPDATE_SUBSCRIPTION called as the transaction fails. The subscription status is suspended.

Day 2: EVENT_BEFORE_UPDATE_SUBSCRIPTION called as a second renewal invoice is created. The subscription status is suspended.
Day 2 (1 hr later): EVENT_BEFORE_UPDATE_SUBSCRIPTION called as the transaction succeeds. The subscription status is active.

You can see from the above that just listening to the EVENT_BEFORE_UPDATE SUBSCRIPTION will result in two emails being sent each day. Even if I listen for the status being suspended, an unnecessary email will be sent the following day.

What I really want to do is differentiate between the event being called by Stripe creating an invoice and Stripe attempting a transaction.

Has anyone done this or know a variable I can test against to identify whether it's an invoice creation or transaction that has triggered the event?

1

Could you use one of the following events?

\craft\commerce\stripe\services\Invoices::EVENT_BEFORE_SAVE_INVOICE
\craft\commerce\stripe\services\Invoices::EVENT_SAVE_INVOICE

Maybe looking in the invoice model invoiceData attribute (that is passed to the above event).

If that won't suffice, we should expose a way for you to listen to any Stripe Webhook event that comes into commerce, and react.

Please comment on the ticket for that here if so: https://github.com/craftcms/commerce/issues/1799

2
  • This is taking time while I wait for renewals but I've had a successful renewal (sorry, I only started listening for it this week). It triggered those invoice events once, with a status of 'paid'. I could do with knowing what the other statuses are before I do more, so will wait for a failed renewal. Thanks. – Clive Portman Nov 6 '20 at 17:19
  • Back again. I had what looks like a failed renewal. I'm logging both of the above events and none of them were triggered. – Clive Portman Nov 17 '20 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.