payumoney logo

PayUmoney hashing using PHP

Lot of people looking for PayUmoney integration in their portals to process the payments. But everyone is searching for content which build the exact hash (PayUmoney hash). I done some code to build the clear hash. You can refer it as quick testing for PayUmoney payments .

Here I try to bind the hashing within a single function with minimum and required parameters. You may done with this in your portals.

PayUmoney Hashing function:

/**
 * This function is used to prepare PayUmoney Payment
 * @param {array} $params : Contains information of PayUmoney parameters
 * @return {array} $result : Contains processed information
 */
public static function preparePayuPayment($params)
{        
    $SS_URL = (isset($params["SS_URL"]))? $params["SS_URL"] : "";
    $FF_URL = (isset($params["FF_URL"]))? $params["FF_URL"] : "";
    $params["key"] = MERCHANT_KEY;    
    
    $hashSequence = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10";
    
    $formError = 0;
    $txnid = "";

    if(empty($params['txnid']))
    {
      $txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
    }
    else
    {
      $txnid = $params['txnid'];
    }    
    
    $params['txnid'] = $txnid;
    $hash = '';
    
    if(empty($params['hash']) && sizeof($params) > 0)
    {
        if(empty($params['txnid']) || empty($params['amount']) || empty($params['firstname']) || empty($params['email']) || empty($params['phone']) || empty($params['productinfo']))
        {
            $formError = 1;
        }
        else
        {
            $hashVarsSeq = explode('|', $hashSequence);
            $hash_string = '';    
            foreach($hashVarsSeq as $hash_var)
            {
                  $hash_string .= isset($params[$hash_var]) ? $params[$hash_var] : '';
                  $hash_string .= '|';
              }
            $hash_string .= $params["SALT_KEY"];
            $hash = strtolower(hash('sha512', $hash_string));
        }
    }
    else if(!empty($params['hash']))
    {
        $hash = $params['hash'];
    }
    
    $params["hash"] = $hash;
    return array("status"=>$formError, "params"=>$params);
}

In above code, $params variable contains all the parameters which are posted by your payment form.