Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,
I want to add 5.5% fees to the field amount before sending it to the payment gateway..I am able to add the fees and show in a text box. But I couldn't send to payment gateway..It says "Checksum error". Please help!
The working version is given here
Enter a dummy name, dummy email, dummy phone, amount and click submit.. It will reload once and take to payment gateway's page which will show checksum error.
The error is with the field "amount". Actually Payu provide the code
PHP
<input name="amount" value="<?php echo (empty($posted['amount'])) ? '' : $posted['amount'] ?>" />
But I just want to add 5.5% to that amount.

PHP
<?php
// Merchant key here as provided by Payu
$MERCHANT_KEY = "JBZaLc";

// Merchant Salt as provided by Payu
$SALT = "GQs7yium";

// 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] = $value; 
	
  }
}

$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|firstname|email|productinfo|amount|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['firstname'])
          || empty($posted['email'])
					|| empty($posted['productinfo'])
					|| empty($posted['amount'])
          || empty($posted['phone'])
          
          || empty($posted['surl'])
          || empty($posted['furl'])
		  || empty($posted['service_provider'])
  ) {
    $formError = 1;
  } else {
    //$posted['productinfo'] = json_encode(json_decode('[{"name":"tutionfee","description":"","value":"500","isRequired":"false"},{"name":"developmentfee","description":"monthly tution fee","value":"1500","isRequired":"false"}]'));
	$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';
}
?>
<html>
  <head>
  <script>
    var hash = '<?php echo $hash ?>';
    function submitPayuForm() {
      if(hash == '') {
        return;
      }
      var payuForm = document.forms.payuForm;
      payuForm.submit();
    }
  </script>
	<!-- CDN -->
		<script src="http://code.jquery.com/jquery.min.js"></script>
		<script src="http://cdnjs.cloudflare.com/ajax/libs/prettify/r224/prettify.js"></script>
		<link href="http://cdnjs.cloudflare.com/ajax/libs/prettify/r224/prettify.css" rel="stylesheet">
		<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,300,600,700&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
		<!-- foundation start -->
		<!-- Set the viewport width to device width for mobile -->
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<!-- Included CSS Files (Compressed) -->
		<link rel="stylesheet" href="foundation/stylesheets/foundation.min.css">
		<link rel="stylesheet" href="foundation/stylesheets/app.css">
		<script src="foundation/javascripts/modernizr.foundation.js"></script>
		<!-- foundation end -->
		<!-- foundation datepicker start -->
		<script src="js/foundation-datepicker.js"></script>
		<link rel="stylesheet" href="stylesheets/foundation-datepicker.css">
		<!-- foundation datepicker end -->
		<link rel="stylesheet" href="stylesheets/example.css">
		<!--[if lt IE 9]>
			<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
		<![endif]-->
		
		<script language="javascript">
function KeyUpEvent()
{
var txt1 = document.getElementById("txt1");
var txt2 = document.getElementById("txt2");
var amount = document.getElementById("amount");
if ((txt1.value != "") && (txt2.value != ""))
{
amount.value = parseInt(txt1.value) + parseInt(txt1.value) * (txt2.value);
}
}

</script>

  </head>
  <body onload="submitPayuForm()">
    <h2>Homestaysatwaya
Posted
Updated 16-Jun-15 1:37am
v4
Comments
Richard MacCutchan 16-Jun-15 6:03am    
Please indicate exactly what error you get and, more importantly, where in the above code it occurs.
Kornfeld Eliyahu Peter 16-Jun-15 7:28am    
You should ask Payu - it seems you passed some invalid parameters, so what you need is a review of the API...
Richard Deeming 16-Jun-15 7:59am    
The most likely cause is that you're computing a hash of a string which includes the amount without the fees, but then changing the amount that you pass to the payment gateway. When the payment gateway computes the hash of the values you've sent, it doesn't match the hash value that you've generated, and you get an error.

This is a common security feature to prevent the user from altering the amount to pay.

You need to calculate the final amount in the PHP code before building the string and computing the hash.
Member 11769321 16-Jun-15 13:35pm    
Thank you all..
I tried to calculate and pass the value to field "amount" which is given as "amount" itself in hash.
<script language="javascript">
function KeyUpEvent()
{
var txt1 = document.getElementById("txt1");
var txt2 = document.getElementById("txt2");
var amount = document.getElementById("amount");
if ((txt1.value != "") && (txt2.value != ""))
{
amount.value = parseInt(txt1.value) + parseInt(txt1.value) * (txt2.value);
}
}
</script>

Inside form,
<tr>
<td>Amount: </td>
<td><INPUT type = "text" id="txt1" ><BR>
<INPUT type = "hidden" value=".055" id="txt2" ><BR>
<INPUT name="amount" id="amount" READONLY></td></tr>

If the amount is given with code <input name="amount" value="" />
is working fine..
Member 11769321 17-Jun-15 12:58pm    
Yes..I got the error. It was in hash statement..Field amount was misplaced and I pasted it again from the original file given by Payumoney. It worked!
Thank you all..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900