Hashing Inline

Adding a hash to inline

The hash is only confirmed if this has been enabled for your integration on Paystack.

The hash should be created thus:

Concatenate fields into one string

Create a string that is the concatenation of these fields:

  • publickey
  • amount
  • currency
  • email
  • reference
  • Stringified metadata (use empty curly braces if no metadata will be sent.)
  • secretkey

As an example for:

var PaystackParams = {
    key: 'pk_test_1nv4Lid1b507383cd77481e091877b6c22d68cf8',
    email: '[email protected]',
    amount: 11100,
    ref: 'T675781540020985',
    metadata: {
        "custom_fields": [
            {
                "display_name": "Mobile number",
                "variable_name": "mobile_number",
                "value": "0802839839"
            }
        ]
    },
    callback: function (response) {
        $.unblockUI();
        window.location.href = 'post-events.html';
    },
    onClose: function () {
        $.unblockUI();
    }
}

The string to hash will be:

[email protected]
love.comT675781540020985{"custom_fields":[{"display_name":"Mobile
number","variable_name":"mobile_number","value":"0802839839"}]
}sk_test_1nv4Lid0eac2be0a6a6915f6ba32f81bc8bac143

Hash concatenated string

Create a SHA512 hash of the string obtained in step 1.

<?php

$tohash = '[email protected]comT675781540020985{"custom_fields":[{"display_name":"Mobile number","variable_name":"mobile_number","value":"0802839839"}]}sk_test_1nv4Lid0eac2be0a6a6915f6ba32f81bc8bac143';

$hash = hash('sha512', $tohash);

Include hash in request to Paystack

Add the hash obtained in step 2 as a parameter on inline.

This would mean you would start inline with params:

var PaystackParams = {
    key: 'pk_test_1nv4Lid1b507383cd77481e091877b6c22d68cf8',
    email: '[email protected]',
    amount: 11100,
    ref: 'T675781540020985',
    metadata: {
        "custom_fields": [
            {
                "display_name": "localStorage.fullname",
                "variable_name": "mobile_number",
                "value": "0802839839"
            }
        ]
    },
    hash: '93fac3a92fc6d81f2b7a370529d2e436833984c5f0e945b756106113f100c6c3e2df1bd270568d424041d8a204da2a95d9d570f656211d2e72cde5c0fe00f1dd',
    callback: function (response) {
        $.unblockUI();
        window.location.href = 'post-events.html';
    },
    onClose: function () {
        $.unblockUI();
    }
}

and other parameters required for the transaction.