Search code examples
codeigniterpaymentgatewaypayumoney

Payumoney Error while integrating codeigniter


I am working on codeigniter and integrating the payumoney payment gateway. Here I have a registration form and there are various fields in the form Now what I am doing I want to add payumoney payment gateway but the problem is this when I add write the fname or amount from myself the it works fine but while I use $this->input->post('first_name') It shows error like follows click to view the image (Here is the error in the image)

Here is the data variables the values for data array

My code is follows :

function checkout() {
        $this->load->config('payu');
        $MERCHANT_KEY = $this->config->item('MERCHANT_KEY');
        $SALT = $this->config->item('SALT');
        $PAYU_BASE_URL = $this->config->item('PAYU_BASE_URL');
        $action = '';
        $txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);

        $udf1 = '';
        $udf2 = '';
        $udf3 = '';
        $udf4 = '';
        $udf5 = '';
        $amount = $this->input->post('corporate_plan_rate');
        $productinfo = 'test';
        $fname = $this->input->post('user_name');
        $email = $this->input->post('user_email');


        $data = array(
            'mkey' => $MERCHANT_KEY,
            'tid' => $txnid,
            'MERCHANT_KEY'=>$MERCHANT_KEY,
            'txnid'=>$txnid,
            'SALT'=>$SALT,
//          'hash' => $hash,
            'amount' => $amount,
            'pinfo' => $productinfo,
            'name' => $fname,
            'productinfo'=>$productinfo,
            'mailid' => $email,
            'phoneno' => '9646403748',
            'udf1' => $udf1,
            'udf2' => $udf2,
            'udf3' => $udf3,
            'udf4' => $udf4,
            'udf5' => $udf5,
        );

        $this->load->view('payu/checkout.php', $data);
    }

and here is my view page:

<html>
    <head>
        <!--<script src="//code.jquery.com/jquery.min.js"></script>-->
        <script>
//          $(function () {
//              setTimeout(function () {
//                  $('form').submit();
//              }, 2000)
//          });
        </script>
    </head>
    <body>
        <?php
        $hashstring = $MERCHANT_KEY . '|' . $txnid . '|' . $amount . '|' . $productinfo . '|' . $name . '|' . $mailid . '|' . $udf1 . '|' . $udf2 . '|' . $udf3 . '|' . $udf4 . '|' . $udf5 . '||||||' . $SALT;

        $hash = strtolower(hash('sha512', $hashstring));
        ?>
        <h2>PayU Form</h2>
        <br/>
        <form method="post" name="payuForm" action="https://test.payu.in/_payment">

            <input name="key" type="hidden" value="<?php echo $mkey ?>" />
            <input name="txnid" type="hidden"  value="<?php echo $tid ?>" />
            <input type="hidden" name="hash" value="<?php echo $hash ?>"/>

            <input name="amount" type="hidden" value="<?php echo $amount; ?>" />

            <input name="productinfo" type="hidden" value="<?php echo $pinfo; ?>">

            <input type="hidden" name="service_provider" value="payu_paisa" size="64" />
            <input name="udf1" type="hidden" value="">
            <input name="udf2" type="hidden" value="">
            <input name="udf3" type="hidden" value="">
            <input name="udf4" type="hidden" value="">
            <input name="udf5" type="hidden" value="">

            <input name="firstname" id="firstname" type="hidden" value="<?php echo $name; ?>"/>

            <input name="email" id="email"  type="hidden"  value='<?php echo $mailid; ?>'>

            <input name="phone"   type="hidden"  value="<?php echo $phoneno; ?>">
            <input name="surl" type="hidden" value="<?php echo base_url('payu/success'); ?>" size="64" />
            <input name="furl" type="hidden" value="<?php echo base_url('payu/cancel'); ?>" size="64" />
            <input name="curl" type="hidden" value="<?php echo base_url('payu/cancel'); ?>" />

            <input type="submit" name="submit_form" value="Click Here for Payment" class="btn btn-info btn-block" >
        </form>
    </body>
</html>

Please help me find out the problem and resolve it out.. Thanx


Solution

  • Please completely replace your controller function with below codes

    function checkout() 
    {
    
            $MERCHANT_KEY = "enter your test merchant key here";
            $SALT = "enter your test salt here";
    
            $txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
    
            $udf1 = '';
            $udf2 = '';
            $udf3 = '';
            $udf4 = '';
            $udf5 = '';
            $amount = $this->input->post('corporate_plan_rate');
            $productinfo = 'test_payment';
            $fname = $this->input->post('user_name');
            $email = $this->input->post('user_email');
    
            $hashstring = $MERCHANT_KEY . '|' . $txnid . '|' . $amount . '|' . $productinfo . '|'. $fname . '|' . $email .'|'.$udf1.'|' .$udf2.'|' .$udf3.'|'.$udf4.'|'.$udf5.'||||||'. $SALT;
    
            $hash = strtolower(hash('sha512', $hashstring));
    
            $data = array(
                'mkey' => $MERCHANT_KEY,
                'tid' => $txnid,
                'hash' => $hash,
                'amount' => $amount,
                'pinfo' => $productinfo,
                'name' => $fname,
                'productinfo'=>$productinfo,
                'mailid' => $email,
                'phoneno' => '9646403748',
            );
    
            $this->load->view('payu/checkout', $data);
    }
    

    Now completely replace your checkout view file with following codes

    <html>
        <head>
        </head>
        <body>
    
            <h2>PayU Form</h2>
            <br/>
            <form method="post" name="payuForm" action="https://test.payu.in/_payment">
    
                <input name="key" type="hidden" value="<?php echo $mkey ?>" />
                <input name="txnid" type="hidden"  value="<?php echo $tid ?>" />
                <input type="hidden" name="hash" value="<?php echo $hash ?>"/>
    
                <input name="amount" type="hidden" value="<?php echo $amount; ?>" />
    
                <input name="productinfo" type="hidden" value="<?php echo $pinfo; ?>">
    
                <input type="hidden" name="service_provider" value="payu_paisa" size="64" />
                <input name="udf1" type="hidden" value="">
                <input name="udf2" type="hidden" value="">
                <input name="udf3" type="hidden" value="">
                <input name="udf4" type="hidden" value="">
                <input name="udf5" type="hidden" value="">
    
                <input name="firstname" id="firstname" type="hidden" value="<?php echo $name; ?>"/>
    
                <input name="email" id="email"  type="hidden"  value='<?php echo $mailid; ?>'>
    
                <input name="phone"   type="hidden"  value="<?php echo $phoneno; ?>">
    
                <input name="surl" type="hidden" value="<?php echo base_url('payu/success'); ?>" size="64" />
                <input name="furl" type="hidden" value="<?php echo base_url('payu/cancel'); ?>" size="64" />
                <input name="curl" type="hidden" value="<?php echo base_url('payu/cancel'); ?>" />
    
                <input type="submit" name="submit_form" value="Click Here for Payment" class="btn btn-info btn-block" >
            </form>
        </body>
    </html>
    

    Please try above code without adding any of your own codes for testing and if the same error occurs comment below.