Handling Webhooks
Learn how to securely process Fenan Pay webhook notifications
Webhooks are a crucial component of the Fenan Pay system, allowing real-time notifications of transaction events to be sent directly to your server. This guide will walk you through the process of handling these webhook notifications securely and efficiently.
Webhooks are POST requests sent from Fenan Pay to your server, containing important transaction status updates.
Event Types
Fenan Pay sends different types of webhook events based on the transaction status:
Payment Events
payment_success
payment_failed
payment_expired
Withdrawal Events
withdrawal_success
withdrawal_failed
Webhook Payload Structure
The webhook payload contains a transaction event object with the following key components:
Field | Type | Description |
---|---|---|
signature | string | A cryptographic signature to verify the payload’s authenticity. |
body | String | Contains either a PaymentIntent or WithdrawalIntent Json string, depending on the event type. You need to parse this string to get the actual object. |
event | string | Specifies the type of webhook notification. which will be found inside the body object. |
Always verify the webhook signature to ensure the body’s integrity and authenticity. Read more about verifying webhook signatures.
Example Webhook Events
Success Transaction
Success Withdrawal
Acknowledging Webhooks
To properly acknowledge receipt of a webhook, your server must respond with:
200
text/plain
SUCCESS
Fenan Pay will retry the webhook up to 3 times at 2-minute intervals if not properly acknowledged.
Best Practices
- Verify signatures: Always verify the webhook signature before processing the payload.
- Process asynchronously: Handle webhook processing in the background to respond quickly.
- Idempotency: Design your webhook handler to be idempotent to safely handle potential duplicate events.
- Logging: Maintain detailed logs of received webhooks for troubleshooting and auditing.
Example Webhook Handler
Here’s a basic example of a webhook handler in Node.js:
Webhook Log
You can track how your server is handling webhooks in the Fenan Pay dashboard. This is very important for debugging and ensuring that your webhook processing is functioning correctly.
By following these guidelines, you’ll ensure robust and secure handling of Fenan Pay webhooks, keeping your system in sync with the latest transaction statuses.