Webhooks allow your application to receive real-time notifications when events occur in your StateSet account, eliminating the need for polling.
๐ Overview
StateSet webhooks are HTTP callbacks that notify your application when specific events occur. Instead of continuously polling our API, you can register webhook endpoints to receive automatic notifications.Key Benefits
Real-time Updates
Receive instant notifications when events occur
Reduced API Calls
Eliminate polling and reduce API usage
Event Reliability
Automatic retries ensure delivery
๐ Quick Start
1
Create Webhook Endpoint
Set up an HTTPS endpoint on your server to receive webhook events:
2
Register Webhook
Register your endpoint with StateSet:
3
Verify Signatures
Verify webhook signatures to ensure authenticity:
๐ Event Types
Payment Events
payment.created
payment.created
Triggered when a new payment is initiated
payment.succeeded
payment.succeeded
Triggered when a payment is successfully completed
payment.failed
payment.failed
Triggered when a payment fails
Stablecoin Events
stablecoin.issued
stablecoin.issued
Triggered when new ssUSD is minted
stablecoin.redeemed
stablecoin.redeemed
Triggered when ssUSD is burned for USD
stablecoin.transferred
stablecoin.transferred
Triggered when ssUSD is transferred
Order Events
order.created
order.created
Triggered when a new order is created
order.paid
order.paid
Triggered when an order is paid
order.fulfilled
order.fulfilled
Triggered when an order is marked as fulfilled
order.cancelled
order.cancelled
Triggered when an order is cancelled
Invoice Events
invoice.created
invoice.created
Triggered when a new invoice is created
invoice.paid
invoice.paid
Triggered when an invoice is paid in full
invoice.partially_paid
invoice.partially_paid
Triggered when a partial payment is made
invoice.overdue
invoice.overdue
Triggered when an invoice becomes overdue
๐ Webhook Security
Signature Verification
All webhook requests include a signature in theX-StateSet-Signature
header. Always verify this signature:
Best Practices
Always Verify Signatures
Always Verify Signatures
Never process webhook events without verifying the signature. This prevents attackers from sending fake events.
Respond Quickly
Respond Quickly
Return a 200 status code as soon as possible. Process events asynchronously if needed:
Handle Duplicates
Handle Duplicates
Webhooks may be sent multiple times. Use the event ID to handle duplicates:
Implement Retry Logic
Implement Retry Logic
Your endpoint should handle retries gracefully. StateSet will retry failed webhooks with exponential backoff.
๐ง Webhook Management
Create a Webhook
List Webhooks
Update a Webhook
Delete a Webhook
Test a Webhook
Send a test event to verify your endpoint is working:๐ Webhook Event Structure
All webhook events follow this structure:Event Fields
Field | Description |
---|---|
id | Unique identifier for the event |
object | Always โeventโ |
type | The type of event (e.g., โpayment.succeededโ) |
created | Unix timestamp of event creation |
data | Event-specific data object |
request | Details about the API request that triggered the event |
pending_webhooks | Number of webhooks yet to be delivered |
api_version | API version used for this event |
๐ Retry Logic
StateSet automatically retries failed webhook deliveries with exponential backoff:Attempt | Delay | Total Time |
---|---|---|
1 | Immediate | 0 seconds |
2 | 10 seconds | 10 seconds |
3 | 1 minute | 1.2 minutes |
4 | 10 minutes | 11.2 minutes |
5 | 1 hour | 1.2 hours |
6 | 3 hours | 4.2 hours |
7 | 12 hours | 16.2 hours |
Handling Failures
Monitor webhook failures through the dashboard or API:๐งช Testing Webhooks
Local Development
Use ngrok to test webhooks locally:Webhook Testing Tool
Use our webhook testing tool in the dashboard:- Navigate to Webhooks โ Testing
- Select an event type
- Customize the payload
- Send test event
Unit Testing
Mock webhook events in your tests:๐ Monitoring & Debugging
Webhook Logs
View detailed logs for all webhook attempts:Metrics
Track webhook performance:Debug Mode
Enable debug mode for verbose logging:๐จ Common Issues
Webhook Not Receiving Events
Webhook Not Receiving Events
Checklist:
- Verify the webhook URL is correct and publicly accessible
- Check that SSL certificate is valid (HTTPS required)
- Ensure the webhook is active
- Verify event types are subscribed
- Check firewall rules allow StateSet IPs
Signature Verification Failing
Signature Verification Failing
Common causes:
- Using wrong webhook secret
- Not using raw request body for signature
- Character encoding issues
- Clock skew (check server time)
Duplicate Events
Duplicate Events
Solutions:
- Store and check event IDs
- Use idempotency keys
- Implement proper deduplication logic
Timeouts
Timeouts
Best practices:
- Respond with 200 immediately
- Process events asynchronously
- Optimize database queries
- Use message queues for heavy processing
๐ IP Allowlist
For enhanced security, allowlist StateSet webhook IPs:IP addresses are subject to change. Subscribe to our changelog for updates.