A webhook allows your application to receive notifications when updates are made on your account on Payant. Webhook update notifications are sent as POST requests to a callback URL that you supply.
The Payant Dashboard Settings to setup a webhook subscription. You will be required to specify:
Webhook URL - a URL to your endpoint that can process both verification and notification requests.
Verify Token - a string that you supply which we will include whenever we send a verification request.
You need to setup a webhook endpoint before you setup a subscription to it on Payant. Your endpoint must be HTTPs and must be able to receive both GET and POST requests.
If you need help setting up HTTPs on your endpoint, check out the Getting Started Guide from Let's Encrypt
We'll send a GET request while setting up your webhook. The request will include the following parameters appended to the end of your webhook URL.
type=subscribe
challenge
- A random string
verify_token
- a string that you supply to setup the webhook
When your endpoint receives the verification request, it must:
Verify that the verify_token
corresponds to the token your supplied when setting up your webhook.
Respond with the challenge
value.
Whenever their are changes on your account, we will send a POST request to your webhook endpoint. The request will have a JSON payload as follows:
type
- Notification type
data
- An array containing the notification data
We have created an example Node.js server for you to get started quickly.
​node-webhook-example by PayantNG​
{"name": "node-webhook-example","version": "1.0.0","description": "Webhook Example Node Server for Payant.ng","main": "webhook.js","scripts": {"start": "node webhook.js"},"author": "Payant Support <[email protected]>","license": "ISC","dependencies": {"body-parser": "^1.17.2","express": "^4.15.3"}}
/*** Webhook Server** @author Payant Support <[email protected]>* @version 1.0.0*/​const express = require('express');const bodyParser = require('body-parser');let app = express();​app.use(bodyParser.json());​app.get('/webhook', (req, res) => {if(req.query.type === 'subscribe' && req.query.verify_token === 'VerifyToken') {console.log("Token validation successful.");res.status(200).send(req.query.challenge);}else {console.error("Token validation failed. Make sure the validation tokens match.");res.sendStatus(403);}});​app.post('/webhook', (req, res) => {var data = req.body;​console.log("Data received: ", data);​//Lastly send back a 200res.sendStatus(200);})​app.listen(process.env.PORT || 8005);