...
To calculate the hash value, you will have to hash the whole object with your unique client secret as key. This allows you to pass data to be hashed as a string alongside the client secret.
Guide on computing transaction Hash
Step 1: First of all you’d need to know your client secret key, this can be found at the developers section of your dashboard.
...
Hashed Value: f04fb635e04d71648bd3cc7999003da6861483342c856d05ddfa9b2dafacb873b0de1d0f8f67405d0010b4348b721c49fa171d317972618debba6b638aedcd3c.
...
Computing the Request Validation Hash(NodeJs)
Code Block | ||
---|---|---|
| ||
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":"111222333@ZZAMZ4WT4Y3E.monnify"}},"eventType":"SUCCESSFUL_TRANSACTION"}'; const computedHash = computeHash(stringifiedRequestBody); console.log("Computed hash", computedHash); |
...
Computing the Request Validation Hash (PHP)
Code Block | ||
---|---|---|
| ||
<?php class 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":"111222333@ZZAMZ4WT4Y3E.monnify"}},"eventType":"SUCCESSFUL_TRANSACTION"}'; $computedHash = CustomTransactionHashUtil::computeSHA512TransactionHash($data, $DEFAULT_MERCHANT_CLIENT_SECRET); echo $computedHash; ?> |
...
Computing the Request Validation Hash (Java)
Code Block | ||
---|---|---|
| ||
public 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())); } } |
...