> For the complete documentation index, see [llms.txt](https://docs.paypangea.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.paypangea.com/webhooks/webhooks.md).

# 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:

```json
{
  "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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.paypangea.com/webhooks/webhooks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
