1
0 Comments

Billing is LIVE!

Had a bit of a break from hacking and finally found some time to add some more features.

I needed to iterate billing/plans because they weren't working. I decided to change to paid-for accounts and offer a free trial for people to get started. Here's how I did it:

Updating the Session

I needed so quick way to check if a user had an active subscription or was on an active trial. I'm using authjs so I updated the session callback to add this property.

Wrap the app in a check for active subscription

The nextjs pages of the app are wrapped in a layout component. I added a quick server-side check to look-up the new user property and redirect is the user hasn't yet subscribed.

Build a plans page

I made a new route at /setup to be the destination for people to arrive at if they do not have an active subscription. I built a custom create checkout session button following Stripe's docs, but in the end it was WAY easier to just use their pre-built components. The only chance I made was to add a toggle switch for people to choose between monthly and annual billing.

Stripe webhook

You need a way for Stripe to tell your app what's happening with customers. You do this by building a custom webhook route. This works by listening to particular stripe events and running custom code. Things like "customer created" and "subscription started"

That's it. Loads more to do.

, Founder of Icon for Flua
Flua
on July 27, 2024