Webhooks

Overview

Paychant webhooks allow you to get automatic updates anytime the status on your widget instance changes.

The webhook will be called when the transaction reaches the processing status and also when it is complete. Once configured, your URL will receive notifications for the PROCESSING, COMPLETE, and FAILED statuses.

Once Webhook as been created, you can monitor all past and present event details in the logs.

Receiving Event

To start receiving event, you need to create unauthenticated POST route on your application.

const crypto = require('crypto');
const secret = process.env.SECRET_KEY; // Your paychant webhook secret

// Using Express
router.post("/webhook/url", function(req, res) {
    
   res.sendStatus(200); // Return status code 200 quickly

   // Validate event 
   const hmac = crypto.createHmac('sha512', secret);
   const hash = hmac.update(JSON.stringify(req.body)).digest('hex');
   const headerSig = req.headers['paychant-signature'];

   if (hash === headerSig) {
      var event = req.body;
      // Do someting with the event
   }
    
});

Respond Quickly With Status code 2xx

For webhook notification event delivery to be satisfied, your endpoint must return a HTTP status code of 2xx to Paychant. All response codes outside this range, including 3xx codes, indicate to Paychant that you did not receive the event, and thus continue to send the notification event every 30 minutes for 24 hours. After 24 hours Paychant marks the event as failed and stops trying to send it to your endpoint.

Events Response

{
     event: 'WIDGET.CREATED',
     data: {
       env: 'sandbox',
       pid: '8847431020',
       date: '30/03/2023 - 01:46:02',
       fiat: 'NGN',
       asset: 'CUSD',
       chain: 'CELO',
       action: 'BUY',
       fiatAmount: 149241,
       assetAmount: 300,
       userAddress: '0xCd96602dBbeE307a1d50cb074C294847aB4702FB',
       exchangeRate: 497.47,
       paymentMethod: 'Bank Transfer',
       cryptoAddress: '---',
       transactionRef: '7CMJS1Q90GS79AA'
    }
 }

Below is the list of the events when we send the webhook:

Buy (OnRamp)

Event Code Description

CREATED

When the transaction is created.

AWAITING_PAYMENT

When the transaction state is expecting the user to make a payment.

PAYMENT_CONFIRMED

When we have received the fiat payment from the user.

PAYMENT_COMPLETED

When we have received the fiat payment and the crypto is successfully sent to the user.

PAYMENT_INSUFFICIENT

When we received the fiat payment but the amount of fiat sent by the user is not sufficient.

PAYMENT_TIMEOUT

When the user failed to make the fiat payment within the given timeframe.

PAYMENT_FAILED

There are a couple of things that can make a transaction fail, it can either be, a canceled transaction by the user, payment not made within the given timeframe, or a network connection problem.

Sell (OffRamp)

Event CodeDescription

CREATED

When the transaction is created.

AWAITING_PAYMENT

When a wallet address is generated for the user to send the crypto payment.

PAYMENT_CONFIRMED

When the crypto payment is received & the fiat transfer is initiated via our fiat vendor.

PAYMENT_COMPLETED

When the fiat transfer is successfully delivered to the user's bank account or mobile wallet by our fiat vendor.

PAYMENT_INSUFFICIENT

When we received the crypto payment but the amount of crypto sent by the user is not sufficient.

PAYMENT_TIMEOUT

When the user failed to make the crypto payment within the given timeframe.

PAYMENT_FAILED

There are a couple of things that can make a transaction fail, it can either be, a canceled transaction by the user, payment not made within the given timeframe, or a network connection problem.

Last updated