Merchants can configure webhook endpoints through their dashboard to receive notifications when specific events occur. When configured events happen, CashPay will send notifications in JSON format with all required information about the transaction, such as the amount and status.

Setting Up Webhooks

  1. Navigate to the Webhooks section in your CashPay dashboard
  2. Click “Add Webhook Endpoint”
  3. Enter your endpoint URL where you want to receive notifications
  4. Select the events you want to subscribe to (e.g., PAYMENT_CREATED, PAYMENT_COMPLETED)
  5. Save the webhook configuration to receive your unique Webhook Secret Key

Each webhook endpoint can be configured independently with its own secret key and event subscriptions. You can add multiple endpoints and manage them through the dashboard.

The webhook endpoint must return an HTTP Response 200 with content: ok for CashPay API to confirm the callback as successful. The system will try to deliver a webhook notification up to 5 times or until a successful delivery occurs, whichever happens first. If the first attempt fails, the second one is triggered after approximately 1 minute. The third one is delayed for 3 more minutes, the fourth for 30 minutes, and the last one for 3 hours.

Webhook Security

Each webhook endpoint has its own Webhook Secret Key that’s generated when you create the endpoint. This key should be used to validate incoming webhooks using HMAC(sha512) signatures. CashPay sends the signature in the HMAC HTTP header of each request.

Validating Callbacks

Merchants must validate the signature of callbacks coming from CashPay using their Webhook Secret Key created when the webhook was set up in the dashboard. CashPay uses your Webhook Secret Key as the HMAC shared secret key to generate an HMAC(sha512) signature of the raw POST data. The HMAC signature is sent as an HTTP header called HMAC. The body of the request contains the callback data in JSON format, similar to the Payment Information API response body.

Testing Webhook

For payment callback handling, you can use tools like requestcatcher.com to create a test endpoint URL and inspect the callback data sent from CashPay. Note that CashPay payment callbacks will not be sent to private networks (e.g., localhost).

For local debugging, you can use services like https://ngrok.io to expose your local server to the internet and receive webhook callbacks.

To utilize the payment webhook, please follow these steps:

  1. Create a web server and define an endpoint to handle POST requests.

    • Ensure that the firewall software on your server (e.g., Cloudflare) allows incoming requests from CashPay. You may need to whitelist CashPay’s IP addresses on your side. Please reach out to support@CashPay.com to obtain the list of IP addresses.
  2. Configure your server to receive POST requests at the specified endpoint URL.

    • The POST request body will contain the necessary parameters sent by CashPay in JSON format.
  3. Validate the HMAC signature of the request to ensure the authenticity of the callback.

    • Use your MERCHANT_API_KEY to calculate the HMAC signature and compare it with the received HMAC header.
  4. Process the callback data accordingly based on the status and other parameters provided.

Sample Payment IPN data

In this section, we will provide examples of the data CashPay send to your system at various stages of the payment process.

Example codes

Again, please note that these code snippets serve as examples and may require modifications based on your specific implementation and framework.

Troubleshooting

Here are some common issues you might encounter when implementing webhooks and how to solve them:

If you’re still experiencing issues after trying these solutions, please contact our support team at support@cashpay.space for further assistance.