Overview
CrediBill sends webhooks to notify your application of real-time payment and subscription events. All webhooks are signed with HMAC-SHA256 for security verification.Webhook Configuration
Setting Up Webhooks
- Log in to CrediBill dashboard
- Go to Settings → Webhooks
- Enter your webhook URL (must be HTTPS in production)
- Save the webhook secret for signature verification
- Select which events to receive
Webhook URL Requirements
- HTTPS only in production (HTTP allowed for local testing)
- Public accessibility - must be reachable from internet
- Valid SSL certificate - self-signed certificates rejected in production
- Timeout handling - respond within 10 seconds
- Rate handling - handle rapid webhook delivery
Webhook Format
All webhooks are HTTP POST requests with JSON payload:HTTP Headers
Signature Verification
Why Verify Signatures?
- Confirms webhook originated from CrediBill
- Prevents webhook spoofing attacks
- Validates payload integrity
- Protects against man-in-the-middle attacks
Verification Steps
Step 1: Extract Headers
Step 2: Construct Signature Payload
Step 3: Compute HMAC-SHA256
Step 4: Timing-Safe Comparison
Complete Example
Payment Events
payment.success
Sent when a payment completes successfully. Payload:- ✅ Activate/enable customer’s subscription
- ✅ Grant access to features
- ✅ Send confirmation email with receipt
- ✅ Update customer’s billing status to “active”
- ✅ Log successful payment for analytics
payment.failed
Sent when a payment attempt fails. Payload:INSUFFICIENT_FUNDS- Customer doesn’t have enough balanceINVALID_ACCOUNT- Account number/phone invalidDECLINED- Card or account declinedTIMEOUT- Provider timeout (may retry automatically)INVALID_CREDENTIALS- Our credentials rejectedPROVIDER_ERROR- Provider API error (will retry)
- ⚠️ Mark subscription as “past_due”
- ⚠️ Send payment failure email
- ⚠️ Optionally restrict access (depends on your policy)
- ⚠️ Provide payment update link
- ⚠️ Note: CrediBill will auto-retry up to 3 times
Subscription Events
subscription.created
Sent when a new subscription is created. Payload:- ✅ Send welcome email
- ✅ Log in analytics
- ✅ Start trial period countdown (if applicable)
subscription.activated
Sent when subscription becomes active (first payment succeeds or trial ends with successful charge). Payload:- ✅ Grant full access to features
- ✅ Send “subscription active” email
- ✅ Start usage tracking/monitoring
subscription.past_due
Sent when payment fails and subscription enters past-due state. Payload:- ⚠️ Display payment failure notice on customer dashboard
- ⚠️ Send “payment failed” email
- ⚠️ Show “update payment method” prompt
- ⚠️ Optionally reduce feature access
subscription.canceled
Sent when subscription is canceled. Payload:customer_request- Customer requested cancellationpayment_failed- Canceled due to failed payment after retriesadmin_action- Admin canceled subscriptionfraud_detected- Fraud prevention system
- ✅ Revoke all feature access immediately
- ✅ Send cancellation confirmation email
- ✅ Offboard customer data (if applicable)
- ✅ Send “we’re sorry” follow-up email
subscription.expired
Sent when subscription naturally expires (end of term, no renewal). Payload:- ✅ Disable all features
- ✅ Show “subscription expired” message
- ✅ Offer reactivation option
- ✅ Offer downgrade/upgrade options
Invoice Events
invoice.generated
Sent when an invoice is created for a billing period. Payload:- ✅ Store invoice in your system
- ✅ Send invoice to customer (optional - CrediBill can auto-send)
- ✅ Add to customer’s invoice history
- ✅ Track for accounting/reconciliation
invoice.paid
Sent when invoice is fully paid. Payload:- ✅ Update invoice status to “paid” in your system
- ✅ Send payment receipt
- ✅ Update accounting records
- ✅ Clear any past-due notices
invoice.payment_failed
Sent when payment attempt for invoice fails. Payload:- ⚠️ Send payment failure notification
- ⚠️ Show dunning email to customer
- ⚠️ Provide “update payment method” link
- ⚠️ Track failed invoices for reporting
Best Practices
1. Return 200 OK Immediately
2. Handle Idempotency
3. Implement Retry Logic
4. Validate Timestamp
5. Log All Webhooks
Testing Webhooks
Local Development
Use ngrok to expose your local server:https://your-ngrok-url.ngrok.io/webhooks/credibill
Test Mode Webhooks
In test mode, trigger webhooks manually from dashboard:- Go to Dashboard → Webhooks → Test
- Select event type
- Select test data
- Click “Send Test Webhook”
Webhook Logs
View all webhook delivery history:- Go to Dashboard → Webhooks → Logs
- See delivery attempts, timestamps, responses
- Manually retry failed webhooks
- Export logs for analysis
Common Testing Scenarios
Troubleshooting
Webhooks Not Received
Checklist:- Webhook URL is publicly accessible (not localhost)
- HTTPS certificate is valid (not self-signed in production)
- Firewall allows traffic from CrediBill
- No WAF/IP blocking of CrediBill IPs
- Webhook endpoint returns 200 OK
- Endpoint responds within 10 seconds
- Check webhook logs in CrediBill dashboard
- Look for delivery attempts and responses
- Enable verbose logging in your app
- Test endpoint manually with curl
Signature Verification Fails
Common causes:- Using parsed JSON body instead of raw body
- Webhook secret copied incorrectly (extra spaces, wrong env var)
- Timestamp header missing or incorrect
- Not using timing-safe comparison
Duplicate Webhooks
Cause: Network timeouts causing retries Solution: Implement idempotency (see “Best Practices” above)Rate Limits
- 100 webhooks/second per app max
- Failed webhooks retry with exponential backoff
- No limit on total webhooks received
- Delivery timeout: 10 seconds per attempt
Webhook Status Codes
CrediBill expects HTTP 200 for successful delivery. Other codes cause retries:| Code | Meaning | Retry? |
|---|---|---|
| 200 | Success | No |
| 4xx | Client error (except 408) | No |
| 408 | Request timeout | Yes |
| 5xx | Server error | Yes |
| Timeout | No response in 10s | Yes |
Support
- Webhook debugging: Check logs in dashboard
- Signature issues: Contact support with webhook examples
- Delivery problems: Check our status page