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?