Chargebee webhooks
Receive and verify Chargebee webhooks. Use when setting up Chargebee webhook handlers, debugging Basic Auth verification, or handling subscription billing events.From its SKILL.md
npx -y skills add hookdeck/webhook-skills --skill chargebee-webhooksAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- reads credentialsReads from 2 credential sources: `CHARGEBEE_WEBHOOK_USERNAME` and 1 more.
- runs commandsInstructs the agent to run 1 command, including `npx hookdeck-cli listen 3000 chargebee --path /webhooks/chargebee`.
What its file declares
Copied from the file, not written here
The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
9.9 KB, ~2.2k tokens by cl100k_base, as published. Nobody here has run it
Chargebee Webhooks
When to Use This Skill
- Setting up Chargebee webhook handlers
- Debugging Basic Auth verification failures
- Understanding Chargebee event types and payloads
- Processing subscription billing events
Essential Code
Chargebee uses Basic Authentication for webhook verification. Here's how to implement it:
Express.js
// Verify Chargebee webhook with Basic Auth
// NOTE: Chargebee uses Basic Auth (not HMAC signatures), so raw body access
// is not required. Use express.json() for automatic JSON parsing:
app.post('/webhooks/chargebee', express.json(), (req, res) => {
// Extract Basic Auth credentials
const auth = req.headers.authorization;
if (!auth || !auth.startsWith('Basic ')) {
return res.status(401).send('Unauthorized');
}
// Decode and verify credentials
const encoded = auth.substring(6);
const decoded = Buffer.from(encoded, 'base64').toString('utf-8');
const [username, password] = decoded.split(':');
const expectedUsername = process.env.CHARGEBEE_WEBHOOK_USERNAME;
const expectedPassword = process.env.CHARGEBEE_WEBHOOK_PASSWORD;
if (username !== expectedUsername || password !== expectedPassword) {
return res.status(401).send('Invalid credentials');
}
// Access the parsed JSON directly
const event = req.body;
console.log(`Received ${event.event_type} event:`, event.id);
// Handle specific event types
switch (event.event_type) {
case 'subscription_created':
case 'subscription_changed':
case 'subscription_cancelled':
// Process subscription events
break;
case 'payment_succeeded':
case 'payment_failed':
// Process payment events
break;
}
res.status(200).send('OK');
});
// Note: If you later need raw body access (e.g., for HMAC signature
// verification with other providers), use express.raw():
// app.post('/webhooks/other', express.raw({ type: 'application/json' }), (req, res) => {
// const rawBody = req.body.toString();
// // ... verify signature using rawBody ...
// });
Next.js (App Router)
// app/webhooks/chargebee/route.ts
import { NextRequest } from 'next/server';
export async function POST(req: NextRequest) {
// Extract Basic Auth credentials
const auth = req.headers.get('authorization');
if (!auth || !auth.startsWith('Basic ')) {
return new Response('Unauthorized', { status: 401 });
}
// Decode and verify credentials
const encoded = auth.substring(6);
const decoded = Buffer.from(encoded, 'base64').toString('utf-8');
const [username, password] = decoded.split(':');
const expectedUsername = process.env.CHARGEBEE_WEBHOOK_USERNAME;
const expectedPassword = process.env.CHARGEBEE_WEBHOOK_PASSWORD;
if (username !== expectedUsername || password !== expectedPassword) {
return new Response('Invalid credentials', { status: 401 });
}
// Process the webhook
const event = await req.json();
console.log(`Received ${event.event_type} event:`, event.id);
return new Response('OK', { status: 200 });
}
FastAPI
# main.py
from fastapi import FastAPI, Header, HTTPException, Depends
from typing import Optional
import base64
import os
app = FastAPI()
def verify_chargebee_auth(authorization: Optional[str] = Header(None)):
"""Verify Chargebee webhook Basic Auth"""
if not authorization or not authorization.startswith("Basic "):
raise HTTPException(status_code=401, detail="Unauthorized")
# Decode credentials
encoded = authorization[6:]
decoded = base64.b64decode(encoded).decode('utf-8')
# Split username:password (handle colons in password)
if ':' not in decoded:
raise HTTPException(status_code=401, detail="Invalid authorization format")
colon_index = decoded.index(':')
username = decoded[:colon_index]
password = decoded[colon_index + 1:]
expected_username = os.getenv("CHARGEBEE_WEBHOOK_USERNAME")
expected_password = os.getenv("CHARGEBEE_WEBHOOK_PASSWORD")
if username != expected_username or password != expected_password:
raise HTTPException(status_code=401, detail="Invalid credentials")
return True
@app.post("/webhooks/chargebee")
async def handle_chargebee_webhook(
event: dict,
auth_valid: bool = Depends(verify_chargebee_auth)
):
"""Handle Chargebee webhook events"""
event_type = event.get("event_type")
print(f"Received {event_type} event: {event.get('id')}")
# Process event based on type
if event_type in ["subscription_created", "subscription_changed", "subscription_cancelled"]:
# Handle subscription events
pass
elif event_type in ["payment_succeeded", "payment_failed"]:
# Handle payment events
pass
return {"status": "OK"}
Common Event Types
⚠️ WARNING: Verify Event Names!
The event type names below are examples and MUST be verified against the Chargebee API documentation for your specific Chargebee configuration. Event names can vary significantly between API versions and configurations.
Special attention required for:
- Payment events (shown as
payment_succeededandpayment_failedbelow)- Invoice events (shown as
invoice_generatedbelow)- Any custom events specific to your Chargebee setup
Always check your Chargebee Webhook settings for the exact event names your account uses.
| Event | Triggered When | Common Use Cases |
|---|---|---|
subscription_created | New subscription is created | Provision access, send welcome email |
subscription_changed | Subscription is modified | Update user permissions, sync changes |
subscription_cancelled | Subscription is cancelled | Revoke access, trigger retention flow |
subscription_reactivated | Cancelled subscription is reactivated | Restore access, send notification |
payment_succeeded | Payment is successfully processed | Update payment status, send receipt |
payment_failed | Payment attempt fails | Retry payment, notify customer |
invoice_generated | Invoice is created | Send invoice to customer |
customer_created | New customer is created | Create user account, sync data |
Environment Variables
# Chargebee webhook Basic Auth credentials
CHARGEBEE_WEBHOOK_USERNAME=your_webhook_username
CHARGEBEE_WEBHOOK_PASSWORD=your_webhook_password
Local Development
For local webhook testing, use Hookdeck CLI:
npx hookdeck-cli listen 3000 chargebee --path /webhooks/chargebee
No account required. Provides local tunnel + web UI for inspecting requests.
Reference Materials
- Overview - What Chargebee webhooks are, common event types
- Setup - Configure webhooks in Chargebee dashboard
- Verification - Basic Auth verification details and gotchas
Examples
- Express Example - Complete Express.js implementation with tests
- Next.js Example - Next.js App Router implementation with tests
- FastAPI Example - Python FastAPI implementation with tests
Recommended: webhook-handler-patterns
We recommend installing the webhook-handler-patterns skill alongside this one for handler sequence, idempotency, error handling, and retry logic. Key references (open on GitHub):
- Handler sequence — Verify first, parse second, handle idempotently third
- Idempotency — Prevent duplicate processing
- Error handling — Return codes, logging, dead letter queues
- Retry logic — Provider retry schedules, backoff patterns
Related Skills
- stripe-webhooks - Stripe payment webhook handling
- shopify-webhooks - Shopify e-commerce webhook handling
- github-webhooks - GitHub repository webhook handling
- resend-webhooks - Resend email webhook handling
- clerk-webhooks - Clerk auth webhook handling
- elevenlabs-webhooks - ElevenLabs webhook handling
- openai-webhooks - OpenAI webhook handling
- paddle-webhooks - Paddle billing webhook handling
- webhook-handler-patterns - Handler sequence, idempotency, error handling, retry logic
- hookdeck-event-gateway - Webhook infrastructure that replaces your queue — guaranteed delivery, automatic retries, replay, rate limiting, and observability for your webhook handlers
What ships with it: 25 files
51.6 KB alongside SKILL.md, 9 of them executable
examples/
- express/.env.example263 B
- express/jest.config.jsruns159 B
- express/package.json489 B
- express/README.md1.5 KB
- express/src/index.jsruns3.9 KB
- express/test/webhook.test.jsruns5.9 KB
- fastapi/.env.example227 B
- fastapi/main.pyruns4.4 KB
- fastapi/README.md1.7 KB
- fastapi/requirements.txt104 B
- fastapi/test_webhook.pyruns6.6 KB
- nextjs/app/layout.tsx168 B
- nextjs/app/page.tsx743 B
- nextjs/app/webhooks/chargebee/route.tsruns3.3 KB
- nextjs/.env.example227 B
- nextjs/next.config.jsruns93 B
- nextjs/package.json571 B
- nextjs/README.md1.7 KB
- nextjs/test/webhook.test.tsruns6.6 KB
- nextjs/tsconfig.json643 B
- nextjs/vitest.config.tsruns137 B
references/
- overview.md3.2 KB
- setup.md3.1 KB
- verification.md5.3 KB
- TODO.md567 B
Gives 0 of the 12 instructions most quality gates skills give in ~2.2k tokens
Counted across 1,524 of the 2,830 authors here whose files we hold, read 2026-09-06
- Read full output and check exit codein 45 of 1524, across 40 files
- Verify output confirms the claimin 44 of 1524, across 39 files
- Identify the command that proves the claimin 43 of 1524, across 39 files
- Execute the full verification commandin 36 of 1524, across 30 files
- Produce a verification reportin 34 of 1524, across 18 files
- Review git diff changesin 30 of 1524, across 16 files
- Fix build failures immediatelyin 29 of 1524, across 9 files
- Group findings by severityin 28 of 1524
- State claim only with evidencein 27 of 1524, across 22 files
- Verify regression tests with red-green cyclein 26 of 1524, across 22 files
- Run the full test suitein 26 of 1524, across 25 files
- Run test suite with coveragein 25 of 1524, across 10 files
Said here and by no other author read
- Use hookdeck-cli for local development
- Use Basic Authentication for webhook verification
- Store credentials in environment variables
- Verify event names against Chargebee documentation
- Return 401 status for unauthorized requests
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.