Answers.Body: <p>Listen to the <code>invoice.payment_succeeded</code> webhook and check the <code>billing_reason</code> for <code>subscription_cycle</code>. Full answer here: <a href="https://stackoverflow.com/a/54165193/1215040">https://stackoverflow.com/a/54165193/1215040</a></p>
  
  <pre><code>use craft\commerce\stripe\base\Gateway as StripeGateway;
  use craft\commerce\stripe\events\ReceiveWebhookEvent;
  use yii\base\Event;
  
  Event::on(
      StripeGateway::class,
      StripeGateway::EVENT_RECEIVE_WEBHOOK,
      function(ReceiveWebhookEvent $e) {
  
          if ($e-&gt;webhookData['type'] == 'invoice.payment_succeeded') {
              $invoice = $e-&gt;webhookData['data']['object'];
              if ($invoice['billing_reason'] == 'subscription_cycle') {
                  // It's not the first payment!
              }
              if ($invoice['billing_reason'] == 'subscription_create') {
                  // It's the first payment!
              }
          }
      }
  );
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-07T11:15:55.940Z
Answers.LastActivityDate: 2019-11-08T14:37:06.413Z
Answers.LastEditDate: 2019-11-08T14:37:06.413Z
Answers.UserDisplayName: James Smith
Body: <p>I've got a custom module that I have written to inject data into various places in my site when events happen with Commerce Subs.</p>
  
  <p>As per the question title, I need to update an entry when a recurring payment happens (not the initial payment as I'm already doing something with that event).</p>
  
  <p>I cannot see how to identify the subsequent payments from the events I have available to me in Craft Commerce</p>
  
Tags: <plugin-development><plugin-craftcommerce2><plugin-commerce-stripe>
Title: How to identify the recurring payments that happen after the initial subs creation payment the in Commerce Subs
ThreadText: # How to identify the recurring payments that happen after the initial subs creation payment the in Commerce Subs
  
  (Asked by: username_0 on 2019-11-06)
  
  I've got a custom module that I have written to inject data into various places in my site when events happen with Commerce Subs.
  
  As per the question title, I need to update an entry when a recurring payment happens (not the initial payment as I'm already doing something with that event).
  
  I cannot see how to identify the subsequent payments from the events I have available to me in Craft Commerce
  
  **Tags:** plugin-development, plugin-craftcommerce2, plugin-commerce-stripe
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-11-07. Score: 1
  
  Listen to the `invoice.payment_succeeded` webhook and check the `billing_reason` for `subscription_cycle`. Full answer here: <https://stackoverflow.com/a/54165193/1215040>
  
  ```
  use craft\commerce\stripe\base\Gateway as StripeGateway;
  use craft\commerce\stripe\events\ReceiveWebhookEvent;
  use yii\base\Event;
  
  Event::on(
      StripeGateway::class,
      StripeGateway::EVENT_RECEIVE_WEBHOOK,
      function(ReceiveWebhookEvent $e) {
  
          if ($e->webhookData['type'] == 'invoice.payment_succeeded') {
              $invoice = $e->webhookData['data']['object'];
              if ($invoice['billing_reason'] == 'subscription_cycle') {
                  // It's not the first payment!
              }
              if ($invoice['billing_reason'] == 'subscription_create') {
                  // It's the first payment!
              }
          }
      }
  );
  
  ```
  
  
  ---
  
  