Posts By vishavjeet (52)

CCVenue Payment Gateway integration in PHP CodeIgniter

#Step1: Create Library for encryption/decription


<?php

defined('BASEPATH') OR exit('No direct script access allowed');

error_reporting(0);

class Ccvenuecrypto {

function encrypt($plainText,$key)

{

$key = $this->hextobin(md5($key));

$initVector = pack("C*", 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);

$openMode = openssl_encrypt($plainText, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $initVector);

$encryptedText = bin2hex($openMode);

return $encryptedText;

}

function decrypt($encryptedText,$key)

{

$key = $this->hextobin(md5($key));

$initVector = pack("C*", 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);

$encryptedText = $this->hextobin($encryptedText);

$decryptedText = openssl_decrypt($encryptedText, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $initVector);

return $decryptedText;

}

//*********** Padding Function *********************

public function pkcs5_pad($plainText, $blockSize)

{

$pad = $blockSize - (strlen($plainText) % $blockSize);

return $plainText . str_repeat(chr($pad), $pad);

}

//********** Hexadecimal to Binary function for php 4.0 version ********

public function hextobin($hexString)

{

$length = strlen($hexString);

$binString="";

$count=0;

while($count<$length)

{

$subString =substr($hexString,$count,2);

$packedString = pack("H*",$subString);

if ($count==0)

{

$binString=$packedString;

}

else

{

$binString.=$packedString;

}

$count+=2;

}

return $binString;

}

}


#Step2: Create Controller for logic

class Order_Api extends CI_Controller

{

public function __construct()

{

parent::__construct();

$this->load->library('ccvenuecrypto');

date_default_timezone_set('Asia/Kolkata');

}


    public function ccvpayementform()

{

$tid=time();

$shippingData = $this->Front_model->getDataRow('billing_shippings', 'billing_shipping_id', $billing_shipping_id);

$name = "Vishavjeet Singh";

$email = "xyz@gmail.com";

$phone = "8888XXXXX";

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

$en_order_id=$order_id+12844;

$merchant_data="$en_order_id=$token";

$encrypted_order_id=$this->ccvenuecrypto->encrypt($merchant_data,$working_key);

// Method for encrypting the data.

$action= CCVENUEREQUESTHANDLE;

$form = '<form method="POST" name="customerData" id="ccVenue_submit" action="'.$action.'">

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

<input type="hidden" name="merchant_id" value="XXXXX" />

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

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

<input type="hidden" name="currency" value="INR"/>

<input type="hidden" name="redirect_url" value="'.CCVENUEREDIRECTURL.'" />

<input type="hidden" name="cancel_url" value="'.CCVENUECANCELURL.'" />

<input type="hidden" name="language" value="EN"/>

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

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

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

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

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

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

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

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

<input type="hidden" name="customer_identifier" value=""/>

<INPUT TYPE="submit" value="CheckOut">

<p>Payment Redirect to CCAVENUES, Please wait...</p>

</form>

<script>document.getElementById("ccVenue_submit").submit();</script>';

}

public function ccavRequestHandler()

{

$this->load->library('ccvenuecrypto');

error_reporting(0);

$merchant_data='XXXX';

$working_key='XYZ';

//Shared by CCAVENUES

$access_code='XXXXX';//Shared by CCAVENUES

$rcvdString=$this->ccvenuecrypto->decrypt($_POST['merchant_param5'],$workingKey);

$decryptValues=explode('=', $rcvdString);

$oid=$decryptValues[0]-12844; // Custom decription as per your need

$token=$decryptValues[1];

$user_id=$_POST['merchant_param1'];

if($oid!=$_POST['order_id'])

{

$this->failureCCVenuePayment($oid, $user_id, $token, $_POST['tid']);

}

$orders = $this->Front_model->getDataRow('orders', 'order_id', $oid);

if(empty($orders))

{

$this->failureCCVenuePayment($oid, $user_id, $token, $_POST['tid']);

}

if($_POST['currency']!='INR')

{

$this->failureCCVenuePayment($oid, $user_id, $token, $_POST['tid']);

}

if($orders['order_total']!=$_POST['amount'])

{

$this->failureCCVenuePayment($oid, $user_id, $token, $_POST['tid']);

}

if($token!=$_POST['merchant_param2'])

{

$this->failureCCVenuePayment($oid, $user_id, $token, $_POST['tid']);

}

if($orders['txnid']!=$_POST['tid'])

{

$this->failureCCVenuePayment($oid, $user_id, $token, $_POST['tid']);

}

foreach ($_POST as $key => $value){

$merchant_data.=$key.'='.urlencode($value).'&';

}

$encrypted_data=$this->ccvenuecrypto->encrypt($merchant_data,$working_key);

// Method for encrypting the data.

// https://test.ccavenue.com/transaction/transaction.do?command=initiateTransaction

?>

<form method="post" name="redirect" action="https://secure.ccavenue.com/transaction/transaction.do?command=initiateTransaction">

<?php

echo "<input type=hidden name=encRequest value=$encrypted_data>";

echo "<input type=hidden name=access_code value=$access_code>";

?>

</form>

</center>

<script language='javascript'>document.redirect.submit();</script>

<?php

}

public function ccavResponseHandler()

{

$this->load->library('ccvenuecrypto');

error_reporting(E_ALL);

ini_set('display_errors', 1);

$workingKey='XYZ';//Shared by CCAVENUES

$encResponse=$_POST["encResp"];

//This is the response sent by the CCAvenue Server

$rcvdString=$this->ccvenuecrypto->decrypt($encResponse,$workingKey);

//Crypto Decryption used as per the specified working key.

$order_status="";

$decryptValues=explode('&', $rcvdString);

$dataSize=sizeof($decryptValues);

$user_id=$token=$order_id=$discount_id=$tracking_id=$bank_ref_no=$tracking_id='';

for($i = 0; $i < $dataSize; $i++)

{

$information=explode('=',$decryptValues[$i]);

if($i==0) $order_id=$information[1];

else if($i==1) $tracking_id=$information[1];

else if($i==2) $bank_ref_no=$information[1];

else if($i==3) $order_status=$information[1];

else if($i==26) $user_id=$information[1];

else if($i==27) $token=$information[1];

else if($i==29) $discount_id=$information[1];

}

if($order_status==="Success")

$this->successCCVenuePayment($user_id, $token, $order_id, $discount_id, $tracking_id, $bank_ref_no, $tracking_id );

else if($order_status==="Aborted")

$this->cancelCCVenuePayment($order_id, $user_id, $token, $tracking_id);

else if($order_status==="Failure")

$this->failureCCVenuePayment($order_id, $user_id, $token, $tracking_id);

else

$this->failureCCVenuePayment($order_id, $user_id, $token, $tracking_id);

}

public function ccvenueCancel()

{

$this->load->library('ccvenuecrypto');

error_reporting(E_ALL);

ini_set('display_errors', 1);

$workingKey='XXXXX';//Shared by CCAVENUES

$encResponse=$_POST["encResp"];

//This is the response sent by the CCAvenue Server

$rcvdString=$this->ccvenuecrypto->decrypt($encResponse,$workingKey);

//Crypto Decryption used as per the specified working key.

$order_status="";

$decryptValues=explode('&', $rcvdString);

$dataSize=sizeof($decryptValues);

$user_id=$token=$order_id=$discount_id=$tracking_id=$bank_ref_no=$tracking_id='';

for($i = 0; $i < $dataSize; $i++)

{

$information=explode('=',$decryptValues[$i]);

if($i==0) $order_id=$information[1];

else if($i==1) $tracking_id=$information[1];

else if($i==2) $bank_ref_no=$information[1];

else if($i==3) $order_status=$information[1];

else if($i==26) $user_id=$information[1];

else if($i==27) $token=$information[1];

else if($i==29) $discount_id=$information[1];

}

$this->cancelCCVenuePayment($order_id, $user_id, $token, $tracking_id);

}

}


