Jump to content

Create a Hash using a variable


Recommended Posts

Hi, I am trying to set up a payment system on our website but its not working.

basically when passing the value's through they chargetotal and total amounts need to match. when testing it on our server they match however when passing it through the gateway it has to be hashed which is either hashing the variable or changing to total.

Below is my code. Any help would be much appreciated. I am talking to the company however they are strugglng as much a me.


For it to be able to work. $total about needs to be the same as $chargetotal. $chargetotal is the amount being input through the form.

Payment Page
<? include("ipg-util.php"); ?><?php $chargetotal=$total;

<head><title> PHP Sample Payment Screen</title></head>
    <p><h1>Order Form</h1>
<form method="post" action=theirgateway">
    <input type="hidden" name="txntype" value="sale">
    <input type="hidden" name="timezone" value="Europe/London"/>
    <input type="hidden" name="txndatetime" value="<?php echo getDateTime() ?>"/>
   <input type="hidden" name="hash" value="<?php echo createHash("$total","826" ) ?>"/>
    <input type="hidden" name="storename" value="**********"/>
    <input type="hidden" name="mode" value="fullpay"/>
<input type="text" name="chargetotal" value="<?php echo $chargetotal;?>" />
    <input type="hidden" name="currency" value="826"/>
    <input type="hidden"   name="responseSuccessURL" value="http://yourdomain.com/Thanks" /> 
    <input type="hidden"   name="responseFailURL" value="http://yourdomain.com/PaymentFailure" /> 
    <input type="submit" value="Submit">    </form>
The supporting file ipg-util.php

    $dateTime = date("Y:m:d-H:i:s");

    function getDateTime() {
        global $dateTime;
        return $dateTime;

    function createHash($chargetotal, $currency) {
        $storename ="*************";
  $sharedekyt = "*************";

        $stringToHash = $storename . getDateTime() . $chargetotal . $currency . $sharedkyt;

        $ascii = bin2hex($stringToHash);

        return sha1($ascii);



Link to comment
Share on other sites

You're including date and time, down to the second, in the string to hash. So the hashes will only be calculated the same on the same second. Assuming wherever you post this form to does the same hash, it'd also have to do so within the same exact second to get a matching value.

Link to comment
Share on other sites

Sorry when passing the values for the chargetotal to the gateway they need to match so if a user input 15 then the amount created in the hash needs to be 15 at the moment they do not match so when I am going through to the gateway it throws and error.

Link to comment
Share on other sites

Hi Yes, I have checked the previous messages. The only thing I have in terms of the hash is 

<input type="hidden" name="hash" value="<?php echo createHash(
"13.00","826" ) ?>"/>
However because it has a value of 13 is in, the gateway will then only accept a value of 13. So regardless of the amount the user puts in it won't accept it. I was trying to put the value the user enters through the form into a variable and then call the variable within the hash as below
<input type="hidden" name="hash" value="<?php echo createHash($chargetotal, "826" ) ?>"/>
and $_REQUEST['chargetotal'];
Thanks for your help
This is the guide we got 
Edited by redds013
Link to comment
Share on other sites

So we are nursery school, We want our parents to be able to pay for their fees using online payment, The amount they pay will differ each month as their child will attend different days. So when they get to our form, I would like them to input the amount they are going pay and then send that amount through to the gateway to be processed.

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.