PayUMoney Payment Gateway Integration In PHP
I
have received requests from some visitors to write article on How to implement PayUMoney Payment Gateway in PHP. PayUMoney payment gateway is one of the well known payment gateways in India. Click here to create account on paymoney. You need to submit your documents related to your business, bank details and your identity verification documents as well to PayUMoney.
In this tutorial i will show you how to create payment gateway system with payumoney in PHP. PayUmoney developer support also provides ready made tutorials in PHP, paython, JAVA, JSP, RAILS, ASP.NET and VB.NET. Its easy and simple to integrate it in project.
Create the PayUmoney account at www.payumoney.com and follow the steps showing in Dashboard to get approval for your PayUMoney account. Once your account get approved, you can start real payments using PayUMoney.
Contains PHP code and payment login. Replace below values with your own.
<Merchant Key>
– with your PayUMoney merchant key
<Salt>
– with your PayUMoney salt key
When you have tested completely, change development URL to live URL to make original payments.
$PAYU_BASE_URL = "https://test.payu.in";
to
$PAYU_BASE_URL = "https://payu.in";
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
<?php
$MERCHANT_KEY = "<Merchant Key>";
$SALT = "<Salt>";
$PAYU_BASE_URL = "https://test.payu.in";
$action = '';
$posted = array();
if(!empty($_POST)) {
foreach($_POST as $key => $value) {
$posted[$key] = $value;
}
}
$formError = 0;
if(empty($posted['txnid'])) {
$txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
} else {
$txnid = $posted['txnid'];
}
$hash = '';
$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';
}
?>
<html>
<head>
<script>
var hash = '<?php echo $hash ?>';
function submitPayuForm() {
if(hash == '') {
return;
}
var payuForm = document.forms.payuForm;
payuForm.submit();
}
</script>
</head>
<body onload="submitPayuForm()">
<h2>Payment System with PayUMoney - By Gopal Joshi (www.sgeek.org)</h2>
<form action="<?php echo $action; ?>" method="post" name="payuForm">
<input type="hidden" name="key" value="<?php echo $MERCHANT_KEY ?>" />
<input type="hidden" name="hash" value="<?php echo $hash ?>"/>
<input type="hidden" name="txnid" value="<?php echo $txnid ?>" />
<input type="hidden" name="amount" value="50" />
<input type="hidden" name="productinfo" value="Iphone 6C - 16GB" />
<input type="hidden" name="surl" value="http://example.com/success.php"/> <!-- Success notification -->
<input type="hidden" name="furl" value="http://example.com/failure.php"/> <!-- Failure notification -->
<table>
<tr>
<td>Amount: </td>
<td>$50</td>
<td>First Name: </td>
<td><input name="firstname" id="firstname" value="<?php echo (empty($posted['firstname'])) ? '' : $posted['firstname']; ?>" /></td>
</tr>
<tr>
<td>Email: </td>
<td><input name="email" id="email" value="<?php echo (empty($posted['email'])) ? '' : $posted['email']; ?>" /></td>
<td>Phone: </td>
<td><input name="phone" value="<?php echo (empty($posted['phone'])) ? '' : $posted['phone']; ?>" /></td>
</tr>
<tr>
<td>Product: </td>
<td colspan="3"> Iphone 6C - 16GB</td>
</tr>
<tr>
<?php if(!$hash) { ?>
<td colspan="4"><input type="submit" value="Submit" /></td>
<?php } ?>
</tr>
</table>
</form>
</body>
</html>
|
success.php
Success surl
(Success URL) file. In case payment succeeded, page will redirect on success.php
page with $_POST
method and success parameters. You can do further process of success payment here.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
<?php
$status =$_POST["status"];
$firstname =$_POST["firstname"];
$amount =$_POST["amount"];
$txnid =$_POST["txnid"];
$posted_hash =$_POST["hash"];
$key =$_POST["key"];
$productinfo =$_POST["productinfo"];
$email =$_POST["email"];
$salt ="eCwWELxi";
If (isset($_POST["additionalCharges"])) {
$additionalCharges =$_POST["additionalCharges"];
$retHashSeq = $additionalCharges.'|'.$salt.'|'.$status.'|||||||||||'.$email.'|'.$firstname.'|'.$productinfo.'|'.$amount.'|'.$txnid.'|'.$key;
} else {
$retHashSeq = $salt.'|'.$status.'|||||||||||'.$email.'|'.$firstname.'|'.$productinfo.'|'.$amount.'|'.$txnid.'|'.$key;
}
$hash = hash("sha512", $retHashSeq);
if ($hash != $posted_hash) {
echo "Sorry! Invalid Transaction. Please try again";
} else {
echo "<h4>Your Payment has been done. Your Transaction ID for this transaction is ".$txnid.".</h4>";
}
?>
|
failure.php
Failure furl
(Failure URL) file. In case of payment failure, page will redirect on failure.php
page with post
method and failure parameters. You can do further process of failed payment here.
1
2
3
|
<?php
echo "<h1>Sorry! Your Payment Canceled</h1>";
?>
|
For further queries in integration you can comment here or email me on .
Read More
Stripe Payment Integration in PHP
How To Setup PayPal Account
Introduction To PayPal Adaptive Payments
Introduction To Adyen Payment Platform
sfiletypechecker-JQuery Plugin Validate Input File
Sachin
Hey Gopal ,
Good to see the post. I have started learning php now. And your blog is adding values to me.
Ataul
Thank you Gopal. Good post. I tested this and it is working..
cty truyen thong ghitaphan
Appreciate this post. Let me try it out.
Siva prasad
Hi Gopal , I have implemented same kind in my application. i’m using codeigniter, when i click payment button its reloading the page and then redirecting to the payumoney gayeway page. can we do this without reloading the page???
Gopal Joshi
Hi Siva,
You need to redirect page to payment hosted page by PayUmoney. It offers optimized payment page for both desktop and mobile browsers.
Arushi Jain
Hi Gopal, This is a very good tutorial though I am not able to get the source code. The downloaded folder is empty. Please fix it asap.
Gopal Joshi
Hello Arushi,
Sorry for inconvenience. The issue has been solved. You can now download source code.
Thank You
Arushi Jain
Thank you Gopal for your immediate response… I have one more query regarding this. In this tutorial you have created the $hash but not used in $action. As I am also doing the same, the redirection page (https://test.payu.in/_payment) is showing error. Dont we have to send $hash or $posted in some way. On the other hand the demo you provided has redirected utl like this: https://test.payu.in/_payment_options?mihpayid=5694e7b6b4b913aef2450b018d14c22dd7abbb137dc500c5baa75c59d9c98d4d
Gopal Joshi
Hi Arushi,
We do not need to use $hash in $action or else. Can you post the error that you are showing here?
Arushi Jain
Gopal Joshi
It seems like you are passing wrong amount parameter in PayUMoney. It would be batter if you recheck the required input parameters mansion in Error message.
Arushi Jain
Okay I got it what I was doing wrong is the form which i had created was sent in body of the api request, but we need to send them into params of the request.
Now one last query, what we need to send in “key” params. Because when I am sending merchantKey in “key” params it shows following error “Merchant key missing in Request”
Gopal Joshi
You only need to send the merchant Key in ‘key’ parameter. You are going in right direction, just verify merchant key you are passing in ‘key’ parameter. Also verify that PayUMoney has either activated your account or not. If they have not activated your test account yet than go to payumoney.com and complete required steps from dashboard.
Arushi Jain
But I am using test keys as provided by payU.
Gopal Joshi
Kindly Try below test keys
Merchant Key: “gtKFFx”
Salt “eCwWELxi”
Pratibha Yadav
Hello Sir,
i want to integrate payment gateway in php core, but i never try this functionality… i also check on internet but i can’t understand anything… so can help me out???
Gopal Joshi
Hello Pratibha,
Payumoney payment gateway integration is quite easy. First of all read the article carefully and download source code by clicking on “Download” button. After downloading codebase, study tutorial by running in local system. You can study video tutorial on YouTube as well posted on sgeekorg channel. You may also comment your queries or errors if occurs here. I will glad to help you.
Thank You
Himanshu kumar
Hello admin,
Can we use pay u money without form. I don’t want to show value in hidden field anyone can change this.
Ashwin Jain
Hello Gopal,
The tutorial is working for me but the only problem i m getting is, after the payment the page is not getting redirected to success.php or failure.php. Instead it is showing ‘page url cannot be found Error 404’ and the link in address bar is ‘https://test.payu.in/failure.php’ though all the files are in same folder. What can be the issue?
Gopal Joshi
You have enter wrong Failure Url or Success Url. Double check both the urls
kamlesh
Error Reason
One or more mandatory parameters are missing in the transaction request.
Corrective Action
Please ensure that you send all mandatory parameters in the transaction request to PayU.
Mandatory parameters which must be sent in the transaction are:
key, txnid, amount, productinfo, firstname, email, phone, surl, furl, hash
.
The parameters which you have actually sent in the transaction are:
key, txnid, amount, productinfo, surl, firstname, email, phone.
Mandatory parameter missing from your transaction request are:
hash.
Please re-initiate the transaction with all the mandatory parameters.
Gopal Joshi
Hi Kamlesh,
Error says itself that you have to fill all the mandatory parameters. Recheck all the parameters your are passing in PayUMoney.
kamlesh
Hello Gopal,
why this error
Sorry We were unable to process your payment
Checksum Failed
Rahul
hello Gopal,
I have a queastion that i have to upload data and a file on mysql server from an html page but the condition is file and data should be upload when the payment is success, so please help me for the same because am unable to do this things.
Regards,
Rahul Aggarwal
manoj
Hi gopal thanks for code …
I want to pass select tag option value to payumoney instead of udf1 so kindly suggest code for that.
Thanks
Gopal Joshi
Manoj,
“utf” stands for User Defined Field itself.
Kindly, Render select option in the form and replace “udf1” string in $hashSequence variable with select option’s name that you have added in form. Now, The value you have selected will be pass to payumoney.
manoj
I am facing issue to save user defined field (udf1) value which I pass to PayUmoney in my database after payment successful.
manoj
plz share one example for that
sanju
Thanks sir
apoorv mittal
Not working in postman
sachin dhotre
how to get transaction details like transaction ID and it’s status after success page or in failure page.please help me
Gopal Joshi
Sachin,
You can get all transaction details by using
$_POST
method on success or failure page.vinay
Hai Sir,
I am having a small of issue can you help me in even though i tried changing salt and merchant id
SORRY!
We were unable to process your payment
Error Reason
You seem to be using an incorrect key or salt value.
Corrective Action
Please note that this is PayU’s Test Environment – https://test.payu.in/_payment , but the key (T2ELVHi4) you are using is not a Test Environment key.
Please ensure that you are using correct key and salt in the transaction request. Please note that key and salt are alphanumeric string values which are provided by PayU.
Value of a sample key – gtKFFx
Value of a sample salt – eCwWELxi
In case you haven’t received the key/salt yet, please contact your Account Manager at PayU.
Gopal Joshi
You have entered wrong salt or key. Kindly Verify both and ensure that you are using Test Environment Key for testing.
manoj
I have form in which amount is calculated through a javascript. so i am facing issue to send total calculated amount to payumoney . So Kindly suggest what am i write in amount value
xavier
i want to check the transaction status using api provided by payumoney can you show me the sample code.
Gopal Joshi
Pls Review
success.php
file in articleInnocent Ekene
How can i change the currency to Nigerian currency
Pritam Soni
You can’t I guess. Payumoney is only for India
Ashok
i have got this while going to payment
“Merchant has to use his own email to make the payment” could you please any one to help me.
Gopal Joshi
A reason behind it is that your payUMonay account is not activated to receive live payments yet. Kindly contact to Support Team. Generally It takes 8-10 day to activate.
Malorie
Hello Gopal, just became alert to your blog through Google, and found that it is truly informative.
I will appreciate if you continue this in future.
Lots of people will be benefited from your writing. Cheers!
Smitha
Hi my friend! I want to say that this post is amazing, great written and include almost all significant infos. I’d like to see more posts like this.
omkar
Hi Gopal,
Based on radio button selection page should redirect to payumoney for payment can you please help me out
nikhil
Hi,
How to add the details of Payu Payment into my Database
Gopal Joshi
Hi Nikhil,
You may insert payment details into database before payment having Payment Status field and update payment details and status on Payment Success or Fail (on
success.php
) .NIKHIL
hi gopal joshi,
thanx for your support
I integrate payumoney to my website but in production environment it showing as
SORRY!
We were unable to process your payment
Error Reason
You seem to be using an incorrect key or salt value.
Corrective Action
Please note that this is PayU’s Live (Production) Environment – https://secure.payu.in/_payment, but the key (gBLFfgZM) you are using in the transaction is not a Live (Production) Environment key.
Please ensure that if you are hitting PayU’s Production Environment, you must use only the Production (Live) key and salt in the transaction request – which have been shared with you by the PayU Account Manager.
How to get the correct Live key/alias and salt?
Your PayU Account Manager would have shared the Live key/alias and salt values with you on your registered email-ID. The mail would be in the below format:
…
Dear Merchant,
Your login details.
Thank you for choosing PayUbiz.
User Name:
Login Alias:
Password Link:
…
I entered key and salt correctly and my payumoney account is activated for payments please help
Gopal Joshi
Hi Nikhil,
First of all please ensure that you have activated your payumoney account completely by login in payumoney website. If your account is activated properly than verify salt and key that you are using in app is for production (You should have two salt and key. One for production and another for development environment).
Ayush jain
$MERCHANT_KEY = “rjQUPktU”;
$SALT = “e5iIg1jwi8”;
$PAYU_BASE_URL = “https://test.payu.in”;
IN FORM use one more parameter:-
Vinyanshu
Dear Gopal,
I have seen all the details as well as the video you have uploaded here. I am still stuck in this. Actually you have given sample pages but how to link them and where to add all the field. And what if i want to do custom install for one or more website with single page payment gateway. Which is some another domain, subdomain for all of my E commerce websites.
Please give proper instructions and steps for the same.
raju
Thank you bro..
RUSHIKANT BIRAJDAR
When its live. Its giving error that
payu.in/_payment
is wrong site and there is mistake in siteSumit Ringane
Hello sir,
If U have any idea to implement payU money gateway code in asp.net MVC . Please forward me.
vasudevareddy
Hi ,
Any one can help me,
How to integrate payubiz payment gateway in codeigniter.
apoorv mittal
Error Reason
One or more mandatory parameters are missing in the transaction request.
Corrective Action
Please ensure that you send all mandatory parameters in the transaction request to PayU.
Mandatory parameters which must be sent in the transaction are:
key, txnid, amount, productinfo, firstname, email, phone, surl, furl, hash
.
The parameters which you have actually sent in the transaction are:
key, txnid, amount, productinfo, surl, hash, firstname, email, phone.
Mandatory parameter missing from your transaction request are:
.
Please re-initiate the transaction with all the mandatory parameters.