Overview
Webhooks are essential for handling asynchronous events from:- Stripe (payments and subscriptions)
- Clerk (user authentication)
checkout.session.completed
event is supported.
You can implment a more custom billing model by modifying the billing module.
Configure Your Stripe Webhooks
-
Configure Stripe Dashboard
- Go to the Stripe Dashboard
- Add a new webhook endpoint with your API URL:
https://api.${DOMAIN_NAME}/checkout-webhook
- Copy the webhook signing secret
- Add it to your secrets as
StripeSecretKey
-
Configure your stripe product
- Go to the Stripe Dashboard
- Copy the price ID for your product
- Add it to your secrets as
StripePriceId
-
Enable Events
- Select the events you want to listen for
checkout.session.completed
-
Testing Webhooks
Deploy or start your API
Clerk Webhooks
Clerk webhooks are also implemented in the control plane. Preconfigured for you is a clerk webhook that will trigger when a user signs up. This webhook will create a new user in the Database and create a new API key for them with Unkey. Clerk webhooks are really extensible and go beyond just a trigger on signup.Configure Your Clerk Webhooks
Set up webhook endpoint- Go to the Webhooks page in Clerk Dashboard
- Select “Add Endpoint”
- Enter your endpoint URL
https://${stage}-api.${DOMAIN_NAME}/signup-webhook
- Select the
user.created
event which triggers when a new user registers - Create the endpoint
- Copy the Signing Secret from your endpoint’s settings page
- Add it to your
.env.{stage}
file asClerkWebhookSecret
- Create a JWT template in the clerk dashboard
- Login with a test user
- Generate a JWT token using the template via the console
env.test
where needed.
There are other methods to generate a JWT token for testing, but this is the most straightforward.
Learn more about Clerk JWT tokens here
Learn more about Clerk Webhooks here