Search code examples
phpstripe-paymentswebhookslaravel-8subscription

Testing Stripe's trial_will_end webhook


I'm in a bit of a pickle

I want to create a webhook listener to Stripe's customer.subscription.trial_will_end event to send a customer an email letting them know billing will start and giving them cancellation info, but I can't work out how to test it works without waiting a day between each test, i.e. setting the trial period for 4 days, and the event being fired when there's 3 days left.

The Stripe docs give a method for testing trials, but this doesn't fit my use case as the only thing that doesn't work using that method is the trial_will_end event. The CLI can send webhook events, but again the trial_will_end event is not implemented.

How can I test this functionality without having to wait a full day between tests?


Solution

  • There are not currently great ways to manage time-dependent events like this. You will need to seed some test data to generate such events. For a given day of testing through, you can re-use a recent trial_will_end event (say evt_123) using the CLI resend function (doc):

    stripe events resend evt_123 --webhook-endpoint we_321

    This will let you re-test your endpoint to handle the event & send the email multiple times, ingesting the same event.