Ryan Glover Ryan Glover - 1 month ago 5
Node.js Question

How to Prevent/Manage Stripe Webhook Sending Invoice for $0 on Trial Signup?

I'm working on an app that comes with a 14 day trial for free.

To handle payments, I'm using Stripe and listening for webhooks so I can perform functions on the backend when events happen.

One thing I've noticed, though, is that Stripe is sending me invoice data with an amount charged of $0 for the trial period. So, if a customer signs up, they get an invoice from Stripe for $0 (I have my webhook setup to fire off an email for each invoice I receive).

This isn't terrible, but from a UX perspective, I'd like to avoid the shock of getting an immediate invoice when someone is expecting a trial (even if that invoice is for $0).

I've considered just checking the data Stripe sends over and filtering out $0 invoices, but if I offer a discount or something, this doesn't seem like the best way.

Any thoughts/notes on how to implement this better?

Answer

A couple options here:

  • When you create the customer/subscription, the API returns both the customer and the subscription data to you in its response. You can use data from either or both of these to filter intelligently. Of particular interest:

    • current_period_start: This will also be the timestamp of the invoice.
    • trial_end: Until this timestamp, any invoice including a subscription is for a trial.
    • customer: If you don't like the others, you can always query the customer record when processing a $0 invoice. Customers in their trial period have a status of trialing.
  • If you're sending the email on invoice.created events, only the initial subscription invoice is created as closed. All other subscription invoices are open when Stripe creates them. (This is so you can make adjustments before the invoice is processed.) An invoice that's both $0 and closed has a high probability of being a trial—100%, in fact, if you're not otherwise creating already-closed invoices.

Comments