You are right, but it just does not work, just dont know what may be the reason, but PG guys have given me a php implementation of that, this is different from what Im looking at but in this file, you can see how they have implemented the sha512. This file does not show error. Check this.
[php]<?php
// Merchant key here as provided by Payu
$MERCHANT_KEY = “C0Dr8m”;
// Merchant Salt as provided by Payu
$SALT = “3sf0jURk”;
// End point - change to https://secure.payu.in for LIVE mode
$PAYU_BASE_URL = “https://test.payu.in”;
$action = ‘’;
$posted = array();
if(!empty($_POST)) {
//print_r($_POST);
foreach($_POST as $key => $value) {
$posted[$key] = htmlentities($value, ENT_QUOTES);
}
}
/foreach ($posted as $key => $value) {
echo “posted[”.$key."]=".$value."
";
}/
//echo $posted;
$formError = 0;
if(empty($posted[‘txnid’])) {
// Generate random transaction id
$txnid = substr(hash(‘sha256’, mt_rand() . microtime()), 0, 20);
} else {
$txnid = $posted[‘txnid’];
}
$hash = ‘’;
// Hash Sequence
$hashSequence = “key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10”;
if(empty($posted[‘hash’]) && sizeof($posted) > 0) {
if(
empty($posted[‘key’])
|| empty($posted[‘txnid’])
|| empty($posted[‘amount’])
|| empty($posted[‘firstname’])
|| empty($posted[‘email’])
|| empty($posted[‘phone’])
|| empty($posted[‘productinfo’])
|| empty($posted[‘surl’])
|| empty($posted[‘furl’])
) {
$formError = 1;
} else {
$hashVarsSeq = explode(’|’, $hashSequence);
$hash_string = ‘’;
foreach($hashVarsSeq as $hash_var) {
$hash_string .= isset($posted[$hash_var]) ? $posted[$hash_var] : ‘’;
$hash_string .= ‘|’;
}
$hash_string .= $SALT;
$hash = strtolower(hash(‘sha512’, $hash_string));
$action = $PAYU_BASE_URL . ‘/_payment’;
}
} elseif(!empty($posted[‘hash’])) {
$hash = $posted[‘hash’];
$action = $PAYU_BASE_URL . ‘/_payment’;
}
?>
PayU Form
<?php if($formError) { ?>
Please fill all mandatory fields.
<?php } ?>
Mandatory Parameters |
Amount: |
|
First Name: |
|
Email: |
|
Phone: |
|
Product Info: |
|
Success URI: |
|
Failure URI: |
|
Optional Parameters |
Last Name: |
|
Cancel URI: |
|
Address1: |
|
Address2: |
|
City: |
|
State: |
|
Country: |
|
Zipcode: |
|
UDF1: |
|
UDF2: |
|
UDF3: |
|
UDF4: |
|
UDF5: |
|
PG: |
|
COD URL: |
|
TOUT URL: |
|
Drop Category: |
|
Custom Note: |
|
Note Category: |
|
<?php if(!$hash) { ?>
|
<?php } ?>
[/php]