抱歉发生了一些错误'在测试模式下集成PayUMoney支付网关

时间:2014-05-21 04:19:24

标签: php integration payment-gateway payu payumoney

我试图在我的客户端网站中集成 PayUMoney 支付网关。我的客户向我提供了 PayUMoney 的登录详细信息。我能够找到商家密钥但找不到两者中的任何一个:

  1. 商人盐
  2. 我可以在沙盒上创建测试帐户和测试的开发者网站
  3. PayUMoney 为我提供了一个默认值的表单,但是当我测试时,它会给出消息:抱歉发生了一些错误。

    以下是表格:

    <?php
    // Merchant key here as provided by Payu
    $MERCHANT_KEY = "JBZaLc";
    
    // Merchant Salt as provided by Payu
    $SALT = "GQs7yium";
    
    // End point - change to https://secure.payu.in for LIVE mode
    $PAYU_BASE_URL = "https://test.payu.in";
    
    $action = '';
    
    $posted = array();
    if(!empty($_POST)) {
    //print_r($_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) {
    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'])
          || empty($posted['service_provider'])
    ) {
    $formError = 1;
    } else {
    //$posted['productinfo'] = json_encode(json_decode('[{"name":"tutionfee","description":"","value":"500","isRequired":"false"},{"name":"developmentfee","description":"monthly tution     fee","value":"1500","isRequired":"false"}]'));
    $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>PayU Form</h2>
    <br/>
    <?php if($formError) { ?>
      <span style="color:red">Please fill all mandatory fields.</span>
      <br/>
      <br/>
    <?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 ?>" />
      <table>
        <tr>
          <td><b>Mandatory Parameters</b></td>
        </tr>
        <tr>
          <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>
        </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 Info: </td>
          <td colspan="3"><textarea name="productinfo"><?php echo (empty($posted['productinfo'])) ? '' : $posted['productinfo'] ?></textarea></td>
        </tr>
        <tr>
          <td>Success URI: </td>
          <td colspan="3"><input name="surl" value="<?php echo (empty($posted['surl'])) ? '' : $posted['surl'] ?>" size="64" /></td>
        </tr>
        <tr>
          <td>Failure URI: </td>
          <td colspan="3"><input name="furl" value="<?php echo (empty($posted['furl'])) ?     '' : $posted['furl'] ?>" size="64" /></td>
        </tr>
    
        <tr>
          <td>Service Provider: </td>
          <td colspan="3"><input name="service_provider" value="<?php echo (empty($posted['service_provider'])) ? '' : $posted['service_provider'] ?>" size="64" /></td>
        </tr>
    
        <tr>
          <td><b>Optional Parameters</b></td>
        </tr>
        <tr>
          <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>
        </tr>
        <tr>
          <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>
        </tr>
        <tr>
          <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>
        </tr>
        <tr>
          <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>
        </tr>
        <tr>
          <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>
        </tr>
        <tr>
          <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>
        </tr>
        <tr>
          <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>
        </tr>
        <tr>
          <?php if(!$hash) { ?>
            <td colspan="4"><input type="submit" value="Submit" /></td>
          <?php } ?>
        </tr>
      </table>
    </form>
    </body>
    </html>
    

10 个答案:

答案 0 :(得分:30)

这对第一批人来说很困惑。提供的默认keysalt将无法立即生效。

为了使用测试密钥和salt测试网关,请按照以下步骤操作:

  
      
  1. 继续test.payumoney.com
  2.   
  3. 注册为商家 - 使用任何商家   您的有效电子邮件ID - 请不要使用随机电子邮件ID。
  4.   
  5. 填写“商家详情” - 您可以使用PAN号码。 ABCDE1234F和   DOB - 01/04/1990
  6.   
  7. 完成“银行帐户详细信息”(您可以使用   IFSC- ALLA0212632)
  8.   
  9. 您不必担心银行验证步骤或之后的任何其他步骤。
  10.   
  11. 转到下面提到的位置进行测试   商家ID:卖方信息中心 - &gt;设置 - &gt;我的帐户 - &gt;轮廓   设置

  12.   
  13. 之后,使用contact us表单将测试商家ID发送给技术团队,他们将批准。

  14.   
  15. 一旦获得批准,您可以在以下位置找到您的测试密钥和盐:卖方仪表板 - &gt;设置 - &gt;我的帐户 - &gt;商人钥匙 - 盐。
  16.   
  17. 将默认keysalt替换为新生成的测试keysalt。在此之后你不应该看到错误,抱歉,发生了一些问题。
  18.   

我希望这会有所帮助。

答案 1 :(得分:12)

payumoney提供的密钥和盐无效使用以下内容进行测试:

// Merchant key here as provided by Payu
$MERCHANT_KEY = "gtKFFx";

// Merchant Salt as provided by Payu
$SALT = "eCwWELxi";

并确保将服务提供商字段留空。

答案 2 :(得分:9)

表单中有一个“服务提供商”字段(参数名称为 - service_provider)。该字段的值应为'payu_paisa'。如果您在表单中填写此字段中的任何其他内容,则会收到错误。

答案 3 :(得分:7)

将“服务提供商”字段留空。 这应该有用。

答案 4 :(得分:6)

最后我才知道他们没有激活测试帐户。

答案 5 :(得分:1)

试试这个:

<?php
/**
 * Returns the pay page url or the merchant js file.
 * 
 * @param unknown $params           
 * @param unknown $salt         
 * @throws Exception
 * @return Ambigous <multitype:number string , multitype:number Ambigous <boolean, string> >
 */
function pay ( $params, $salt )
{
    if ( ! is_array( $params ) ) throw new Exception( 'Pay params is empty' );

    if ( empty( $salt ) ) throw new Exception( 'Salt is empty' );

    $payment = new Payment( $salt );
    $result = $payment->pay( $params );
    unset( $payment );

    return $result;
}

/**
 * Displays the pay page.
 * 
 * @param unknown $params           
 * @param unknown $salt         
 * @throws Exception
 */
function pay_page ( $params, $salt )
{
    if ( count( $_POST ) && isset( $_POST['mihpayid'] ) && ! empty( $_POST['mihpayid'] ) ) {
        $_POST['surl'] = $params['surl'];
        $_POST['furl'] = $params['furl'];

        $result = response( $_POST, $salt );
        Misc::show_reponse( $result );
    } else {
        $host = (isset( $_SERVER['https'] ) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

        if ( isset( $_SERVER['REQUEST_URI'] ) && ! empty( $_SERVER['REQUEST_URI'] ) ) $params['surl'] = $host;
        if ( isset( $_SERVER['REQUEST_URI'] ) && ! empty( $_SERVER['REQUEST_URI'] ) ) $params['furl'] = $host;

        $result = pay( $params, $salt );
        Misc::show_page( $result );
    }
}

/**
 * Returns the response object.
 * 
 * @param unknown $params           
 * @param unknown $salt         
 * @throws Exception
 * @return number
 */
function response ( $params, $salt )
{
    if ( ! is_array( $params ) ) throw new Exception( 'PayU response params is empty' );

    if ( empty( $salt ) ) throw new Exception( 'Salt is empty' );

    if ( empty( $params['status'] ) ) throw new Exception( 'Status is empty' );

    $response = new Response( $salt );
    $result = $response->get_response( $_POST );
    unset( $response );

    return $result;
}

/**
 * Basic autoloader
 * 
 * @param classname $file           
 *
define( 'INCLUDE_PATH', dirname( __FILE__ ) . '/src/' );
function __autoload ( $file )
{
    require_once INCLUDE_PATH . $file . '.php';
}
*/

/* Should libcurl or curl.so be absent. */

if ( ! function_exists( 'curl_init' ) ) :

    define( 'CURLOPT_URL', 1 );
    define( 'CURLOPT_USERAGENT', 2 );
    define( 'CURLOPT_POST', 3 );
    define( 'CURLOPT_POSTFIELDS', 4 );
    define( 'CURLOPT_RETURNTRANSFER', 5 );
    define( 'CURLOPT_REFERER', 6 );
    define( 'CURLOPT_HEADER', 7 );
    define( 'CURLOPT_TIMEOUT', 8 );
    define( 'CURLOPT_CONNECTTIMEOUT', 9 );
    define( 'CURLOPT_FOLLOWLOCATION', 10 );
    define( 'CURLOPT_AUTOREFERER', 11 );
    define( 'CURLOPT_PROXY', 12 );
    define( 'CURLOPT_PORT', 13 );
    define( 'CURLOPT_HTTPHEADER', 14 );
    define( 'CURLOPT_SSL_VERIFYHOST', 15 );
    define( 'CURLOPT_SSL_VERIFYPEER', 16 );

    function curl_init ( $url = false )
    {
        return new Curl( $url );
    }

    function curl_setopt ( &$ch, $name, $value )
    {
        $ch->setopt( $name, $value );
    }

    function curl_exec ( $ch )
    {
        return $ch->exec();
    }

    function curl_close ( &$ch )
    {
        unset( $ch );
    }

    function curl_errno ( $ch )
    {
        return $ch->error;
    }

    function curl_error ( $ch_error )
    {
        return "Could not open socket";
    }

    function curl_getinfo ( $ch, $opt = NULL )
    {
        return $ch->info;
    }

    function curl_setopt_array ( &$ch, $opt )
    {
        $ch->setoptArray( $opt );
    }



endif;


class Curl {
    private $url = "";
    private $user_agent = "libCurl";
    private $return_result = false;
    private $referrer = false;
    private $cookies_on = false;
    private $proxy = array ();
    private $timeout = 30;
    private $cookies;
    private $headers;
    private $method = "GET";
    private $httpHeader = "application/x-www-form-urlencoded";

    public $error = 0;
    public $info = array ();

    function __construct ( $url = false )
    {
        $this->cookies = new Cookies();
        $this->url = $url;
        $this->info['total_time'] = time();
    }

    function __destruct ()
    {}

    private function getHost ( $url )
    {
        $url = str_replace( array ( "http://", "https://" ), "", $url );
        $tmp = explode( "/", $url );
        return $tmp[0];
    }

    private function getQuery ( $url )
    {
        $url = str_replace( array ( "http://", "https://" ), "", $url );
        $tmp = explode( "/", $url, 2 );
        return "/" . $tmp[1];
    }

    private function _parseRawData ( $rawData )
    {
        $array = explode( "\r\n\r\n", $rawData, 2 );
        $this->header_data = $array[0];
        $this->content = $array[1];
        $this->_parseHeaders( $array[0] );
    }

    private function _parseHeaders ( $rawHeaders )
    {
        $rawHeaders = trim( $rawHeaders );
        $headers = explode( "\r\n", $rawHeaders );

        foreach ( $headers as $header ) {
            if ( preg_match( "|http/1\.. (\d+)|i", $header, $match ) ) {
                $this->status_code = $match[1];
                continue;
            }

            $headerArray = explode( ":", $header );
            $headerName = trim( $headerArray[0] );
            $headerValue = trim( $headerArray[1] );

            if ( preg_match( "|set-cookie2?|i", $headerName ) ) $this->cookies->add( $headerValue );
            if ( isset( $headerName ) ) $this->headers[strtolower( $headerName )] = $headerValue;
        }

        if ( isset( $this->headers["location"] ) ) {
            $this->url = $this->headers["location"];
            $this->exec();
        }
    }

    public function setopt ( $name, $value = false )
    {
        switch ( $name ) {
        case CURLOPT_URL :
            $this->url = $value;
            $this->proxy["port"] = substr( $this->url, 0, 5 ) === 'https' ? 443 : 80;
            break;
        case CURLOPT_USERAGENT :
            $this->user_agent = $value;
            break;
        case CURLOPT_POST :
            $this->method = ($value == true) ? "POST" : "GET";
            break;
        case CURLOPT_POSTFIELDS :
            $this->post_data = $value;
            break;
        case CURLOPT_RETURNTRANSFER :
            $this->return_result = ($value == true);
            break;
        case CURLOPT_REFERER :
            $this->referrer = $value;
            break;
        case CURLOPT_HEADER :
            $this->options["header"] = ($value == true);
            break;
        case CURLOPT_PROXY :
            list ( $this->proxy["host"], $this->proxy["port"] ) = explode( ":", $value );
            break;
        case CURLOPT_CONNECTTIMEOUT : /* Fall through. */
        case CURLOPT_TIMEOUT :
            $this->timeout = ($value >= 0) ? $value : 30;
            break;
        case CURLOPT_PORT :
            $this->proxy["port"] = $value ? $value : (substr( $this->url, 0, 5 ) === 'https' ? 443 : 80);
            break;
        case CURLOPT_HTTPHEADER :
            $this->httpHeader = substr( implode( ";", $value ), 0, - 1 );
            break;
        }
    }

    public function setoptArray ( $options )
    {
        foreach ( $options as $name => $value )
            $this->setopt( $name, $value );
    }

    public function exec ()
    {
        $errno = false;
        $errstr = false;
        $url = $this->url;

        $host = $this->getHost( $url );
        $query = $this->getQuery( $url );

        $this->proxy["host"] = $host;

        if ( isset( $this->proxy["port"] ) ) {
            $this->proxy["host"] = (443 === $this->proxy["port"]) ? "ssl://$host" : $host;
            $fp = pfsockopen( $this->proxy["host"], $this->proxy["port"], $errno, $errstr, $this->timeout );
            $request = $query;
        } else {
            $fp = pfsockopen( $host, 80, $errno, $errstr, $this->timeout );
            $request = $query;
        }

        if ( ! $fp ) { /*trigger_error($errstr, E_WARNING);*/ $this->error = 1;
            return;
        }

        $headers = $this->method . " $request HTTP/1.0 \r\nHost: $host \r\n";
        if ( $this->user_agent ) $headers .= "User-Agent: " . $this->user_agent . "\r\n";
        if ( $this->referrer ) $headers .= "Referer: " . $this->referrer . "\r\n";
        if ( $this->method == "POST" ) {
            $headers .= "Content-Type: " . $this->httpHeader . "\r\n";
            $headers .= "Content-Length: " . strlen( $this->post_data ) . "\r\n";
        }

        if ( $this->cookies_on ) $headers .= $this->cookies->createHeader();
        $headers .= "Connection: Close\r\n\r\n";
        if ( "POST" == $this->method ) $headers .= $this->post_data;
        $headers .= "\r\n\r\n";

        fwrite( $fp, $headers );
        $rawData = "";
        while ( ! feof( $fp ) )
            $rawData .= fread( $fp, 512 );
            /* fclose($fp); /* Too lazy to read the docs.*/
        $this->info['total_time'] = time() - $this->info['total_time'];

        $this->_parseRawData( $rawData );
        if ( $this->options["header"] ) $this->content = $rawData;
        if ( $this->return_result ) return $this->content;
        echo $this->content;
    }

}

class Cookies {
    private $cookies;

    function __construct ()
    {}

    function __destruct ()
    {}

    public function add ( $cookie )
    {
        list ( $data, $etc ) = explode( ";", $cookie, 2 );
        list ( $name, $value ) = explode( "=", $data );
        $this->cookies[trim( $name )] = trim( $value );
    }

    public function createHeader ()
    {
        if ( 0 == count( $this->cookies ) || ! is_array( $this->cookies ) ) return "";
        $output = "";
        foreach ( $this->cookies as $name => $value )
            $output .= "$name=$value; ";
        return "Cookies: $output\r\n";
    }

}

class Misc {

    const SUCCESS = 1;
    const FAILURE = 0;

    public static function get_hash ( $params, $salt )
    {
        $posted = array ();

        if ( ! empty( $params ) ) foreach ( $params as $key => $value )
            $posted[$key] = htmlentities( $value, ENT_QUOTES );

        $hash_sequence = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10";

        $hash_vars_seq = explode( '|', $hash_sequence );
        $hash_string = null;

        foreach ( $hash_vars_seq as $hash_var ) {
            $hash_string .= isset( $posted[$hash_var] ) ? $posted[$hash_var] : '';
            $hash_string .= '|';
        }

        $hash_string .= $salt;
        return strtolower( hash( 'sha512', $hash_string ) );
    }

    public static function reverse_hash ( $params, $salt, $status )
    {
        $posted = array ();
        $hash_string = null;

        if ( ! empty( $params ) ) foreach ( $params as $key => $value )
            $posted[$key] = htmlentities( $value, ENT_QUOTES );

        $additional_hash_sequence = 'base_merchantid|base_payuid|miles|additional_charges';
        $hash_vars_seq = explode( '|', $additional_hash_sequence );

        foreach ( $hash_vars_seq as $hash_var )
            $hash_string .= isset( $posted[$hash_var] ) ? $posted[$hash_var] . '|' : '';

        $hash_sequence = "udf10|udf9|udf8|udf7|udf6|udf5|udf4|udf3|udf2|udf1|email|firstname|productinfo|amount|txnid|key";
        $hash_vars_seq = explode( '|', $hash_sequence );
        $hash_string .= $salt . '|' . $status;

        foreach ( $hash_vars_seq as $hash_var ) {
            $hash_string .= '|';
            $hash_string .= isset( $posted[$hash_var] ) ? $posted[$hash_var] : '';
        }

        return strtolower( hash( 'sha512', $hash_string ) );
    }

    public static function curl_call ( $url, $data )
    {
        $ch = curl_init();

        curl_setopt_array( $ch, array ( 
            CURLOPT_URL => $url, 
            CURLOPT_POSTFIELDS => $data, 
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_POST => true, 
            CURLOPT_RETURNTRANSFER => true, 
            CURLOPT_USERAGENT => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36', 
            CURLOPT_SSL_VERIFYHOST => 0, 
            CURLOPT_SSL_VERIFYPEER => 0 ) );

        $o = curl_exec( $ch );

        if ( curl_errno( $ch ) ) {
            $c_error = curl_error( $ch );

            if ( empty( $c_error ) ) $c_error = 'Server Error';

            return array ( 'curl_status' => Misc::FAILURE, 'error' => $c_error );
        }

        $o = trim( $o );
        return array ( 'curl_status' => Misc::SUCCESS, 'result' => $o );
    }

    public static function show_page ( $result )
    {

        if ( $result['status'] === Misc::SUCCESS )
            header( 'Location:' . $result['data'] );
        else
            throw new Exception( $result['data'] );
    }

    public static function show_reponse ( $result )
    {
        if ( $result['status'] === Misc::SUCCESS )
            $result['data']();
        else
            return $result['data'];
    }

}



class Payment {

    private $url;
    private $salt;
    private $params = array ();

    public function __construct ( $salt, $env = 'test' )
    {
        $this->salt = $salt;

        switch ( $env ) {
        case 'test' :
            $this->url = 'https://test.payu.in/';
            break;
        case 'prod' :
            $this->url = 'https://secure.payu.in/';
            break;
        default :
            $this->url = 'https://test.payu.in/';
        }
    }

    public function __destruct ()
    {
        unset( $this->url );
        unset( $this->salt );
        unset( $this->params );
    }

    public function __set ( $key, $value )
    {
        $this->params[$key] = $value;
    }

    public function __get ( $key )
    {
        return $this->params[$key];
    }

    public function pay ( $params = null )
    {
        if ( is_array( $params ) ) foreach ( $params as $key => $value )
            $this->params[$key] = $value;

        $error = $this->check_params();

        if ( $error === true ) {
            $this->params['hash'] = Misc::get_hash( $this->params, $this->salt );
            $result = Misc::curl_call( $this->url . '_payment?type=merchant_txn', http_build_query( $this->params ) );
            $transaction_id = ($result['curl_status'] === Misc::SUCCESS) ? $result['result'] : null;

            if ( empty( $transaction_id ) ) return array ( 
                'status' => Misc::FAILURE, 
                'data' => $result['error'] );

            return array ( 
                'status' => Misc::SUCCESS, 
                'data' => $this->url . '_payment_options?mihpayid=' . $transaction_id );
        } else {
            return array ( 'status' => Misc::FAILURE, 'data' => $error );
        }
    }

    private function check_params ()
    {
        if ( empty( $this->params['key'] ) ) return $this->error( 'key' );
        if ( empty( $this->params['txnid'] ) ) return $this->error( 'txnid' );
        if ( empty( $this->params['amount'] ) ) return $this->error( 'amount' );
        if ( empty( $this->params['firstname'] ) ) return $this->error( 'firstname' );
        if ( empty( $this->params['email'] ) ) return $this->error( 'email' );
        if ( empty( $this->params['phone'] ) ) return $this->error( 'phone' );
        if ( empty( $this->params['productinfo'] ) ) return $this->error( 'productinfo' );
        if ( empty( $this->params['surl'] ) ) return $this->error( 'surl' );
        if ( empty( $this->params['furl'] ) ) return $this->error( 'furl' );

        return true;
    }

    private function error ( $key )
    {
        return 'Mandatory parameter ' . $key . ' is empty';
    }

}


class Response {

    private $salt;
    private $params = array ();

    public function __construct ( $salt )
    {
        $this->salt = $salt;
    }

    public function __destruct ()
    {
        unset( $this->salt );
        unset( $this->params );
    }

    public function __set ( $key, $value )
    {
        $this->params[$key] = $value;
    }

    public function __get ( $key )
    {
        return $this->params[$key];
    }

    public function get_response ( $params = null )
    {
        $this->params = (is_array( $params ) && count( $params )) ? $params : $_POST;

        $error = $this->check_params();

        if ( $error === true ) {
            if ( Misc::reverse_hash( $this->params, $this->salt, $this->params['status'] ) === $this->params['hash'] ) {
                switch ( $this->params['status'] ) {
                case 'success' :
                    return array ( 
                        'status' => Misc::SUCCESS, 
                        'data' => $this->params['surl'] );
                    break;
                case 'failure' :
                    return array ( 
                        'status' => Misc::SUCCESS, 
                        'data' => $this->params['furl'] );
                    break;
                default :
                    return array ( 
                        'status' => Misc::FAILURE, 
                        'data' => 'Unmapped status' );
                }
            } else {
                return array ( 
                    'status' => Misc::FAILURE, 
                    'data' => 'Hash Mismatch' );
            }
        } else {
            return array ( 'status' => Misc::FAILURE, 'data' => $error );
        }

    }

    private function check_params ()
    {
        if ( empty( $this->params['key'] ) ) return $this->error( 'key' );
        if ( empty( $this->params['txnid'] ) ) return $this->error( 'txnid' );
        if ( empty( $this->params['amount'] ) ) return $this->error( 'amount' );
        if ( empty( $this->params['firstname'] ) ) return $this->error( 'firstname' );
        if ( empty( $this->params['email'] ) ) return $this->error( 'email' );
        if ( empty( $this->params['phone'] ) ) return $this->error( 'phone' );
        if ( empty( $this->params['productinfo'] ) ) return $this->error( 'productinfo' );
        if ( empty( $this->params['surl'] ) ) return $this->error( 'surl' );
        if ( empty( $this->params['furl'] ) ) return $this->error( 'furl' );
        return true;
    }

    private function error ( $key )
    {
        return 'Mandatory parameter ' . $key . ' is empty';
    }

}
$txnid = uniqid();
$response = pay_page( array ('key' => 'tradus', 'txnid' => uniqid( 'animesh_' ), 'amount' => rand( 0, 100 ),'firstname' => 'animesh', 'email' => 'animesh.kundu@payu.in', 'phone' => '1234567890','productinfo' => 'This is shit', 'surl' => 'payment_success', 'furl' => 'payment_failure'), '200' );

?>

答案 6 :(得分:1)

如果您使用默认表单并且它要求Product Info,它也会造成麻烦。在他们的PDF文档中,他们给出了像这样的产品信息的json格式 -

&#13;
&#13;
{“paymentParts”:[{ "name":"abc",
"description":"abcd",
"value":"500",
"isRequired":"true",
“settlementEvent” : “EmailConfirmation” },
{
"name":"xyz",
"description":"wxyz",
"value":"1500",
"isRequired":"false",
“settlementEvent”: “EmailConfirmation” }],
{“paymentIdentifiers”:[{ "field":"CompletionDate",
}, {
"value":"31/10/2012”
"field":"TxnId", "value":"abced"
}]}
&#13;
&#13;
&#13;

将此json插入Product Info textarea可能有助于您解决问题。

答案 7 :(得分:1)

Payumoney更改了TEST KEY和TEST SALT

为了让测试模式正常工作,请将这些凭据与测试网址

一起使用
Test Key - rjQUPktU 
Test Salt - e5iIg1jwi8

仍然面临问题,然后尝试按照步骤

  

您使用的是正确的商家密钥吗?在许多购物车中,使用的字段名称“商家ID”被错误地用于代替商家密钥。但是,实际需要输入的是PayUmoney提供的“商家密钥”。请注意,我们会向您发送一封电子邮件,其中包含以下3个详细信息:

     

(1)商家ID
  (2)商家钥匙
  (3)商人盐
  
  PayUmoney与您的网站集成时不需要PayUmoney发送的商家ID。这只是您在PayUmoney的注册号码。因此,集成中使用的唯一2个信息是Merchant Key&amp;商人盐。   您是在实时模式下使用测试凭据还是在测试模式下使用实时凭据?如果是,请确保在实时模式下使用测试模式下的测试凭据和实时凭据。请确保在测试模式下,您只使用下面提到的测试凭证 -

  测试键 - rjQUPktU
  试验盐 - e5iIg1jwi8

  你有所有的批准吗?

如果您的批准尚待批准,即使您正在做正确的事情,也很可能会出现此错误。请使用以下链接安排呼叫,以联系支持团队以获取帮助:   https://calendly.com/payumoney-integration/30_minutes

答案 8 :(得分:0)

最近,PayUMoney在测试环境中做了一些修改,因为测试密钥-JBZaLc和salt-GQs7yium将不再起作用。

为了使用测试密钥和salt测试网关,您必须这样做 继续test.payumoney.com并注册成为商家。因此,您将获得商家ID和Salt ID。

答案 9 :(得分:0)

对于 PayU APIs Asp per doc 和其他参考 API 参考:https://www.payumoney.com/dev-guide/apireference.html

初始启用测试模式,可以使用沙盒 URL 来测试 API 测试模式:https://developer.payumoney.com/test-mode/ 在测试模式下测试 API 您可以使用您的测试凭证在测试模式下测试 PayUmoney 提供的所有 API。要在沙盒中测试 API,请在您调用的 API 的相关 URL 的开头添加 /sandbox,并确保您在 API 请求中传递测试授权标头。

例如,要测试检查商家交易状态 API:

生产网址是

https://www.payumoney.com/payment/payment/chkMerchantTxnStatus

在测试模式下:

https://www.payumoney.com/sandbox/payment/payment/chkMerchantTxnStatus