API Documentation
Webhooks API
Receive real-time notifications about important events in your PayDirect account.
What are Webhooks?
Webhooks allow your application to receive real-time HTTP POST notifications when certain events occur in your PayDirect account, such as payment status changes, wallet updates, or agent actions.
Webhooks are essential for integrating PayDirect with your backend systems and automating workflows.
Registering Webhook Endpoints
You can register and manage webhook endpoints in your Developer Dashboard.
- Go to the Webhooks section in the dashboard
- Click "Add Endpoint"
- Enter your endpoint URL and select the events you want to subscribe to
- Save your changes
Event Types
You can subscribe to the following event types:
| Event | Description |
|---|---|
| payment.created | Triggered when a new payment request is created |
| payment.updated | Triggered when a payment status changes |
| wallet.created | Triggered when a new wallet is created |
| wallet.balance.updated | Triggered when a wallet's balance changes |
| agent.created | Triggered when a new agent is registered |
| agent.updated | Triggered when an agent is updated |
Example Webhook Payload
Webhook requests are sent as JSON in the POST body. Here’s an example for a payment update:
json
{
"event": "payment.updated",
"data": {
"paymentId": "pay_abc123",
"status": "completed",
"amount": "0.5",
"currency": "ETH",
"updatedAt": "2024-03-20T12:00:00Z"
}
}Security & Verification
Each webhook request includes a X-PayDirect-Signature header. Use this to verify the authenticity of the request:
javascript
// Example: Verifying the signature in Node.js
const crypto = require('crypto');
const signature = req.headers['x-paydirect-signature'];
const payload = JSON.stringify(req.body);
const secret = process.env.PAYDIRECT_WEBHOOK_SECRET;
const expected = crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex');
if (signature !== expected) {
// Reject the request
}Never expose your webhook secret. Always verify the signature before processing the event.
Error Handling & Retries
If your endpoint does not return a 2xx status code, PayDirect will retry the webhook up to 5 times with exponential backoff.
- Return a 2xx status code to acknowledge receipt
- Retries occur at increasing intervals (e.g., 1m, 5m, 15m, 1h, 3h)
- After 5 failed attempts, the webhook will be marked as failed