We now have the Subscription Management Portal running on our site. It's time to keep the users in sync with the subscription events that come through with Stripe webhooks. When free trials end, cancellations, upgrades, and downgrades come through you will be notified and change the user status in your system. This allows to you restrict access, change functionality, or provide notifications to the users, whether the changes are made by the user from the Subscription Management Portal, or by an Admin from the Stripe Dashboard. Here's what we'll go over:
Events needed. Stripe provides tons of events, but we only need to listen to some to complete our billing flow.
Occurs whenever a customer is signed up for a new plan. Use it to ensure the data was populated in your user system by the handleResponse method.
Occurs whenever a customer's subscription ends. Use this to update the user's subscription status.
Occurs whenever a subscription changes (e.g., switching from one plan to another, or changing the status from trial to active). Use this to update the user's subscription status for upgrades/downgrades and trial ends.
Occurs whenever a new source is created for a customer. Use for sending notifications to your user.
Occurs whenever a card or source will expire at the end of the month. Use for sending notifications to your user.
Occurs whenever a source's details are changed. Use for sending notifications to your user.
Occurs three days before a subscription's trial period is scheduled to end, or when a trial is ended immediately (using
Occurs whenever an invoice payment attempt fails, due either to a declined payment or to the lack of a stored payment method. Use for sending notifications to your user or restricting access.
You can add your app as an endpoint from the Stripe Dashboard. You should set up an 'Account' type webhook endpoint and configure the events listed above. For more details on setting up your app as an endpoint, read here.