đŸĒWebhooks

Integrating webhooks into your PayPangea payment flow allows your application to react in real-time to events such as payment confirmations. This section details how to set up and utilize webhooks for receiving transaction status updates.

Handling Webhook Notifications

When a relevant event occurs, PayPangea will send a POST request to your webhook endpoint with a JSON payload containing details about the event. For transaction events, the payload will look like this:

{
  "tkn": "unique_transaction_identifier",
  "merchantid": "your_merchant_id",
  "status": "OK" // or "FAIL"
}
  • tkn: This is the transaction's unique identifier.

  • merchantid: Your unique merchant ID that yoou send when initiated the payment.

  • status: Indicates the transaction's status, which can be "OK" for successful transactions or "FAIL" for unsuccessful ones.

Receiving and Processing Webhook Data

On your server, you'll need to set up a route that matches your configured endpoint URL to handle incoming POST requests. Here's an example of how you might process the received webhook data:

app.post('/your-webhook-endpoint', async (req, res) => {
  const { tkn, merchantid, status } = req.body;

  if(status === 'OK') {
    // Handle successful transaction
    // Update your database, send confirmation emails, etc.
  } else {
    // Handle failed transaction
    // Log the error, inform the customer, etc.
  }

  res.status(200).send('Webhook received');
});

Best Practices

  • Validation: Always validate the received data to ensure it matches the expected format and comes from PayPangea.

  • Security: Use HTTPS for your endpoint to ensure encrypted communication. Additionally, implement measures to verify the authenticity of the incoming requests.

  • Error Handling: Implement robust error handling to gracefully manage failures or unexpected data in webhook notifications.

Conclusion

Webhooks are a powerful tool for automating real-time reactions to payment events in your application. By following the steps outlined above, you can seamlessly integrate PayPangea webhooks into your payment flow, enhancing the reliability and user experience of your service.

Last updated