Answers.Body: <p>I've looked into this in more detail now, and whilst it used to be the case that EVENT_AFTER_CREATE_SUBSCRIPTION only worked for successful payments, it's now (post Commerce 2.2.0), no longer the case due to the fact that a subscription can get created in a "Suspended" status, which still triggers that event (<a href="https://github.com/craftcms/commerce/issues/1105" rel="nofollow noreferrer">https://github.com/craftcms/commerce/issues/1105</a>).</p>
  
  <p>I'm still using that event, but in Commerce 2.2.7 (and beyond unless they change it again!), you'll need to make an additional check inside your code to make sure the subscription is not Suspended.</p>
  
  <pre><code>Event::on(
      Subscriptions::class,
      Subscriptions::EVENT_AFTER_CREATE_SUBSCRIPTION,
      function(SubscriptionEvent $e) {
  
          // --------------------------------------------
          // BAIL OUT on Suspended subs!
          // --------------------------------------------
  
          if ($e-&gt;subscription-&gt;isSuspended){
              return;
          }
  
          // --------------------------------------------
          // Continue...
          // --------------------------------------------
  
          ...
      }
  );
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-01T15:46:03.810Z
Answers.LastActivityDate: 2019-11-01T15:46:03.810Z
Answers.UserDisplayName: James Smith
Body: <p>Regarding Event: <code>EVENT_AFTER_CREATE_SUBSCRIPTION</code>
  <a href="https://docs.craftcms.com/commerce/api/v2/craft-commerce-services-subscriptions.html#events" rel="nofollow noreferrer">https://docs.craftcms.com/commerce/api/v2/craft-commerce-services-subscriptions.html#events</a></p>
  
  <p>The document states "The event that is triggered after a subscription is created. Plugins can get notified after a subscription is created."</p>
  
  <p>Using the commerce 2 as an example:</p>
  
  <p>I just need an expert to confirm that a subscription is created or <code>EVENT_AFTER_CREATE_SUBSCRIPTION</code> has executed <strong>only</strong> when a user has successfully made payment to a subscription.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-14T10:32:18.673Z
Comments.Text: I'm building a subscription site at the moment and wondered this too recently, as it's not clear from the docs. Looking through the code at `/vendor/craftcms/commerce/src/services/Subscriptions.php` ~ line 389ff suggests to me that it _should_ only execute after a payment, but I can't say for sure, as it's only checking for `$response->isInactive()` -- there might be other ways the response could fail. The alternative might be to use the Stripe plugin's `EVENT_RECEIVE_WEBHOOK` and listen for `customer.subscription.created`. I'd like someone more experienced than me to answer though!
Comments.UserDisplayName: James Smith
Tags: <craft3><plugin-craftcommerce2>
Title: EVENT_AFTER_CREATE_SUBSCRIPTION can someone confirm this means successful purchase?
ThreadText: # EVENT_AFTER_CREATE_SUBSCRIPTION can someone confirm this means successful purchase?
  
  (Asked by: username_0 on 2019-10-14)
  
  Regarding Event: `EVENT_AFTER_CREATE_SUBSCRIPTION`
  <https://docs.craftcms.com/commerce/api/v2/craft-commerce-services-subscriptions.html#events>
  
  The document states "The event that is triggered after a subscription is created. Plugins can get notified after a subscription is created."
  
  Using the commerce 2 as an example:
  
  I just need an expert to confirm that a subscription is created or `EVENT_AFTER_CREATE_SUBSCRIPTION` has executed **only** when a user has successfully made payment to a subscription.
  
  **Tags:** craft3, plugin-craftcommerce2
  
  > **Comments:**
  > **username_1**: I'm building a subscription site at the moment and wondered this too recently, as it's not clear from the docs. Looking through the code at `/vendor/craftcms/commerce/src/services/Subscriptions.php` ~ line 389ff suggests to me that it _should_ only execute after a payment, but I can't say for sure, as it's only checking for `$response->isInactive()` -- there might be other ways the response could fail. The alternative might be to use the Stripe plugin's `EVENT_RECEIVE_WEBHOOK` and listen for `customer.subscription.created`. I'd like someone more experienced than me to answer though!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-11-01. Score: 2 | Accepted answer
  
  I've looked into this in more detail now, and whilst it used to be the case that EVENT\_AFTER\_CREATE\_SUBSCRIPTION only worked for successful payments, it's now (post Commerce 2.2.0), no longer the case due to the fact that a subscription can get created in a "Suspended" status, which still triggers that event (<https://github.com/craftcms/commerce/issues/1105>).
  
  I'm still using that event, but in Commerce 2.2.7 (and beyond unless they change it again!), you'll need to make an additional check inside your code to make sure the subscription is not Suspended.
  
  ```
  Event::on(
      Subscriptions::class,
      Subscriptions::EVENT_AFTER_CREATE_SUBSCRIPTION,
      function(SubscriptionEvent $e) {
  
          // --------------------------------------------
          // BAIL OUT on Suspended subs!
          // --------------------------------------------
  
          if ($e->subscription->isSuspended){
              return;
          }
  
          // --------------------------------------------
          // Continue...
          // --------------------------------------------
  
          ...
      }
  );
  
  ```
  
  
  ---
  
  