PayU Payment Gateway Transaction Update in PHP CodeIgniter

public function payuStatusSuccess()

{

$txnid=$orders['txnid'];

$time=3*60; // 3 minute

if(isset($_REQUEST['time']) && $_REQUEST['time']>0)

$time=$_REQUEST['time'];

sleep($time);

$url = "https://www.payumoney.com/payment/op/getPaymentResponse?merchantKey=XYZ&merchantTransactionIds=$txnid";

$curl = curl_init($url);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

curl_setopt($curl, CURLOPT_POST, true);

curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode([]));

curl_setopt($curl, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'authorization: 1dw3esxfSCme5OCb+/fg6nKsI85I4UOj0slne/sUhP8=']);

$response = curl_exec($curl);

curl_close($curl);

$data = json_decode($response);

if($data->status==0){

$mihpayid = $data->result[0]->postBackParam->mihpayid;

$user_id = $data->result[0]->postBackParam->udf1;

$token = $data->result[0]->postBackParam->udf2;

$order_id = $data->result[0]->postBackParam->udf3;

$discount_id = $data->result[0]->postBackParam->udf4;

$payuMoneyId = $data->result[0]->postBackParam->payuMoneyId;

$payu_status=$data->result[0]->postBackParam->status;

$payment_status=2;

if($payu_status=='success' && $order_r_id==$order_id)

{

// Backend Logic for update order

}

}

PayU Payment Gateway integration in PHP CodeIgniter

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

   } 

}

How can create cache in Codeigniter?

public function index(){

 $this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file'));

if($this->cache->apc->is_supported()) echo 'driver is available';

else echo 'driver is not available';

if(!$this->cache->get('homePage'))

{

$myArray = array('one'=>1, 'two'=>2);

$this->cache->save('homePage', $myArray, 300);

echo 'cache not available';

}

$showCache =null;

$showCache = $this->cache->get('homePage');

var_dump($showCache);die();


}

How to upload file on AWS S3 Bucket using Rest API

#Step1: Create Aws3 class which file path application/libraries/Guzzlehttp.php

Source Code:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

include("./vendor/autoload.php");

use GuzzleHttp\Client;

class Guzzlehttp{

     public function __construct(){

          $this->client = new \GuzzleHttp\Client();

     }

    public function sendMultiForm($end_point_url, $multipart){

          return $this->client->request('POST', $end_point_url, [ 'multipart' => $multipart ]);

    }

    public function sendForm($end_point_url, $form_params){

        return $this->client->request('POST', $end_point_url, ['form_params' =>$form_params]);

     }

 }

#Step2: load library in Controller

class Product_Api extends CI_Controller

{

      public function __construct()

     {

         parent::__construct();

        $this->load->library('guzzlehttp');

        date_default_timezone_set('Asia/Kolkata');

     } 

    public function addProductImage()

    {  

      

       $image_abs_path = 'uploads/products/'.$product_id.'/'.$img1_nm;

      $end_point_url="https://www.xyz.com/";

     $multipart=[

            ['name' => 'file_path_name','contents' =>$image_abs_path],

            ['name' => 'image_url', 'contents' => fopen($image_abs_path, 'r')]

       ];

     $response=$this->guzzlehttp->sendMultiForm($end_point_url, $multipart);

    // echo $body = $response->getBody();

    }




First Previous 8 9 10 11 Next Last