Skip to content

Instantly share code, notes, and snippets.

@hitswa
Last active July 1, 2018 18:43
Show Gist options
  • Save hitswa/7de282e77409c2268692a82d03db5c92 to your computer and use it in GitHub Desktop.
Save hitswa/7de282e77409c2268692a82d03db5c92 to your computer and use it in GitHub Desktop.
custom easy to implement PayUMoney page to send payment request
<?php
$MERCHANT_KEY = "xxxxxxxx"; // replace with marchent key
$SALT = "xxxxxxxxx"; // replace with salt
$txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
$surl = 'http://xxxxxxx.com/payment_response'; // replace with success url
$furl = 'http://xxxxxxx.com/payment_response'; // replace with fail url
$curl = 'http://xxxxxxx.com/payment_response'; // replace with cancel url
$action = 'https://sandboxsecure.payu.in/_payment'; // sandbox url
// $action = 'https://secure.payu.in/_payment'; // live url
/* DO NOT EDIT THIS PAGE AFTER THIS COMMENT */
/* test credentials
Card Type: Visa
Card Name: Test
Card Number: 4012001037141112
Expiry Date : 05/20
CVV : 123
Card Type: Master
Card Name: Test
Card Number: 5123456789012346
Expiry Date : 05/20
CVV : 123
*/
$posted = [];
$posted['key'] = $MERCHANT_KEY;
$posted['txnid'] = $txnid;
$posted['surl'] = $surl;
$posted['furl'] = $furl;
$posted['service_provider'] = 'payu_paisa';
$posted['curl'] = $curl;
$posted['amount'] = isset($_POST['amount']) ? $_POST['amount'] : '';
$posted['firstname'] = isset($_POST['firstname']) ? $_POST['firstname'] : '';
$posted['email'] = isset($_POST['email']) ? $_POST['email'] : '';
$posted['phone'] = isset($_POST['phone']) ? $_POST['phone'] : '';
$posted['productinfo'] = isset($_POST['productinfo']) ? $_POST['productinfo'] : '';
/* PARAMETERS BELOW THIS LINE ARE NOT COMPULSORY */
$posted['lastname'] = isset($_POST['lastname']) ? $_POST['lastname'] : '';
$posted['address1'] = isset($_POST['address1']) ? $_POST['address1'] : '';
$posted['address2'] = isset($_POST['address2']) ? $_POST['address2'] : '';
$posted['city'] = isset($_POST['city']) ? $_POST['city'] : '';
$posted['state'] = isset($_POST['state']) ? $_POST['state'] : '';
$posted['country'] = isset($_POST['country']) ? $_POST['country'] : '';
$posted['zipcode'] = isset($_POST['zipcode']) ? $_POST['zipcode'] : '';
$posted['udf1'] = isset($_POST['udf1']) ? $_POST['udf1'] : '';
$posted['udf2'] = isset($_POST['udf2']) ? $_POST['udf2'] : '';
$posted['udf3'] = isset($_POST['udf3']) ? $_POST['udf3'] : '';
$posted['udf4'] = isset($_POST['udf4']) ? $_POST['udf4'] : '';
$posted['udf5'] = isset($_POST['udf5']) ? $_POST['udf5'] : '';
$posted['udf6'] = isset($_POST['udf6']) ? $_POST['udf6'] : '';
$posted['udf7'] = isset($_POST['udf7']) ? $_POST['udf7'] : '';
$posted['udf8'] = isset($_POST['udf8']) ? $_POST['udf8'] : '';
$posted['udf9'] = isset($_POST['udf9']) ? $_POST['udf9'] : '';
$posted['udf10'] = isset($_POST['udf10']) ? $_POST['udf10'] : '';
if(empty($posted['amount']) || empty($posted['firstname']) || empty($posted['email']) || empty($posted['phone']) || empty($posted['productinfo']) ) {
echo 'required parameter missing, try again';
exit();
}
$hash_string = $posted['key'] .'|'. $posted['txnid'] .'|'. $posted['amount'] .'|'. $posted['productinfo'] .'|'. $posted['firstname'] .'|'. $posted['email'] .'|'. $posted['udf1'] .'|'. $posted['udf2'] .'|'. $posted['udf3'] .'|'. $posted['udf4'] .'|'. $posted['udf5'] .'|'. $posted['udf6'] .'|'. $posted['udf7'] .'|'. $posted['udf8'] .'|'. $posted['udf9'] .'|'. $posted['udf10'] .'|'.$SALT;
$hash = strtolower(hash('sha512', $hash_string));
$posted['hash'] = $hash;
?><!DOCTYPE html>
<html>
<head>
<title>payUForm</title>
</head>
<body>
<p>please wait...</p>
<form action="<?php echo $action; ?>" method="post" name="payuForm">
<input type="hidden" name="key" value="<?php echo $posted['key'] ?>" />
<input type="hidden" name="txnid" value="<?php echo $posted['txnid'] ?>" />
<input type="hidden" name="hash" value="<?php echo $posted['hash'] ?>" />
<input type="hidden" name="amount" value="<?php echo $posted['amount'] ?>" />
<input type="hidden" name="firstname" value="<?php echo $posted['firstname'] ?>" />
<input type="hidden" name="email" value="<?php echo $posted['email'] ?>" />
<input type="hidden" name="phone" value="<?php echo $posted['phone'] ?>" />
<input type="hidden" name="productinfo" value="<?php echo $posted['productinfo'] ?>" />
<input type="hidden" name="surl" value="<?php echo $posted['surl'] ?>" />
<input type="hidden" name="furl" value="<?php echo $posted['furl'] ?>" />
<input type="hidden" name="service_provider" value="<?php echo $posted['service_provider'] ?>" />
<input type="hidden" name="lastname" value="<?php echo $posted['lastname'] ?>" />
<input type="hidden" name="curl" value="<?php echo $posted['curl'] ?>" />
<input type="hidden" name="address1" value="<?php echo $posted['address1'] ?>" />
<input type="hidden" name="address2" value="<?php echo $posted['address2'] ?>" />
<input type="hidden" name="city" value="<?php echo $posted['city'] ?>" />
<input type="hidden" name="state" value="<?php echo $posted['state'] ?>" />
<input type="hidden" name="country" value="<?php echo $posted['country'] ?>" />
<input type="hidden" name="zipcode" value="<?php echo $posted['zipcode'] ?>" />
<input type="hidden" name="udf1" value="<?php echo $posted['udf1'] ?>" />
<input type="hidden" name="udf2" value="<?php echo $posted['udf2'] ?>" />
<input type="hidden" name="udf3" value="<?php echo $posted['udf3'] ?>" />
<input type="hidden" name="udf4" value="<?php echo $posted['udf4'] ?>" />
<input type="hidden" name="udf5" value="<?php echo $posted['udf5'] ?>" />
<input type="hidden" name="udf6" value="<?php echo $posted['udf6'] ?>" />
<input type="hidden" name="udf7" value="<?php echo $posted['udf7'] ?>" />
<input type="hidden" name="udf8" value="<?php echo $posted['udf8'] ?>" />
<input type="hidden" name="udf9" value="<?php echo $posted['udf9'] ?>" />
<input type="hidden" name="udf10" value="<?php echo $posted['udf10'] ?>" />
</form>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
$(document).ready(function(){
var payuForm = document.forms.payuForm;
var hash = $( "input[name*='hash']" ).val();
if( hash != '' ) {
payuForm.submit();
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment