Configuration
Add webhook secret to environment
Add your webhook signing secret to your
.env file. You can find this secret in your Lettermint dashboard under the Webhooks section:Optional: Configure webhook settings
You can optionally customize the webhook route prefix and timestamp tolerance:Or publish and modify the config file:Then update
config/lettermint.php:Configuration Options
Webhook Secret
The signing secret used to verify incoming webhook requests. This ensures that the webhook payload is from Lettermint and hasn’t been tampered with.Route Prefix
The route prefix for the webhook endpoint. The full URL will be:lettermint (results in /lettermint/webhook)
Timestamp Tolerance
The maximum allowed time difference (in seconds) between the webhook timestamp and the current time. This helps prevent replay attacks. Default:300 (5 minutes)
A tolerance of 300 seconds (5 minutes) is recommended for most applications. This accounts for clock skew while still providing protection against replay attacks.
Signature Verification
The package automatically verifies webhook signatures using theVerifyWebhookSignature middleware. This middleware:
- Extracts the webhook secret from your configuration
- Validates the signature headers against the request payload
- Checks that the timestamp is within the configured tolerance
- Returns a 401 Unauthorized response if verification fails
Webhook class:
Signature verification happens automatically. You don’t need to write any verification code yourself.
Testing Your Webhook
Once configured, you can test your webhook endpoint from the Lettermint dashboard. This will send awebhook.test event to your endpoint to verify it’s working correctly.
You can also listen for test events in your application:
Troubleshooting
401 Unauthorized Responses
If your webhook endpoint is returning 401 responses:- Verify that
LETTERMINT_WEBHOOK_SECRETis set correctly in your.envfile - Check that the secret matches the one in your Lettermint dashboard
- Ensure your server’s clock is synchronized (timestamp tolerance may be exceeded)
Webhook Not Receiving Events
- Verify the webhook URL is configured correctly in your Lettermint dashboard
- Check that your application is publicly accessible (webhooks can’t reach localhost)
- Review your application logs for errors
- Ensure CSRF protection is disabled for the webhook route (automatically handled by the package)