0

i am developing web app that is total restful front-end using angular and backend nodejs,express and mongodb. i am trying to integrate payumoney payment gateway with my web app. Plz Go through this https://www.payumoney.com/developer-doc-api.html api is returning html page when i hit payment Endpoint https://test.payu.in/_payment. i don't know how to make user to redirect to payumoney payment page. Before All this i am getting error Checksum FailedError Returned in Html Page. iam sending data in this format

request.post({
                url: 'https://test.payu.in/_payment',
                headers: {
                    Authorization:'4sOSsCZXIopj4XvbddLX8kF7tmlTu2UZsjHVAwPt404=' 
                       },
                form:  { 
      key: 'lfX7uR',
      txnid: 578cb861e9c38ecc185ec8e7,
      firstname: 'Rayees',
      lastname: 'Mir',
      email: 'rayees@mir.com',
      phone: '9797187225',
      productinfo: '{"_id":"57611c58763eb9c0116d6def","expiryDate":"2016-09-15T09:14:00.536Z","amount":8600,"updated":"2016-06-22T13:55:43.176Z","user":"5757c59e3d47bd50118e07c7","__v":27,"status":"active","created":"2016-06-15T09:14:00.533Z","products":[{"_id":"575a9257685404601d1da5c0","quantity":3,"salesPrice":200,"addedDate":"2016-06-15T15:29:29.525Z","listPrice":50},{"_id":"575a9286ee1ca30c27abb9eb","quantity":20,"salesPrice":400,"addedDate":"2016-06-22T13:55:43.176Z","listPrice":210}]}',
      amount: 8200,
      surl: 'https://www.google.com',
      furl: 'https://www.facebook.com',
      hash: '',
      service_provider: '',
      address1: '',
      address2: '',
      city: '',
      state: '',
      country: '',
      zipcode: '',
      udf1: '',
      udf2: '',
      udf3: '',
      udf4: '',
      udf5: '',
      udf6: '',
      udf7: '',
      udf8: '',
      udf9: '',
      udf10: '' }
            },function(result){
                console.log(result);
            });
Rayees
  • 57
  • 3
  • 15

2 Answers2

0

You need to Calculate the Hash of your request data before proceeding further, according to the documentation you should create hash on server side, here is the sample code:

<?php
error_reporting(0);

$salt = "eCwWELxi"; # salt value need to be picked from your database
$amount = $_POST["amount"]; # amount need to be picked up from your database
$reverseHash = generateReverseHash();

if ($_POST["hash"] == $reverseHash) {
    # transaction is successful
    # do the required javascript task
    echo("Transaction Success & Verified");
    AndroidSuccess($_POST["amount"]);
}
else{
    # transaction is tempered
    # handle it as required
    echo("<br>");
    echo "\nInvalid transaction";
}

# For Android Success
function AndroidSuccess($input) {
    echo '<script type="text/javascript">';
    echo 'PayU.onSuccess("Amount =" +'.$_POST["amount"].')';
    echo "</script>";
}

# Function to generate reverse hash
function generateReverseHash() {
    global $salt;
    global $amount;
    if ($_POST["additional_charges"] != null) {
        $reversehash_string = $_POST["additional_charges"] . "|" . $salt . "|" . $_POST["status"]  . "||||||" . $_POST["udf5"] . "|" . $_POST["udf4"] . "|" . $_POST["udf3"] . "|" . $_POST["udf2"] . "|" . $_POST["udf1"] . "|" .
        $_POST["email"] . "|" . $_POST["firstname"] . "|" . $_POST["productinfo"] . "|" . $amount . "|" . $_POST["txnid"] . "|" . $_POST["key"] ;
    }
    else{
        $reversehash_string =  $salt . "|" . $_POST["status"]  . "||||||" . $_POST["udf5"] . "|" . $_POST["udf4"] . "|" . $_POST["udf3"] . "|" . $_POST["udf2"] . "|" . $_POST["udf1"] . "|" .
             $_POST["email"] . "|" . $_POST["firstname"] . "|" . $_POST["productinfo"] . "|" . $amount . "|" . $_POST["txnid"] . "|" . $_POST["key"] ;
    }

//  echo($reversehash_string);
    $reverseHash = strtolower(hash("sha512", $reversehash_string));
    return $reverseHash;
}
John Conde
  • 217,595
  • 99
  • 455
  • 496
Kiran Maniya
  • 8,453
  • 9
  • 58
  • 81
-1

your hash is missing try generating hash using sha512 algorithm in php, jquery request is not allowed you have to send all the parameters using form post method