admin

python.ds.com@gmail.com

PayU Payment Gateway integration in PHP CodeIgniter

Posted on February 15, 2021



class Order_Api extends CI_Controller

{

     public function __construct()

    {

        parent::__construct();

       date_default_timezone_set('Asia/Kolkata');

     }

     public function payU()

    {

         $MERCHANT_KEY = "";

        $SALT = "";

       // Merchant Key and Salt as provided by Payu.

      $PAYU_BASE_URL = "https://sandboxsecure.payu.in"; // For Sandbox Mode

      $PAYU_BASE_URL = "https://secure.payu.in"; // For Production Mode

     $action = '';

      $posted = array();

     $hash = '';

    if(empty($posted['txnid'])) {

    // Generate random transaction id

    $txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);

    } else {

      $txnid = $posted['txnid'];

   }

$orderData = array('txnid' => $txnid );

$extra = $discount_id.'||'.$delivery_id.'||'.$delivery_amount.'||'.$discount_amount;

$amount = 10;

$name = "Vishavjeet Singh";

$email = "xyz@gmail.com";

$phone = "88888xxxxx";

$productinfo = array();

$surl = SUCCESSURL;

$furl = "https://www.python-ds.com/failde";

$curl = "https://www.python-ds.com/canceled";

$udf1 = $user_id;

$udf2 = $token;

$udf3 = $order_id;

$udf4 = $discount_id;

$udf5 = "";

$posted['key']=$MERCHANT_KEY;

$posted['hash']=$hash;

$posted['txnid']=$txnid;

$posted['amount']=$amount;

$posted['firstname']=$name;

$posted['email']=$email;

$posted['phone']=$phone;

$posted['productinfo']=$productinfo;

$posted['surl']=$surl;

$posted['furl']=$furl;

$posted['curl']=$curl;

$posted['udf1']=$udf1;

$posted['udf2']=$udf2;

$posted['udf3']=$udf3;

$posted['udf4']=$udf4;

$posted['udf5']=$udf5;

$posted['service_provider']='payu_paisa';

$hash = '';

$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';

$form = '

<form action="'.$action.'" method="post" name="payU_submit" id="payU_submit">

<input type="hidden" name="key" value="'.$MERCHANT_KEY.'" />

<input type="hidden" name="hash" value="'.$hash.'"/>

<input type="hidden" name="txnid" value="'.$txnid.'" />

<input type="hidden" name="amount" value="'.$amount.'" />

<input type="hidden" name="firstname" id="firstname" value="'.$name.'" />

<input type="hidden" name="email" id="email" value="'.$email.'" />

<input type="hidden" name="phone" value="'.$phone.'" />

<textarea hidden name="productinfo">'.$productinfo.'</textarea>

<input type="hidden" name="surl" value="'.$surl.'" />

<input type="hidden" name="furl" value="'.$furl.'" />

<input type="hidden" name="curl" value="'.$curl.'" />

<input type="hidden" name="udf1" value="'.$udf1.'" />

<input type="hidden" name="udf2" value="'.$udf2.'" />

<input type="hidden" name="udf3" value="'.$udf3.'" />

<input type="hidden" name="udf4" value="'.$udf4.'" />

<input type="hidden" name="udf5" value="'.$udf5.'" />

<input type="hidden" name="service_provider" value="payu_paisa" />

</form>

<script>

document.getElementById("payU_submit").submit();

</script>';

';

}

public function successPayment()

{

$user_id = $_REQUEST['udf1'];

$token = $_REQUEST['udf2'];

$order_id = $_REQUEST['udf3'];

$discount_id = $_REQUEST['udf4'];

$payuMoneyId = $_REQUEST['payuMoneyId'];

$mihpayid = $_REQUEST['mihpayid'];

$txnid = $_REQUEST['txnid'];

}

public function failurePayment()

{

$user_id = $_REQUEST['udf1'];

$token = $_REQUEST['udf2'];

$order_id = $_REQUEST['udf3'];

$discount_id = $_REQUEST['udf4'];

$payuMoneyId = $_REQUEST['payuMoneyId'];

$mihpayid = $_REQUEST['mihpayid'];

$txnid = $_REQUEST['txnid'];

}

public function cancelPayment()

{

           $user_id = $_REQUEST['udf1'];

            $token = $_REQUEST['udf2'];

             $order_id = $_REQUEST['udf3'];

               $discount_id = $_REQUEST['udf4'];

          $payuMoneyId = $_REQUEST['payuMoneyId'];

          $mihpayid = $_REQUEST['mihpayid'];

      $txnid = $_REQUEST['txnid'];

   } 

}


Sign In for comment and like the post.