title: How can I test subscription renewal flows in stripe?
body: <p>I want to test my application's handling of webhook events from stripe when a subscription payment has been made (or failed).  Here is what I've tried so far:</p>
  
  <ul>
  <li>Set up a new subscription</li>
  <li>Update user's credit card to be the one that can be added to an account, but will fail to actually be charged</li>
  <li>Change the trial end date to be in one second</li>
  <li>Wait a few seconds expecting the webhook to be sent</li>
  </ul>
  
  <p>However, According to <a href="https://stripe.com/docs/api/go#invoices">the documentation</a>:</p>
  
  <blockquote>
    <p>If you have configured webhooks, the invoice will wait until one hour after the last webhook is successfully sent (or the last webhook times out after failing).</p>
  </blockquote>
  
  <p>One hour is a long time to wait, since I am trying to do this as part of an automated integration test suite.</p>
  
  <p>One suggestion (from IRC) is to fake out the webhook request, so that my integration test sends the event, instead of Stripe sending it. However, since Stripe doesn't include any sort of HMAC in the webhooks, I can't trust the data in the payload.  So, my application just takes the event ID from the webhook payload and fetches the <a href="https://stripe.com/docs/webhooks">event from the Stripe API</a>:</p>
  
  <blockquote>
    <p>If security is a concern, or if it's important to confirm that Stripe sent the webhook, you should only use the ID sent in your webhook and should request the remaining details from the API directly.</p>
  </blockquote>
  
  <p>This will obviously not work if I am trying to inject fake events for my test (by design).</p>
  
  <p>What are the best practices for testing this sort of scenario?</p>