Receive real-time notifications about payment events and status changes.
Instead of polling the API to check payment status, webhooks automatically send HTTP POST requests to your server when events occur. This provides real-time updates and reduces API calls.
Example: When a payment is completed, PayFlow immediately sends a webhook to your server with the payment details, so you can update your database and notify your customer.
Payment was completed successfully
Triggers when payment status changes to COMPLETED
Payment processing failed
Triggers when payment status changes to FAILED
Payment was cancelled by customer
Triggers when payment status changes to CANCELLED
New customer was created
Triggers when a new customer is added
Each webhook contains event information and the associated data:
{ "id": "evt_1234567890", "type": "payment.succeeded", "created_at": "2024-01-15T10:30:00Z", "data": { "id": "pay_1234567890", "amount": 2500, "currency": "PKR", "status": "completed", "customer_email": "customer@example.com", "provider": "payfast", "provider_ref": "PF123456789" } }
id
- Unique event identifiertype
- Event type (e.g., payment.succeeded)created_at
- When the event occurreddata
- Event-specific dataamount
- Payment amount in smallest currency unitcurrency
- Three-letter currency codestatus
- Current payment statusprovider_ref
- Provider's reference numberCreate a webhook endpoint in your application that can receive HTTP POST requests:
// Express.js example app.post('/webhooks/payflow', (req, res) => { const event = req.body; // Handle the webhook event handleWebhookEvent(event); // Respond with 200 to acknowledge receipt res.json({ received: true }); });
Always verify webhook signatures to ensure they come from PayFlow:
const crypto = require('crypto'); function verifyWebhookSignature(payload, signature, secret) { const expectedSignature = crypto .createHmac('sha256', secret) .update(JSON.stringify(payload)) .digest('hex'); return crypto.timingSafeEqual( Buffer.from(signature), Buffer.from(expectedSignature) ); }
Webhook endpoints must use HTTPS to ensure data security. PayFlow will not send webhooks to HTTP endpoints.
Implement idempotency to handle duplicate webhook deliveries safely. Use the event ID to prevent processing the same event multiple times.
Use the webhook testing tool in your PayFlow dashboard to send test webhooks to your endpoint:
For local development, use tools like ngrok to expose your local server to the internet:
# Install ngrok npm install -g ngrok # Expose your local server ngrok http 3000 # Use the HTTPS URL provided by ngrok in your webhook endpoint