Demo
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
stripe-to-discord.ts
https://charmaine--b3a2866a310411f09167569c3dd06744.web.val.run
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
Add the following environment variables to your Val Town account:
DISCORD_WEBHOOK_URL: The Discord webhook URL you copiedSTRIPE_WEBHOOK_SECRET: Your Stripe webhook signing secret (you'll get this in the next step)
- 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.succeededcustomer.subscription.createdcustomer.subscription.updatedcustomer.subscription.deletedinvoice.paidinvoice.payment_failed- (Add more as needed)
- Click "Add endpoint"
- Reveal and copy the signing secret
- Add this as the
STRIPE_WEBHOOK_SECRETenvironment variable in Val Town
You can customize this automation by:
- Adding more event types to the
SUPPORTED_EVENTSarray - Modifying the formatting logic in
formatStripeEventForDiscord() - Changing the color scheme in the
COLORSobject
- 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