Webhooks is an API concept that enables applications to automatically communicate with each other without constant polling. Monnify integration sends notifications to a URL on the merchants’ server when specific events such as when payments are being received or when settlements are made to your account, allowing further actions such as sending an email or providing value to the user.
As part of the Monnify integration, notifications are automatically sent to your system when certain actions are completed. These notifications trigger corresponding activities on your system, and you can specify URLs for certain activities on your integration.
The notifications include an event-type property that indicates what action has taken place, as well as event data containing details of the event.
Supported notification event types on Monnify include
A typical event notification structure is of the format:
As a security measure, Monnify computes a hash of the request body whenever it sends a notification and includes it in the request header with the key 'monnify-signature'. To ensure the notification is valid and authorized, you should also calculate the hash and compare it to the one sent by Monnify before accepting or acting on the notification.
To calculate the hash, you can use a SHA-512 encoding of your client secret key and the object of the request body. The formula is: SHA-512(client secret key + object of request body).
Sample Client Key: 91MUDL9N6U3BQRXBQ2PJ9M0PW4J22M1Y
Sample Request:
{"eventData": {"product": {"reference": "111222333","type": "OFFLINE_PAYMENT_AGENT"},"transactionReference": "MNFY|76|20211117154810|000001","paymentReference": "0.01462001097368737","paidOn": "17/11/2021 3:48:10 PM","paymentDescription": "Mockaroo Jesse","metaData": {},"destinationAccountInformation": {},"paymentSourceInformation": {},"amountPaid": 78000,"totalPayable": 78000,"offlineProductInformation": {"code": "41470","type": "DYNAMIC"},"cardDetails": {},"paymentMethod": "CASH","currency": "NGN","settlementAmount": 77600,"paymentStatus": "PAID","customer": {"name": "Mockaroo Jesse",}},"eventType": "SUCCESSFUL_TRANSACTION"}
Hashed Value:
f04fb635e04d71648bd3cc7999003da6861483342c856d05ddfa9b2dafacb87 3b0de1d0f8f67405d0010b4348b721c49fa171d317972618debba6b638aedcd3c
const sha512 = require('js-sha512').sha512;const DEFAULT_MERCHANT_CLIENT_SECRET = '91MUDL9N6U3BQRXBQ2PJ9M0PW4J22M1Y'const computeHash = (requestBody) => {const result = sha512.hmac(DEFAULT_MERCHANT_CLIENT_SECRET, requestBody)return result}const stringifiedRequestBody = '{"eventData":{"product":{"reference":"111222333","type":"OFFLINE_PAYMENT_AGENT"},"transactionReference":"MNFY|76|20211117154810|000001","paymentReference":"0.01462001097368737","paidOn":"17/11/2021 3:48:10 PM","paymentDescription":"Mockaroo Jesse","metaData":{},"destinationAccountInformation":{},"paymentSourceInformation":{},"amountPaid":78000,"totalPayable":78000,"offlineProductInformation":{"code":"41470","type":"DYNAMIC"},"cardDetails":{},"paymentMethod":"CASH","currency":"NGN","settlementAmount":77600,"paymentStatus":"PAID","customer":{"name":"Mockaroo Jesse","email":"[email protected]"}},"eventType":"SUCCESSFUL_TRANSACTION"}';const computedHash = computeHash(stringifiedRequestBody);console.log("Computed hash", computedHash);
<?phpclass CustomTransactionHashUtil {public static function computeSHA512TransactionHash($stringifiedData, $clientSecret) {$computedHash = hash_hmac('sha512', $stringifiedData, $clientSecret);return $computedHash;}}$DEFAULT_MERCHANT_CLIENT_SECRET = '91MUDL9N6U3BQRXBQ2PJ9M0PW4J22M1Y';$data = '{"eventData":{"product":{"reference":"111222333","type":"OFFLINE_PAYMENT_AGENT"},"transactionReference":"MNFY|76|20211117154810|000001","paymentReference":"0.01462001097368737","paidOn":"17/11/2021 3:48:10 PM","paymentDescription":"Mockaroo Jesse","metaData":{},"destinationAccountInformation":{},"paymentSourceInformation":{},"amountPaid":78000,"totalPayable":78000,"offlineProductInformation":{"code":"41470","type":"DYNAMIC"},"cardDetails":{},"paymentMethod":"CASH","currency":"NGN","settlementAmount":77600,"paymentStatus":"PAID","customer":{"name":"Mockaroo Jesse","email":"[email protected]"}},"eventType":"SUCCESSFUL_TRANSACTION"}';$computedHash = CustomTransactionHashUtil::computeSHA512TransactionHash($data, $DEFAULT_MERCHANT_CLIENT_SECRET);echo $computedHash;?>
<?phppublic class TransactionHashUtil {private static final String HMAC_SHA512 = "HmacSHA512";private static String toHexString(byte[] bytes) {Formatter formatter = new Formatter();for (byte b : bytes) {formatter.format("%02x", b);}return formatter.toString();}public String calculateHMAC512TransactionHash(String data, String merchantClientSecret)throws SignatureException, NoSuchAlgorithmException, InvalidKeyException{SecretKeySpec secretKeySpec = new SecretKeySpec(merchantClientSecret.getBytes(), HMAC_SHA512);Mac mac = Mac.getInstance(HMAC_SHA512);mac.init(secretKeySpec);return toHexString(mac.doFinal(data.getBytes()));}}
It’s highly recommended you do the following when processing webhook notifications from us.