Webhooks allow Mantlz to receive real-time notifications from third-party services like Stripe. This guide covers webhook setup, handling, and security.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/artistatbl/Mantlz/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Mantlz uses webhooks for:- Stripe: Payment events, subscription updates, invoice status
- Form Submissions: Real-time form submission notifications (optional)
- Custom Integrations: User-defined webhook endpoints
Stripe Webhooks
Stripe webhooks handle subscription lifecycle events, payments, and billing.Webhook Endpoint
Mantlz listens for Stripe webhooks at:Setup
Get your webhook signing secret
In your Stripe Dashboard:
- Go to Developers → Webhooks
- Click Add endpoint
- Enter your webhook URL:
- Development:
https://your-ngrok-url.ngrok.io/api/webhooks/stripe - Production:
https://your-domain.com/api/webhooks/stripe
- Development:
- Select events to listen for (see below)
- Click Add endpoint
- Copy the Signing secret (starts with
whsec_)
Events Handled
Mantlz listens for and handles these Stripe events:Event Selection
When creating your webhook endpoint in Stripe, select these events:checkout.session.completedcustomer.subscription.createdcustomer.subscription.updatedcustomer.subscription.deletedcustomer.subscription.resumedinvoice.payment_succeededinvoice.payment_failed
Webhook Handler Implementation
The webhook route verifies and processes Stripe events:src/app/api/webhooks/stripe/route.ts
Webhook Security
Mantlz verifies webhooks using Stripe’s signature verification:- Replay attacks
- Man-in-the-middle attacks
- Unauthorized webhook calls
Failed Payment Handling
Mantlz implements a 3-attempt retry policy for failed payments:First failure
- Update subscription status to
PAST_DUE - Record failure attempt
- Send payment failure email with update link
- Stripe retries in 3 days
Testing Webhooks Locally
Using Stripe CLI
Using ngrok for Remote Testing
Install ngrok
Download from ngrok.com or:
Add webhook endpoint in Stripe
In Stripe Dashboard:
- Go to Developers → Webhooks
- Add endpoint:
https://abc123.ngrok.io/api/webhooks/stripe - Select events
- Copy the signing secret
Monitoring Webhooks
Stripe Dashboard
Monitor webhook delivery in Stripe:- Go to Developers → Webhooks
- Click on your endpoint
- View:
- Recent deliveries
- Success/failure rate
- Response times
- Error details
Application Logs
Mantlz logs all webhook events:Failed Webhook Retry
Stripe automatically retries failed webhooks:- Immediate retry
- 1 hour later
- 2 hours later
- Up to 3 days of retries
Ensure your webhook endpoint returns a 200 status code within 5 seconds to prevent retries.
Webhook Response Format
Always return a success response:Security Best Practices
Keep signing secrets secure
- Never commit secrets to version control
- Use environment variables
- Rotate secrets periodically
Troubleshooting
Webhook signature verification fails
Webhook signature verification fails
- Verify
STRIPE_WEBHOOK_SECRETis set correctly - Ensure you’re using the raw request body (not parsed JSON)
- Check that the secret matches your environment (test vs production)
- Verify the endpoint URL in Stripe matches your deployment
Webhooks not being received
Webhooks not being received
- Check Stripe dashboard for delivery attempts and errors
- Verify endpoint URL is correct and accessible
- Ensure HTTPS is used in production
- Check firewall rules allow Stripe IPs
- Verify the endpoint returns 200 status
Duplicate webhook processing
Duplicate webhook processing
Implement idempotency checks using event IDs:
Webhooks timing out
Webhooks timing out
- Ensure processing completes within 5 seconds
- Move long-running tasks to background jobs
- Return 200 response immediately, process async
- Optimize database queries
Local testing not working with Stripe CLI
Local testing not working with Stripe CLI
- Ensure Stripe CLI is authenticated:
stripe login - Check local server is running on correct port
- Verify webhook secret from CLI is in
.env.local - Restart dev server after changing environment variables
Advanced: Custom Webhooks
Mantlz also supports custom webhook endpoints for form submissions:Payload Format
Verification
Custom webhooks include an HMAC signature:Next Steps
Integrations
Learn about Stripe and other integrations
Environment Setup
Configure environment variables
API Reference
Explore the Mantlz API
Self-Hosting
Deploy Mantlz with Docker