redds013 Posted October 19, 2017 Share Posted October 19, 2017 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; <html> <head><title> PHP Sample Payment Screen</title></head> <body> <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 <?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); } ?> Quote Link to comment Share on other sites More sharing options...
requinix Posted October 20, 2017 Share Posted October 20, 2017 You've said a bit but haven't actually said what the problem is. As in, what is going wrong that you are trying to figure out? Is the hash wrong? Quote Link to comment Share on other sites More sharing options...
Sepodati Posted October 20, 2017 Share Posted October 20, 2017 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. Quote Link to comment Share on other sites More sharing options...
redds013 Posted October 20, 2017 Author Share Posted October 20, 2017 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. Quote Link to comment Share on other sites More sharing options...
Sepodati Posted October 20, 2017 Share Posted October 20, 2017 You have a typo here: $sharedekyt = "*************"; That would create an issue as the shared key is not being included in the hash. Quote Link to comment Share on other sites More sharing options...
redds013 Posted October 20, 2017 Author Share Posted October 20, 2017 (edited) Thanks, Ive changed that, I am still getting the error, though. Attached is the actual screen am getting. Edited October 20, 2017 by redds013 Quote Link to comment Share on other sites More sharing options...
Sepodati Posted October 20, 2017 Share Posted October 20, 2017 I assume you've worked through the first three issues and ruled them out? Is there documentation on how they expect you to generate the hash? Quote Link to comment Share on other sites More sharing options...
redds013 Posted October 20, 2017 Author Share Posted October 20, 2017 (edited) 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 https://www.firstdata.com/en_gb/partners/developers-and-partners.html Edited October 20, 2017 by redds013 Quote Link to comment Share on other sites More sharing options...
Sepodati Posted October 20, 2017 Share Posted October 20, 2017 (edited) Why are you letting the user change the charge value at this point? Why isn't that a hidden field, too, and just the value displayed? Edited October 20, 2017 by Sepodati Quote Link to comment Share on other sites More sharing options...
redds013 Posted October 20, 2017 Author Share Posted October 20, 2017 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. Quote Link to comment Share on other sites More sharing options...
Sepodati Posted October 20, 2017 Share Posted October 20, 2017 You have to do it in two steps, then, or involve JavaScript. Quote Link to comment Share on other sites More sharing options...
redds013 Posted October 21, 2017 Author Share Posted October 21, 2017 Thanks, as stupid as this sounds, How? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.