What are Webhooks?
Webhooks are HTTP POST requests that Card2Crypto sends to your server when important events occur, such as when a payment is completed, fails, or is refunded. Instead of repeatedly polling the API to check payment status, webhooks push notifications to you in real-time.Why Use Webhooks?
Real-Time Updates
Get instant notifications the moment a payment completes
Reliable
Automatic retries ensure you don’t miss critical events
Efficient
No need to poll the API - we push updates to you
Secure
HMAC signatures verify webhooks are authentic
How Webhooks Work
Setting Up Webhooks
1. Create an Endpoint
Create an HTTP endpoint on your server that accepts POST requests:2. Configure in Dashboard
- Go to Dashboard > API Keys
- Click on your shop settings
- Enter your webhook URL
- Copy your webhook secret
- Save settings
Use the “Test Webhook” button to verify your endpoint is working correctly.
3. Verify Signatures
Always verify the webhook signature to ensure it’s from Card2Crypto:Webhook Events
Card2Crypto sends webhooks for these events:Event | Description |
---|---|
payment.completed | Payment was successful |
payment.failed | Payment failed |
payment.refunded | Payment was refunded |
Webhook Payload
All webhooks include:Retry Behavior
If your endpoint doesn’t respond with200 OK
, Card2Crypto automatically retries:
- Retry 1: After 2 seconds
- Retry 2: After 4 seconds
- Retry 3: After 8 seconds (final attempt)
Your endpoint must respond within 10 seconds, or the request will timeout.
Best Practices
Return 200 OK Quickly
Return 200 OK Quickly
Process webhooks asynchronously. Return Bad:
200 OK
immediately, then handle the event in the background.Good:Handle Duplicates
Handle Duplicates
You might receive the same webhook multiple times. Implement idempotency:
Log Everything
Log Everything
Keep detailed logs of all webhooks for debugging:
Monitor Failures
Monitor Failures
Check your Dashboard > Webhook Logs regularly for failed deliveries.
Testing Webhooks
Local Development
Use tools like ngrok to expose your local server:Test Webhook Button
Use the “Test Webhook” button in your shop settings to send a test event:Troubleshooting
Webhooks not arriving
Webhooks not arriving
Check:
- Is your webhook URL correct and publicly accessible?
- Is your server running and accepting POST requests?
- Check your firewall settings
- Look for errors in Dashboard > Webhook Logs
Signature verification fails
Signature verification fails
Check:
- Are you using the correct webhook secret?
- Are you JSON.stringify-ing the payload exactly as received?
- Are you using HMAC-SHA256 (not SHA256)?
- Check for middleware that modifies req.body
Webhooks timing out
Webhooks timing out
Fix:
- Return 200 OK immediately
- Process webhooks asynchronously
- Optimize slow database queries
- Remove external API calls from webhook handler