PayUMoney Integration

Brief :

Now a day as me are moving more towards digitization, new models, concepts, softwares are making their way into the market.  If we talk specifically about websites that operate more into E-commerce and B2C there are few basic things that are necessary for the website to sustain.
Such as customer engagement, customers have become smart and demanding they need softwares/websites which will give them the maximum satisfaction(in terms of time been spend of the website), user friendly flow and the main thing Payment methods.

Its a thumb rule if you want to sell anything online you need to have a payment gateway integrated to your website and that is where PayUMoney comes in.
PayUMoney is an e-commerce application service provider that authorizes credit card payments for e-businesses & online retailers.

Need :

We needed PayUMoney payment gateway to be integrated in one of our project as we were operating into B2C (Business to Customer) model where we wanted the customer to buy our product online and make the payments.

How it works :

You can integrate PayUMoney payment gateway by following the below steps :
There are few requisites that you need before implementing PayUMoney
1. Merchant Id
2. Merchant Key
3. Salt Key.
Note : All the above mentioned key's are different for Test & Live account.

Phase 1. Pre-Phase of Integration(Test) :

1. In this phase first you need to create your own PayUMoney Merchant account with a valid email address.
2. To create the test merchant account visit
3. Follow the instructions to fill all the required details.
4. As we are creating a test account, fill all required business details and use this details for PAN no. ABCDE1234F and DOB – 01/04/1990 .
5. Add your bank detail, note you can add whatever bank name and details use this IFSC – ALLA0212632 in place of IFSC.(No Bank verification in case of test accounts)
6. Once all these steps are completed your test account is live, in case if its not yet live then contact the support team for further assistance.
7. Now once above steps are complete you can get your salt key, go to Manage Account ⇒ My Account ⇒ Merchant -Key Salt copy your key and paste in your code.
8. Once all these steps are done completely you are good to go.
9. You then need to integrate the code given below.

// Merchant key here as provided by PayUMoney.

// Merchant Salt as provided by PayUMoney.

$SALT = "yIEkykqEH3";

// End point - change to for LIVE mode

$action = '';

$posted = array();
if(!empty($_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|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10";
if(empty($posted['hash']) && sizeof($posted) > 0) {
          || empty($posted['txnid'])
          || empty($posted['amount'])
          || empty($posted['firstname'])
          || empty($posted['email'])
          || empty($posted['phone'])
          || empty($posted['productinfo'])
          || empty($posted['surl'])
          || empty($posted['furl'])
          || empty($posted['service_provider'])
  ) {
    $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 Code:

    var hash = '<?php echo $hash ?>';
    function submitPayuForm() {
      if(hash == '') {
      var payuForm = document.forms.payuForm;
  <body onload="submitPayuForm()">
    <h2>PayU Form</h2>
    <?php if($formError) { ?>
      <span style="color:red">Please fill all mandatory fields.</span>
    <?php } ?>
    <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 ?>" />
          <td><b>Mandatory Parameters</b></td>
          <td>Amount: </td>
          <td><input name="amount" value="<?php echo (empty($posted['amount'])) ? '' : $posted['amount'] ?>" /></td>
          <td>First Name: </td>
          <td><input name="firstname" id="firstname" value="<?php echo (empty($posted['firstname'])) ? '' : $posted['firstname']; ?>" /></td>
          <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>
          <td>Product Info: </td>
          <td colspan="3"><textarea name="productinfo"><?php echo (empty($posted['productinfo'])) ? '' : $posted['productinfo'] ?></textarea></td>
          <td>Success URI: </td>
          <td colspan="3"><input name="surl" value="<?php echo (empty($posted['surl'])) ? '' : $posted['surl'] ?>" size="64" /></td>
          <td>Failure URI: </td>
          <td colspan="3"><input name="furl" value="<?php echo (empty($posted['furl'])) ? '' : $posted['furl'] ?>" size="64" /></td>

          <td colspan="3"><input type="hidden" name="service_provider" value="payu_paisa" size="64" /></td>

          <td><b>Optional Parameters</b></td>
          <td>Last Name: </td>
          <td><input name="lastname" id="lastname" value="<?php echo (empty($posted['lastname'])) ? '' : $posted['lastname']; ?>" /></td>
          <td>Cancel URI: </td>
          <td><input name="curl" value="" /></td>
          <td>Address1: </td>
          <td><input name="address1" value="<?php echo (empty($posted['address1'])) ? '' : $posted['address1']; ?>" /></td>
          <td>Address2: </td>
          <td><input name="address2" value="<?php echo (empty($posted['address2'])) ? '' : $posted['address2']; ?>" /></td>
          <td>City: </td>
          <td><input name="city" value="<?php echo (empty($posted['city'])) ? '' : $posted['city']; ?>" /></td>
          <td>State: </td>
          <td><input name="state" value="<?php echo (empty($posted['state'])) ? '' : $posted['state']; ?>" /></td>
          <td>Country: </td>
          <td><input name="country" value="<?php echo (empty($posted['country'])) ? '' : $posted['country']; ?>" /></td>
          <td>Zipcode: </td>
          <td><input name="zipcode" value="<?php echo (empty($posted['zipcode'])) ? '' : $posted['zipcode']; ?>" /></td>
          <td>UDF1: </td>
          <td><input name="udf1" value="<?php echo (empty($posted['udf1'])) ? '' : $posted['udf1']; ?>" /></td>
          <td>UDF2: </td>
          <td><input name="udf2" value="<?php echo (empty($posted['udf2'])) ? '' : $posted['udf2']; ?>" /></td>
          <td>UDF3: </td>
          <td><input name="udf3" value="<?php echo (empty($posted['udf3'])) ? '' : $posted['udf3']; ?>" /></td>
          <td>UDF4: </td>
          <td><input name="udf4" value="<?php echo (empty($posted['udf4'])) ? '' : $posted['udf4']; ?>" /></td>
          <td>UDF5: </td>
          <td><input name="udf5" value="<?php echo (empty($posted['udf5'])) ? '' : $posted['udf5']; ?>" /></td>
          <td>PG: </td>
          <td><input name="pg" value="<?php echo (empty($posted['pg'])) ? '' : $posted['pg']; ?>" /></td>
          <?php if(!$hash) { ?>
            <td colspan="4"><input type="submit" value="Submit" /></td>
          <?php } ?>

Note : The above code will work for both Test & Live integration provided you make changes according in the below section of the code.

// Merchant key here as provided by PayUMoney

// Merchant Salt as provided by PayUMoney
$SALT = "yIEkykqEH3";

// End point - change to for LIVE mode
$PAYU_BASE_URL = ""; (For testing purposes)

10. Also once you have implemented the test feature, you can only test it by entering the below mentioned Card details for your payment to be successful.

Test Card Number: 5123456789012346
Test CVV: 123
Test Expiry: May 2017

Phase -2 (Live Integration):

1. In order to integrate PayUMoney on to your live website, you will first have to create your Merchant account(this time with your actual credentials)
2. Follow all the desired steps and documentation needed.
3. PayUMoney asks for a set of documents which the Merchant is suppose to submit online as well as offline in order to generate his Salt key.
4. Once all the above steps are completed successfully PayUMoney generates your Merchant Key & Salt Key.
5. You just need to replace the key details in the PayUMoney Index.php code and also change the End point to for LIVE mode.\


Michael Patterson sat down with the CEO of Boston Byte, Mustapha Shaikh to discuss the significance and rapid digitization of the healthcar...