I am working on CodeIgniter payUmoney integration. I have a registration form from where one registers and get paid with payUmoney payment gateway and form contains multiple select fields also. I need to use the payUmoney payment gateway. So please help me that how can I insert the records into the database after the successful transaction in CodeIgniter.?
Actually here is my form. Now, what I want to submit the form but After successful payment. For me a little problem that where will I store the data till payment succeeded. Means I want to store the data after a successful transaction. One thing also there is multiple select drops down also, So please help me how to store the data into the database after a transaction using payUmoney.
The answer for your latest comment. The checksum error happens due to hash mismatch. after you submit the form to payu/checkout.php, checkout.php will submit a form to https://test.payu.in/_payment (Test url).
Inside your payu/checkout.php
function checkout() {
$MERCHANT_KEY = "enter your test merchant key here";
$SALT = "enter your test salt here";
$txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
$udf1='';
$udf2='';
$udf3='';
$udf4='';
$udf5='';
$hashstring = $MERCHANT_KEY . '|' . $txnid . '|' . $grandtotal . '|' . $productinfo . '|'. $fname . '|' . $email .'|'.$udf1.'|' .$udf2.'|' .$udf3.'|'.$udf4.'|'.$udf5.'||||||'. $SALT;
$hash = strtolower(hash('sha512', $hashstring));
$data['hash'] = $hash;
//Loading checkout view
$this->load->view('checkout.php');
}
In the checkout.php you must submit a form to https://test.payu.in/_payment with all the fields I used in the hash generation except salt. The hash field is also in that form.
<form method="post" name="payuForm" action="https://test.payu.in/_payment">
<input name="key" type="hidden" value="<?php echo $mkey ?>" />
<input name="txnid" type="hidden" value="<?php echo $tid ?>" />
<input type="hidden" name="hash" value="<?php echo $hash ?>"/>
<input name="amount" type="hidden" value="<?php echo $grandtotal; ?>" />
<input name="productinfo" type="hidden" value="<?php echo $pinfo;?>">
<input type="hidden" name="service_provider" value="payu_paisa" size="64" />
<input name="udf1" type="hidden" value="">
<input name="udf2" type="hidden" value="">
<input name="udf3" type="hidden" value="">
<input name="udf4" type="hidden" value="">
<input name="udf5" type="hidden" value="">
<input name="firstname" id="firstname" type="hidden" value="<?php echo $name; ?>"/>
<input name="email" id="email" type="hidden" value='<?php echo $mailid;?>'>
<input name="phone" type="hidden" value="<?php echo $phoneno; ?>">
<input name="surl" type="hidden" value="<?php echo base_url('payu/success'); ?>" size="64" />
<input name="furl" type="hidden" value="<?php echo base_url('payu/fail'); ?>" size="64" />
<input name="curl" type="hidden" value="<?php echo base_url('payu/cancel'); ?>" />
<?php
}
?>
<input type="submit" name="submit_form" value="Click Here for Payment" class="btn btn-info btn-block" >
</form>
For extra information remember to create a transaction table with fields like transaction id, amount, timestamp, status and all user's info fields. Before the transaction begins ie in payu/checkout function you need to insert this table with status initiated. After a successful transaction update status field of this transaction to success after checking return hash if you care about hacking( I check return hash because I hacked the payumoney site for testing and find out that if I don't check return hash my fake transaction will be successful. )
public function success()
{
//print_r($_REQUEST);
$status= $this->input->post('status');
if($status =='success')
{
$txnid = $this->input->post('txnid');
$amount = $this->input->post('amount');
$productinfo = $this->input->post('productinfo');
$firstname = $this->input->post('firstname');
$hash = $this->input->post('hash');
$email = $this->input->post('email');
$udf1 = $this->input->post('udf1');
$udf2 = $this->input->post('udf2');
$udf3 = $this->input->post('udf3');
$udf4 = $this->input->post('udf4');
$udf5 = $this->input->post('udf5');
$key = $this->input->post('key');
$SALT ="Your salt";
If (isset($_POST["additionalCharges"]))
{
$additionalCharges=$_POST["additionalCharges"];
$retHashSeq = $additionalCharges.'|'.$SALT . '|' . $status . '|||||||||||' . $email . '|' . $firstname . '|' . $productinfo . '|' . $amount . '|' . $txnid . '|' . $key;
}else{
$retHashSeq = $SALT . '|' . $status . '|||||||||||' .$udf5.'|'.$udf4.'|'.$udf3.'|'.$udf2.'|'.$udf1.'|'. $email . '|' . $firstname . '|' . $productinfo . '|' . $amount . '|' . $txnid . '|' . $key;
}
$rethash = hash("sha512", $retHashSeq);
if ($rethash != $hash)
{
$data['errmsg'] = " Invalid Transaction . Error Occured";
//echo "Return Hash failed";
redirect('payu/err',$data);
}
// now begin your custome code if a transaction is success
}