This example demonstrates how to use Upstash Workflow with Next.js to handle Clerk webhook events, manage Stripe subscriptions, and send automated emails.
- Webhook handling for Clerk user events
- Stripe customer and subscription management
- Automated email sending with Resend
- Trial period management
- Event-driven workflow orchestration
- Clerk account and API keys
- Stripe account and API keys
- Resend account and API key
- Upstash account and QStash credentials
- Install the dependencies
npm install
- Set up your environment variables in
.env.local
:
QSTASH_URL=
QSTASH_TOKEN=
CLERK_WEBHOOK_SECRET=
STRIPE_SECRET_KEY=
RESEND_API_KEY=
- Open a local tunnel to your development server:
ngrok http 3000
Set the UPSTASH_WORKFLOW_URL environment variable to the ngrok URL.
- Start the development server.
Then, run the create-user.sh
script in the sh
folder.
./sh/create-user.sh
The example implements the following workflow:
- Validate incoming Clerk webhook on
/api/workflow/onboarding
endpoint - Process user creation events
- Create Stripe customer
- Send welcome email
- Set up trial subscription
- Wait for
await-payment-method
event. If a payment method is added to user,/api/workflow/stripe
endpoint will be triggered by Stripe workflow. - Handle trial period completion
- Send appropriate follow-up emails
Contributions are welcome! Please read our contributing guidelines before submitting pull requests.