Stripe to Discord Notification Automation
This Val Town script creates a webhook endpoint that receives Stripe events and forwards them as nicely formatted notifications to a Discord channel.
- Receives and verifies Stripe webhook events
- Formats different event types into readable Discord messages
- Supports multiple event types (payments, subscriptions, invoices)
- Color-coded notifications based on event type
- Secure webhook signature verification
- Open your Discord server
- Go to Server Settings > Integrations > Webhooks
- Click "New Webhook"
- Name your webhook (e.g., "Stripe Notifications")
- Choose which channel to post to
- Copy the webhook URL
2. Val Town Environment Variables
Add the following environment variables to your Val Town account:
DISCORD_WEBHOOK_URL: The Discord webhook URL you copied
STRIPE_WEBHOOK_SECRET: Your Stripe webhook signing secret (you'll get this in the next step)
3. Stripe Webhook Configuration
- Log in to your Stripe Dashboard
- Go to Developers > Webhooks
- Click "Add endpoint"
- Enter the URL of this Val (copy it from the "Endpoint URL" in Val Town)
- Select the events you want to receive notifications for:
charge.succeeded
customer.subscription.created
customer.subscription.updated
customer.subscription.deleted
invoice.paid
invoice.payment_failed
- (Add more as needed)
- Click "Add endpoint"
- Reveal and copy the signing secret
- Add this as the
STRIPE_WEBHOOK_SECRET environment variable in Val Town
You can customize this automation by:
- Adding more event types to the
SUPPORTED_EVENTS array
- Modifying the formatting logic in
formatStripeEventForDiscord()
- Changing the color scheme in the
COLORS object
- Check the Val Town logs for any errors
- Verify that your webhook secret is correct
- Make sure your Discord webhook URL is valid
- Test with Stripe's webhook testing tool
- Never share your Stripe webhook secret
- The webhook verification ensures that only Stripe can trigger notifications