Documentation
  • INTRODUCTION 🤝
    • 👋 Welcome to Paychant
    • Getting started with Paychant 🚀
  • INTEGRATIONS ⛓
    • Integration options
    • Redirect Integration
    • Overlay Embed
    • Parameters
    • Testing Environment
  • RESOURCES
    • Api Keys
    • Webhooks
    • Supported Fiat Currency
    • Supported Stablecoins
  • API Reference
    • Rest API Reference
Powered by GitBook
On this page
  • Overview
  • Receiving Event
  • Respond Quickly With Status code 2xx
  • Events Response

Was this helpful?

  1. RESOURCES

Webhooks

PreviousApi KeysNextSupported Fiat Currency

Last updated 7 months ago

Was this helpful?

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
   }
    
});
<?php

// Only a post method and headers that contain paychant-signature will be allowed
if ((strtoupper($_SERVER['REQUEST_METHOD']) != 'POST' ) || !array_key_exists('paychant-signature', $_SERVER) ) {
    exit();
}

// Retrieve the request's body
$input = @file_get_contents("php://input");

// SET the SECRET KEY
define('PAYCHANT_WEBHOOK_SECRET_KEY','SECRET_KEY');

// Validate event
if($_SERVER['HTTP_PAYCHANT_SIGNATURE'] !== hash_hmac('sha512', $input, PAYCHANT_WEBHOOK_SECRET_KEY)){
    exit();
}

// Return status code 200 quickly
http_response_code(200);

// Do someting with the event
$event = json_decode($input);

exit();
?>php
import os
from flask import Flask, request, Response
import hmac
import hashlib
import urllib.parse

app = Flask(__name__)
secret = os.environ.get('SECRET_KEY') # Your paychant webhook secret

@app.route('/webhook', methods=['POST'])
def respond():
    
    # Validate event 
    encode = urllib.parse.urlencode(request.json).encode('utf8')
    hashMac = hmac.new(secret, encode, hashlib.sha512).hexdigest()
    headerSig = request.headers.get('paychant-signature')
    
    if(hashMac === headerSig):
        event = request.json; # Do someting with the event
        return Response(status=200)

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'
    }
 }
{
     event: 'WIDGET.AWAITING_PAYMENT',
     data: {
       env: 'sandbox',
       pid: '8847431020',
       date: '30/03/2023 - 01:57:57',
       fiat: 'NGN',
       asset: 'CUSD',
       chain: 'CELO',
       action: 'BUY',
       fiatAmount: 149241,
       assetAmount: 300,
       userAddress: '0xCd96602dBbeE307a1d50cb074C294847aB4702FB',
       exchangeRate: 497.47,
       paymentMethod: 'Bank Transfer',
       cryptoAddress: '---',
       transactionRef: '7CMJS1Q90GS79AA'
    }
 }
{
     event: 'WIDGET.PAYMENT_CONFIRMED',
     data: {
       env: 'sandbox',
       pid: '8847431020',
       date: '30/03/2023 - 02:09:40',
       fiat: 'NGN',
       asset: 'CUSD',
       chain: 'CELO',
       action: 'BUY',
       fiatAmount: 149241,
       assetAmount: 300,
       userAddress: '0xCd96602dBbeE307a1d50cb074C294847aB4702FB',
       exchangeRate: 497.47,
       paymentMethod: 'Bank Transfer',
       cryptoAddress: '---',
       transactionRef: '7CMJS1Q90GS79AA'
    }
 }
{
     event: 'WIDGET.PAYMENT_COMPLETED',
     data: {
       env: 'sandbox',
       pid: '8847431020',
       date: '30/03/2023 - 02:15:40',
       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 asset 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 Code
Description

CREATED

When the transaction is created.

AWAITING_PAYMENT

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

PAYMENT_CONFIRMED

When the asset 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 asset payment but the amount of asset sent by the user is not sufficient.

PAYMENT_TIMEOUT

When the user failed to make the asset 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.