Answers.Body: <p>Could you use one of the following events?</p>
  <pre class="lang-php prettyprint-override"><code>\craft\commerce\stripe\services\Invoices::EVENT_BEFORE_SAVE_INVOICE
  \craft\commerce\stripe\services\Invoices::EVENT_SAVE_INVOICE
  </code></pre>
  <p>Maybe looking in the invoice model <code>invoiceData</code> attribute (that is passed to the above event).</p>
  <p>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.</p>
  <p>Please comment on the ticket for that here if so: <a href="https://github.com/craftcms/commerce/issues/1799" rel="nofollow noreferrer">https://github.com/craftcms/commerce/issues/1799</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-06T17:19:47.637Z
Answers.Text: 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.
Answers.UserDisplayName: Clive Portman
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-17T11:23:02.797Z
Answers.Text: Back again. I had what looks like a failed renewal. I'm logging both of the above events and none of them were triggered.
Answers.UserDisplayName: Clive Portman
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-22T14:14:30.250Z
Answers.LastActivityDate: 2020-10-22T14:14:30.250Z
Answers.UserDisplayName: Luke Holder
Body: <p>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.</p>
  <p>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:</p>
  <p>Day 1: EVENT_BEFORE_UPDATE_SUBSCRIPTION called as the renewal invoice is created. The subscription status is active.<br />
  Day 1 (1 hr later): EVENT_BEFORE_UPDATE_SUBSCRIPTION called as the transaction fails. The subscription status is suspended.</p>
  <p>Day 2: EVENT_BEFORE_UPDATE_SUBSCRIPTION called as a second renewal invoice is created. The subscription status is suspended.<br />
  Day 2 (1 hr later): EVENT_BEFORE_UPDATE_SUBSCRIPTION called as the transaction succeeds. The subscription status is active.</p>
  <p>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.</p>
  <p>What I really want to do is differentiate between the event being called by Stripe creating an invoice and Stripe attempting a transaction.</p>
  <p>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?</p>
  
Tags: <plugin-craftcommerce><events><stripe>
Title: How to differentiate EVENT_BEFORE_UPDATE_SUBSCRIPTION events in Commerce 2/3
ThreadText: # How to differentiate EVENT_BEFORE_UPDATE_SUBSCRIPTION events in Commerce 2/3
  
  (Asked by: username_0 on 2020-07-29)
  
  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?
  
  **Tags:** plugin-craftcommerce, events, stripe
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-10-22. Score: 1
  
  Could you use one of the following events?
  
  ```php
  \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>
  
  > **Comments:**
  > **username_0**: 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.  
  > **username_0**: Back again. I had what looks like a failed renewal. I'm logging both of the above events and none of them were triggered.  
  
  ---
  
  