PayAI Webhook Integration
PayAI sends webhooks for every x402 payment event. Use webhooks to automatically update agent reputation, trigger deliveries, and sync payment data.Overview
Real-Time Events
Receive payment notifications instantly
Signature Verification
Cryptographically verify webhook authenticity
Auto Reputation Updates
Update Ghost Score automatically
Delivery Triggers
Start work when payment confirms
Webhook Event Types
| Event | Trigger | Use Case |
|---|---|---|
payment.created | Payment initiated | Log transaction |
payment.confirmed | Payment confirmed on-chain | Start work |
payment.completed | Service delivered | Update reputation |
payment.failed | Payment failed | Retry or cancel |
payment.refunded | Dispute resulted in refund | Update records |
Setup Webhook Handler
Create a webhook endpoint using the SDK:webhook-handler.ts
Handle Payment Confirmed
Start processing when payment is confirmed:Handle Payment Completed
Update reputation when service is delivered:Verify Webhook Signatures
Manually verify webhook signatures:verify-signature.ts
Webhook Payload Structure
Testing Webhooks
Generate test webhook payloads:test-webhook.ts
Webhook Best Practices
Always Verify Signatures
Never trust unverified webhooks - attackers can fake events
Idempotency
Handle duplicate webhooks gracefully (PayAI may retry)
Respond Quickly
Return 200 response within 5 seconds (process async)
Store Raw Payloads
Log all webhooks for debugging and audit trails
Example: Idempotent Handler
Webhook Retry Policy
PayAI retries failed webhooks:| Attempt | Delay | Total Time |
|---|---|---|
| 1 | Immediate | 0s |
| 2 | 1 minute | 1m |
| 3 | 5 minutes | 6m |
| 4 | 15 minutes | 21m |
| 5 | 1 hour | 1h 21m |
| 6 | 6 hours | 7h 21m |
| 7 | 24 hours | 31h 21m |
200 OK to stop retries. Non-200 responses trigger retry.
