Subversion Repositories SmartDukaan

Rev

Rev 20877 | Blame | Compare with Previous | Last modification | View Log | RSS feed

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

class Checkout extends MY_Controller {

public $layoutName ='';
        
        function __construct() {

                // Call the CI_controller constructor
                parent::__construct();
                $admin = $this->session->userdata('admin');
                // if(!isset($admin) || empty($admin)) {
                //      redirect(base_url().'authorize');
                // }
                $this->output->set_header("Expires: Tue, 01 Jan 2000 00:00:00 GMT");
                $this->output->set_header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
                $this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
                $this->output->set_header("Cache-Control: post-check=0, pre-check=0", false);
                $this->output->set_header("Pragma: no-cache");
                $this->layout->setlayout('layout/layout_main');
                $this->load->model('checkout_model');
                $this->load->model('captcha_model');
                $this->layoutName= $this->layout->getLayout();
                $this->layoutName =substr($this->layoutName , 0, strrpos($this->layoutName , "/")).'/';
                //print_r($this->session->userdata);
                

        }
        public function index()
        {
                $authorized = $this->session->userdata('authorized');
                if(isset($authorized) and !empty($authorized['id']))
                {
                        //if user logged-in
                        redirect(base_url().strtolower(__CLASS__).'/shipping');
                }

                //standard array
        }
        public function __paginateList($data=array())
        {
                        //$data['baseSubTotal']=$data['baseSubTotal'];
                        $data['subTotal'] = $data['subTotal'];
                        //$data['shippingCharges'] = $data['shippingCharges'];
                        return $data;   

        }

        public function orderconfirmation()
        {
                $authorized = $this->session->userdata('authorized');
            if(isset($authorized) && !empty($authorized)){
                        $_GET['userId'] = $authorized['Id'];
                        $_GET['Id'] = $authorized['cartId'];
                        if($authorized['isLoggedIn'] == 1){
                                $_GET['isLoggedIn'] = 'true';
                        }
                        elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
                                $_GET['isLoggedIn'] = 'false';
                        }
                        $newValues = $authorized;
                        $newValues['totalItems'] = 0;
                        $this->session->userdata['authorized'] = $newValues;
                }
        //die();
        $this->lessphp->object()->ccompile('assets/css/shipping.less','assets/css/shipping.css');
        $data['stylesheet'] = 'shipping.css';
                $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$this->config->item('orderconfirmation'));
                // $this->session->unset_userdata('shipping');
                // $this->session->unset_userdata('billing');
                // $this->session->unset_userdata('shoppingId');
                $this->session->unset_userdata(array('hotspotId','addressId'));
                $this->layout->view('checkout/checkout_view',$data);
        }
        public function orderconfirmation1()
        {
                $this->layout->setlayout('layout/layout_bigutsav');
                $authorized = $this->session->userdata('authorized');
            if(isset($authorized) && !empty($authorized)){
                        $_GET['userId'] = $authorized['Id'];
                        $_GET['Id'] = $authorized['cartId'];
                        if($authorized['isLoggedIn'] == 1){
                                $_GET['isLoggedIn'] = 'true';
                        }
                        elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
                                $_GET['isLoggedIn'] = 'false';
                        }
                        $newValues = $authorized;
                        $newValues['totalItems'] = 0;
                        $this->session->userdata['authorized'] = $newValues;
                }
        //die();
        $this->lessphp->object()->ccompile('assets/css/shipping.less','assets/css/shipping.css');
        $data['stylesheet'] = 'shipping.css';
                $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$this->config->item('orderconfirmation1'));
                // $this->session->unset_userdata('shipping');
                // $this->session->unset_userdata('billing');
                // $this->session->unset_userdata('shoppingId');
                $this->session->unset_userdata(array('hotspotId','addressId'));
                $this->layout->view('checkout/checkout_view',$data);
        }
        public function payment1()
        {
                $this->layout->setlayout('layout/layout_bigutsav');
                //standard array
                if (!empty($_GET['cq'])) {
                        $this->session->userdata['authorized']['totalItems'] = $_GET['cq'];
                        $this->session->set_userdata('addressId',$_GET['addressid']);
                }
                $authorized = $this->session->userdata('authorized');
                if(!isset($authorized) || empty($authorized)){
                        redirect(base_url()."cart");
                }
                
                $data = array();
                $codCaptcha = $this->session->userdata('cod');
                if(isset($codCaptcha) && $codCaptcha == 1){
                        $data['codCaptcha'] = 1;
                        $this->session->unset_userdata('cod');
                }else{
                        $data['codCaptcha'] = 0;
                }
                $paymentconfig = $this->config->item('payment1');
                if(!isset($_POST['submit'])){
                        $hotspot = $this->session->userdata('hotspotId');
                        if(isset($hotspot) && !empty($hotspot)){
                                $_GET['hotSpotAddressId'] = $hotspot;
                                $_GET['deliveryLocation'] = 'hotSpot';
                        }else{
                                $_GET['deliveryLocation'] = 'myLocation';
                        }
                        unset($paymentconfig['response'][2]);
                        if(isset($authorized) && !empty($authorized)){
                                $_GET['userId'] = $authorized['Id'];
                                $_GET['Id'] = $authorized['cartId'];
                                if($authorized['isLoggedIn'] == 1){
                                        $_GET['isLoggedIn'] = 'true';
                                }
                                elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
                                        $_GET['isLoggedIn'] = 'false';
                                }
                                if(isset($authorized['isPrivateDealUser']) && $authorized['isPrivateDealUser'] == 1){
                                        $this->session->set_userdata('skipcaptcha',1);
                                        $data['skipcaptcha'] = 1;
                                }
                        }
                        $addressId = $this->session->userdata('addressId');
                        $_GET['addressid'] = $addressId;
                        
                        $this->lessphp->object()->ccompile('assets/css/shipping.less','assets/css/shipping.css');
                $data['stylesheet'] = 'shipping.css';
                $data['title'] = 'Saholic';
                        $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),'',$paymentconfig);
                        if(isset($data['response']['response']['payment_process1'])){
                                $result = json_decode($data['response']['response']['payment_process1'][0]);
                                if(isset($_GET['walletUsed'])) {
                                        $walletUsed = (int)($_GET['walletUsed']);
                                }
                                $this->session->set_userdata('walletUsed',$walletUsed);
                                $this->layout->view('checkout/checkout_view',$data);
                        }
                        else{
                                redirect(base_url()."cart");
                        }
                }
                elseif(isset($_POST['submit'])) {
                        if(isset($_POST['captcha_response_field']) && !empty($_POST['captcha_response_field'])){
                                $captcha = $this->session->userdata('captcha');
                                if(strcmp($captcha,$_POST['captcha_response_field']) != 0){
                                        if(isset($_POST['payoption']) && ($_POST['payoption'] == 3000) || $_POST['payoption'] == 3001) {
                                                $this->session->set_userdata('cod',1);
                                        }
                                redirect(base_url().'payment');
                        }
                        }
                        unset($paymentconfig['response'][0]);
                        unset($paymentconfig['response'][1]);
                        if(isset($authorized) && !empty($authorized)){
                                $_POST['userId'] = $authorized['Id'];
                                if($authorized['isLoggedIn'] == 1){
                                        $_POST['isLoggedIn'] = 'true';
                                }
                                elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
                                        $_POST['isLoggedIn'] = 'false';
                                }
                        }
                        $addressId = $this->session->userdata('addressId');
                        $walletUsed = $this->session->userdata('walletUsed');
                        $_POST['addressid'] = $addressId;
                        $_POST['walletUsed'] = $walletUsed;
                        $_POST['payment_option'] = $_POST['payoption'];
                        $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
                        error_log('[USER] ' .print_r($authorized,1),3,'/tmp/payments.log');
                        error_log('[RESPONSE] '. print_r($data['response']['response'],1),3,'/tmp/payments.log');
                        if(isset($data['response']['response']['payment_submit'][0]) && !empty($data['response']['response']['payment_submit'][0])) {
                                $paymentSubmit = $data['response']['response']['payment_submit'][0];
                                if(isset($paymentSubmit->response->isPaymentRedirect) && $paymentSubmit->response->isPaymentRedirect == 1){
                                        $image = '/assets/images/loading.gif';
                                        $location = $paymentSubmit->response->redirectUrl;
                                        echo '<html><head><meta http-equiv="refresh" content="1;url='.$paymentSubmit->response->redirectUrl.'">
                                        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
                                        <title>Saholic Mobile Site: Redirecting to <'.$paymentSubmit->response->gatewayName.'> Payment Gateway</title>
                                        </head>
                                                <body>
                                        <div style="text-align:center; margin-top:200px;">Please wait while we redirect you to the Payment Gateway.</div>
                                        <div align="center" class="img">
                                        <img title="loading" alt="loading" src="'.$image.'">
                                        </div>
                                                </body>
                                                </html>';
                                }elseif(strpos($paymentSubmit->response->redirectUrl, 'ebs-pay') !== false) {
                                        $url = $this->config->item('curl_base_url').$paymentSubmit->response->redirectUrl;
                                        //echo $url;
                                        $authorized = $this->session->userdata('authorized');
                                        if(isset($authorized) && !empty($authorized)){
                                                $params['userId'] = $authorized['Id'];
                                                if($authorized['isLoggedIn'] == 1){
                                                        $params['isLoggedIn'] = 'true';
                                                }
                                                elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
                                                        $params['isLoggedIn'] = 'false';
                                                }
                                        }
                                        $this->mcurl->add_call('ebs','get',$url,$params);
                                $response = $this->mcurl->execute($url);
                                $data['response'] = $response['ebs']['response'];
                                $response = $this->magento_model->payment_submit($data);
                                if(isset($response) && !empty($response)) {
                                        $ebs = $response[0]->response;
                                        $image = './assets/images/loading.gif';
                                        echo '<html>
                                                <head>
                                                 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
                                                 <title>m.saholic.com: Redirecting to EBS Payment Page</title>
                                                </head>
                                                <body>
                                                    <div style="text-align:center; margin-top:200px;">Please wait while we redirect you to the Payment Gateway.</div>
                                                 <div align="center" class="img">
                                                  <img title="loading" alt="loading" src="'.$image.'">
                                                 </div>
                                                 <div style="display:none">
                                                  <form  method="post" action="'.$ebs->postAction.'" name="frmTransaction" id="frmTransaction">  
                                           <!-- Account Id -->
                                           <input name="account_id" type="hidden" value="'.$ebs->account_id.'" />
                                           <!-- Transaction Details -->
                                           <input name="reference_no" type="hidden" value="'.$ebs->reference_no.'" />
                                           <input name="amount" type="hidden" value="'.$ebs->amount.'" />
                                           <input name="description" type="hidden" value="'.$ebs->description.'" />
                                           <input name="payment_option" type="hidden" value="'.$ebs->payment_option.'"/>
                                           <!-- Billing Address -->
                                           <input name="name" type="hidden" value="'.$ebs->name.'" />
                                           <input name="address" type="hidden" value="'.$ebs->address.'" />
                                           <input name="city" type="hidden" value="'.$ebs->city.'" />
                                           <input name="state" type="hidden" value="'.$ebs->state.'" />
                                           <input name="postal_code" type="hidden" value="'.$ebs->postal_code.'" />
                                           <input name="country" type="hidden" value="'.$ebs->country.'"/>
                                           <input name="email" type="hidden" value="'.$ebs->email.'" />
                                           <input name="phone" type="hidden" value="'.$ebs->phone.'" />
                                           <!-- Delivery Address -->
                                           <input name="ship_name" type="hidden" value="'.$ebs->ship_name.'" />
                                           <input name="ship_address" type="hidden" value="'.$ebs->ship_address.'" />
                                           <input name="ship_city" type="hidden" value="'.$ebs->ship_city.'" />
                                           <input name="ship_state" type="hidden" value="'.$ebs->ship_state.'" />
                                           <input name="ship_postal_code" type="hidden" value="'.$ebs->ship_postal_code.'" />
                                           <input name="ship_country" type="hidden" value="'.$ebs->ship_country.'"/> 
                                           <input name="ship_phone" type="hidden" value="'.$ebs->ship_phone.'" />
                                           <input name="return_url" type="hidden" value="'.$ebs->return_url.'" />
                                           <input name="mode" value="'.$ebs->mode.'"/>
                                           <input name="secure_hash" type="hidden" value="'.$ebs->secure_hash.'" />
                                           <input name="channel" type="hidden" value="'.$ebs->channel.'" />
                                           <input name="page_id" type="hidden" value="'.$ebs->page_id.'" />
                                                  </form>
                                                    </div>
                                                    <script type="text/javascript">
                                                     document.getElementById("frmTransaction").submit();
                                                    </script>
                                                  </body>
                                                </html>';
                                }
                                else{
                                        redirect(base_url().'payment');
                                }
                                }
                                elseif(strpos($paymentSubmit->response->redirectUrl, 'payu-pay') !== false) {
                                        $url = $this->config->item('curl_base_url').$paymentSubmit->response->redirectUrl;
                                        //echo $url;
                                        $params = array();
                                        $authorized = $this->session->userdata('authorized');
                                        if(isset($authorized) && !empty($authorized)){
                                                $params['userId'] = $authorized['Id'];
                                                if($authorized['isLoggedIn'] == 1){
                                                        $params['isLoggedIn'] = 'true';
                                                }
                                                elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
                                                        $params['isLoggedIn'] = 'false';
                                                }
                                        }
                                        $this->mcurl->add_call('payu','get',$url,$params);
                                $response = $this->mcurl->execute($url);
                                error_log("payu response".print_r($response,1));
                                $data['response'] = $response['payu']['response'];
                                $response = $this->magento_model->payment_submit($data);
                                if(isset($response) && !empty($response)){
                                        $payu = $response[0]->response;
                                        $image = '/assets/images/loading.gif';
                                        // $return_url = base_url().'ebs-pay-processing/?DR={DR}';
                                        $ci = get_instance();
                                }
                                ?>
                                        <html>
                                                <head>
                                                <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
                                                 <title>m.saholic.com: Redirecting to PayU Payment Gateway</title>
                                                </head>
                                                <body>
                                                    <div style="text-align:center; margin-top:200px;">Please wait while we redirect you to the Payment Gateway.</div>
                                                 <div align="center" class="img">
                                                  <img title="loading" alt="loading" src="<?php echo $image;?>">
                                                 </div>
                                                 <div style="display:none;">
                                                   <form action="<?php echo $payu->postActionUrl; ?>" method="post" id="payuForm">
                                                        <input type="hidden" name="key" value="<?php echo $payu->key; ?>" />
                                                        <input type="hidden" name="hash" value="<?php echo $payu->hash ?>"/>
                                                        <input type="hidden" name="txnid" value="<?php echo $payu->txnid ?>" />
                                                        <input name="amount" value="<?php echo $payu->amount; ?>" />
                                                                <input name="firstname" id="firstname" value="<?php echo $payu->firstname;?>" />
                                                        <input name="email" id="email" value="<?php echo $payu->email; ?>" />
                                                        <input name="phone" value="<?php echo $payu->phone; ?>" />
                                                        <input name="productinfo" value="<?php echo $payu->productinfo; ?>" />
                                                        <input name="surl" value="<?php echo rtrim(base_url(), "/").$payu->surl; ?>"  />
                                                        <input name="furl" value="<?php echo rtrim(base_url(), "/").$payu->furl; ?>" />
                                                        <input name="bankcode" value="<?php echo $payu->bankcode; ?>" />
                                                        <input name="pg" value="<?php echo $payu->pg; ?>" />
                                                        <input name="curl" value="<?php echo rtrim(base_url(), "/").$payu->curl; ?>" />
                                                        <input type="hidden" name="service_provider" value="payu_paisa" />
                                                        <input type="submit" value="Submit" />                                                    
                                                    </form>
                                            </div>
                                            <script type="text/javascript">
                                                    document.getElementById("payuForm").submit();
                                            </script>
                                          </body>
                                        </html>
                                        <?php
                                }  
                                else{
                                        redirect(base_url().$paymentSubmit->response->redirectUrl);
                                }
                        } else {
                                redirect(base_url()."payment"); 
                        }
                }               
        }
        public function payment()
        {
                //standard array
                if (!empty($_GET['cq'])) {
                        $this->session->userdata['authorized']['totalItems'] = $_GET['cq'];
                        $this->session->set_userdata('addressId',$_GET['addressid']);
                }
                $authorized = $this->session->userdata('authorized');
                if(!isset($authorized) || empty($authorized)){
                        redirect(base_url()."cart");
                }
                
                $data = array();
                $codCaptcha = $this->session->userdata('cod');
                if(isset($codCaptcha) && $codCaptcha == 1){
                        $data['codCaptcha'] = 1;
                        $this->session->unset_userdata('cod');
                }else{
                        $data['codCaptcha'] = 0;
                }
                $paymentconfig = $this->config->item('payment');
                if(!isset($_POST['submit'])){
                        $hotspot = $this->session->userdata('hotspotId');
                        if(isset($hotspot) && !empty($hotspot)){
                                $_GET['hotSpotAddressId'] = $hotspot;
                                $_GET['deliveryLocation'] = 'hotSpot';
                        }else{
                                $_GET['deliveryLocation'] = 'myLocation';
                        }
                        unset($paymentconfig['response'][2]);
                        if(isset($authorized) && !empty($authorized)){
                                $_GET['userId'] = $authorized['Id'];
                                $_GET['Id'] = $authorized['cartId'];
                                if($authorized['isLoggedIn'] == 1){
                                        $_GET['isLoggedIn'] = 'true';
                                }
                                elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
                                        $_GET['isLoggedIn'] = 'false';
                                }
                                if(isset($authorized['isPrivateDealUser']) && $authorized['isPrivateDealUser'] == 1){
                                        $this->session->set_userdata('skipcaptcha',1);
                                        $data['skipcaptcha'] = 1;
                                }
                        }
                        $addressId = $this->session->userdata('addressId');
                        $_GET['addressid'] = $addressId;
                        $this->lessphp->object()->ccompile('assets/css/shipping.less','assets/css/shipping.css');
                $data['stylesheet'] = 'shipping.css';
                $data['title'] = 'Saholic';
                        $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),'',$paymentconfig);
                        if(isset($data['response']['response']['payment_process'])){
                                $result = json_decode($data['response']['response']['payment_process'][0]);
                                $totalAmount = $result->results->totalAmount;
                                if(isset($result->results->isTotalAmountZero)){
                                        $isTotalAmountZero = $result->results->isTotalAmountZero;
                                }
                                $totalAmount = number_format((float)$totalAmount,0,'.','');
                                $captcha = $this->captcha_model->generateCaptcha();
                                $this->session->set_userdata('captcha',$captcha['word']);
                                $data['captcha'] = $captcha;
                                // if($totalAmount == 0 && isset($isTotalAmountZero) && $isTotalAmountZero == 1){
                                //      $captcha = $this->captcha_model->generateCaptcha();
                                //      $this->session->set_userdata('captcha',$captcha['word']);
                                //      $this->session->set_userdata('captchaDisplay',$isTotalAmountZero);
                                //      $data['captcha'] = $captcha;
                                // }
                                $this->layout->view('checkout/checkout_view',$data);
                        }
                        else{
                                redirect(base_url()."cart");
                        }
                }
                elseif(isset($_POST['submit'])) {
                        if(isset($_POST['captcha_response_field']) && !empty($_POST['captcha_response_field'])){
                                $captcha = $this->session->userdata('captcha');
                                if(strcmp($captcha,$_POST['captcha_response_field']) != 0){
                                        if(isset($_POST['payoption']) && ($_POST['payoption'] == 3000) || $_POST['payoption'] == 3001) {
                                                $this->session->set_userdata('cod',1);
                                        }
                                redirect(base_url().'payment');
                        }
                        }
                        unset($paymentconfig['response'][0]);
                        unset($paymentconfig['response'][1]);
                        if(isset($authorized) && !empty($authorized)){
                                $_POST['userId'] = $authorized['Id'];
                                if($authorized['isLoggedIn'] == 1){
                                        $_POST['isLoggedIn'] = 'true';
                                }
                                elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
                                        $_POST['isLoggedIn'] = 'false';
                                }
                        }
                        $addressId = $this->session->userdata('addressId');
                        $_POST['addressid'] = $addressId;
                        $walletUsed = $this->session->userdata('walletUsed');
                        $_POST['walletUsed'] = $walletUsed;
                        $_POST['payment_option'] = $_POST['payoption'];
                        $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
                        error_log('[USER] ' .print_r($authorized,1),3,'/tmp/payments.log');
                        error_log('[RESPONSE] '. print_r($data['response']['response'],1),3,'/tmp/payments.log');
                        if(isset($data['response']['response']['payment_submit'][0]) && !empty($data['response']['response']['payment_submit'][0])) {
                                $paymentSubmit = $data['response']['response']['payment_submit'][0];
                                if(isset($paymentSubmit->response->isPaymentRedirect) && $paymentSubmit->response->isPaymentRedirect == 1){
                                        $image = '/assets/images/loading.gif';
                                        $location = $paymentSubmit->response->redirectUrl;
                                        echo '<html><head><meta http-equiv="refresh" content="1;url='.$paymentSubmit->response->redirectUrl.'">
                                        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
                                        <title>Saholic Mobile Site: Redirecting to <'.$paymentSubmit->response->gatewayName.'> Payment Gateway</title>
                                        </head>
                                                <body>
                                        <div style="text-align:center; margin-top:200px;">Please wait while we redirect you to the Payment Gateway.</div>
                                        <div align="center" class="img">
                                        <img title="loading" alt="loading" src="'.$image.'">
                                        </div>
                                                </body>
                                                </html>';
                                }elseif(strpos($paymentSubmit->response->redirectUrl, 'ebs-pay') !== false) {
                                        $url = $this->config->item('curl_base_url').$paymentSubmit->response->redirectUrl;
                                        //echo $url;
                                        $authorized = $this->session->userdata('authorized');
                                        if(isset($authorized) && !empty($authorized)){
                                                $params['userId'] = $authorized['Id'];
                                                if($authorized['isLoggedIn'] == 1){
                                                        $params['isLoggedIn'] = 'true';
                                                }
                                                elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
                                                        $params['isLoggedIn'] = 'false';
                                                }
                                        }
                                        $this->mcurl->add_call('ebs','get',$url,$params);
                                $response = $this->mcurl->execute($url);
                                $data['response'] = $response['ebs']['response'];
                                $response = $this->magento_model->payment_submit($data);
                                if(isset($response) && !empty($response)) {
                                        $ebs = $response[0]->response;
                                        $image = './assets/images/loading.gif';
                                        echo '<html>
                                                <head>
                                                 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
                                                 <title>m.saholic.com: Redirecting to EBS Payment Page</title>
                                                </head>
                                                <body>
                                                    <div style="text-align:center; margin-top:200px;">Please wait while we redirect you to the Payment Gateway.</div>
                                                 <div align="center" class="img">
                                                  <img title="loading" alt="loading" src="'.$image.'">
                                                 </div>
                                                 <div style="display:none">
                                                  <form  method="post" action="'.$ebs->postAction.'" name="frmTransaction" id="frmTransaction">  
                                           <!-- Account Id -->
                                           <input name="account_id" type="hidden" value="'.$ebs->account_id.'" />
                                           <!-- Transaction Details -->
                                           <input name="reference_no" type="hidden" value="'.$ebs->reference_no.'" />
                                           <input name="amount" type="hidden" value="'.$ebs->amount.'" />
                                           <input name="description" type="hidden" value="'.$ebs->description.'" />
                                           <input name="payment_option" type="hidden" value="'.$ebs->payment_option.'"/>
                                           <!-- Billing Address -->
                                           <input name="name" type="hidden" value="'.$ebs->name.'" />
                                           <input name="address" type="hidden" value="'.$ebs->address.'" />
                                           <input name="city" type="hidden" value="'.$ebs->city.'" />
                                           <input name="state" type="hidden" value="'.$ebs->state.'" />
                                           <input name="postal_code" type="hidden" value="'.$ebs->postal_code.'" />
                                           <input name="country" type="hidden" value="'.$ebs->country.'"/>
                                           <input name="email" type="hidden" value="'.$ebs->email.'" />
                                           <input name="phone" type="hidden" value="'.$ebs->phone.'" />
                                           <!-- Delivery Address -->
                                           <input name="ship_name" type="hidden" value="'.$ebs->ship_name.'" />
                                           <input name="ship_address" type="hidden" value="'.$ebs->ship_address.'" />
                                           <input name="ship_city" type="hidden" value="'.$ebs->ship_city.'" />
                                           <input name="ship_state" type="hidden" value="'.$ebs->ship_state.'" />
                                           <input name="ship_postal_code" type="hidden" value="'.$ebs->ship_postal_code.'" />
                                           <input name="ship_country" type="hidden" value="'.$ebs->ship_country.'"/> 
                                           <input name="ship_phone" type="hidden" value="'.$ebs->ship_phone.'" />
                                           <input name="return_url" type="hidden" value="'.$ebs->return_url.'" />
                                           <input name="mode" value="'.$ebs->mode.'"/>
                                           <input name="secure_hash" type="hidden" value="'.$ebs->secure_hash.'" />
                                           <input name="channel" type="hidden" value="'.$ebs->channel.'" />
                                           <input name="page_id" type="hidden" value="'.$ebs->page_id.'" />
                                                  </form>
                                                    </div>
                                                    <script type="text/javascript">
                                                     document.getElementById("frmTransaction").submit();
                                                    </script>
                                                  </body>
                                                </html>';
                                }
                                else{
                                        redirect(base_url().'payment');
                                }
                                }
                                elseif(strpos($paymentSubmit->response->redirectUrl, 'payu-pay') !== false) {
                                        $url = $this->config->item('curl_base_url').$paymentSubmit->response->redirectUrl;
                                        //echo $url;
                                        $params = array();
                                        $authorized = $this->session->userdata('authorized');
                                        if(isset($authorized) && !empty($authorized)){
                                                $params['userId'] = $authorized['Id'];
                                                if($authorized['isLoggedIn'] == 1){
                                                        $params['isLoggedIn'] = 'true';
                                                }
                                                elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
                                                        $params['isLoggedIn'] = 'false';
                                                }
                                        }
                                        $this->mcurl->add_call('payu','get',$url,$params);
                                $response = $this->mcurl->execute($url);
                                error_log("payu response".print_r($response,1));
                                $data['response'] = $response['payu']['response'];
                                $response = $this->magento_model->payment_submit($data);
                                if(isset($response) && !empty($response)){
                                        $payu = $response[0]->response;
                                        $image = '/assets/images/loading.gif';
                                        // $return_url = base_url().'ebs-pay-processing/?DR={DR}';
                                        $ci = get_instance();
                                }
                                ?>
                                        <html>
                                                <head>
                                                <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
                                                 <title>m.saholic.com: Redirecting to PayU Payment Gateway</title>
                                                </head>
                                                <body>
                                                    <div style="text-align:center; margin-top:200px;">Please wait while we redirect you to the Payment Gateway.</div>
                                                 <div align="center" class="img">
                                                  <img title="loading" alt="loading" src="<?php echo $image;?>">
                                                 </div>
                                                 <div style="display:none;">
                                                   <form action="<?php echo $payu->postActionUrl; ?>" method="post" id="payuForm">
                                                        <input type="hidden" name="key" value="<?php echo $payu->key; ?>" />
                                                        <input type="hidden" name="hash" value="<?php echo $payu->hash ?>"/>
                                                        <input type="hidden" name="txnid" value="<?php echo $payu->txnid ?>" />
                                                        <input name="amount" value="<?php echo $payu->amount; ?>" />
                                                                <input name="firstname" id="firstname" value="<?php echo $payu->firstname;?>" />
                                                        <input name="email" id="email" value="<?php echo $payu->email; ?>" />
                                                        <input name="phone" value="<?php echo $payu->phone; ?>" />
                                                        <input name="productinfo" value="<?php echo $payu->productinfo; ?>" />
                                                        <input name="surl" value="<?php echo rtrim(base_url(), "/").$payu->surl; ?>"  />
                                                        <input name="furl" value="<?php echo rtrim(base_url(), "/").$payu->furl; ?>" />
                                                        <input name="bankcode" value="<?php echo $payu->bankcode; ?>" />
                                                        <input name="pg" value="<?php echo $payu->pg; ?>" />
                                                        <input type="hidden" name="service_provider" value="payu_paisa" />
                                                        <input name="curl" value="<?php echo rtrim(base_url(), "/").$payu->curl; ?>" />
                                                        <input type="submit" value="Submit" />                                                    
                                                    </form>
                                            </div>
                                            <script type="text/javascript">
                                                    document.getElementById("payuForm").submit();
                                            </script>
                                          </body>
                                        </html>
                                        <?php
                                }  
                                else{
                                        redirect(base_url().$paymentSubmit->response->redirectUrl);
                                }
                        } else {
                                redirect(base_url()."payment"); 
                        }
                }               
        }
        
        public function ebsprocessing(){
                if(isset($_GET['DR']) && !empty($_GET['DR'])){
                        $paymentconfig = $this->config->item('ebsProcessing');
                        $authorized = $this->session->userdata('authorized');
                        if(isset($authorized) && !empty($authorized)){
                                $_GET['userId'] = $authorized['Id'];
                                if($authorized['isLoggedIn'] == 1){
                                        $_GET['isLoggedIn'] = 'true';
                                }
                                elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
                                        $_GET['isLoggedIn'] = 'false';
                                }
                        }
                        $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
                        if(isset($data['response']['response']['ebs_processing'][0]->response)){
                                $redirectUrl = $data['response']['response']['ebs_processing'][0]->response->redirectUrl;
                                $redirectUrl = explode('?', $redirectUrl);
                                $redirectUrl = base_url().'ebs-pay-response/?'.$redirectUrl[1];
                                $image = '/assets/images/loading.gif';
                                echo '<html><head><meta http-equiv="refresh" content="2;url='.$redirectUrl.'">
                                        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
                                        <title>Saholic Mobile Site:</title>
                                        </head>
                                                <body>
                                        <div style="text-align:center; margin-top:200px;">'.$data['response']['response']['ebs_processing'][0]->response->redirectMessage.'</div>
                                        <div align="center" class="img">
                                        <img title="loading" alt="loading" src="'.$image.'">
                                        </div>
                                                </body>
                                                </html>';
                        }
                }
        }
        public function ebsresponse(){
                if(isset($_GET['DR']) && !empty($_GET['DR'])){
                        $paymentconfig = $this->config->item('ebsResponse');
                        $authorized = $this->session->userdata('authorized');
                        if(isset($authorized) && !empty($authorized)){
                                $_GET['userId'] = $authorized['Id'];
                                if($authorized['isLoggedIn'] == 1){
                                        $_GET['isLoggedIn'] = 'true';
                                }
                                elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
                                        $_GET['isLoggedIn'] = 'false';
                                }
                        }
                        $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
                        if(isset($data['response']['response']['ebs_response'][0]->response) && !empty($data['response']['response']['ebs_response'][0]->response)){
                                $redirectUrl = $data['response']['response']['ebs_response'][0]->response->redirectUrl;
                                redirect($redirectUrl);
                        }
                        else{
                                redirect(base_url().'payment');
                        }
                }
        }

        public function payuresponse(){
                error_log("payu response ".print_r($_REQUEST,1));
                $paymentconfig = $this->config->item('payuResponse');
                $authorized = $this->session->userdata('authorized');
                if(isset($authorized) && !empty($authorized)){
                        $_GET['userId'] = $authorized['Id'];
                        if($authorized['isLoggedIn'] == 1){
                                $_GET['isLoggedIn'] = 'true';
                        }
                        elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
                                $_GET['isLoggedIn'] = 'false';
                        }
                }
                $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
                error_log("payu response ".print_r($data['response'],1));
                if(isset($data['response']['response']['payu_response'][0]->response) && !empty($data['response']['response']['payu_response'][0]->response)){
                        $redirectUrl = $data['response']['response']['payu_response'][0]->response->redirectUrl;
                        redirect(rtrim(base_url(), "/").$redirectUrl);
                }
                else{
                        redirect(rtrim(base_url(), "/").'payment');
                }
        }

        public function hdfcPayResponse(){
                if(isset($_POST)){
                        $paymentconfig = $this->config->item('hdfcResponse');
                        $authorized = $this->session->userdata('authorized');
                        if(isset($authorized) && !empty($authorized)){
                                $_POST['userId'] = $authorized['Id'];
                                if($authorized['isLoggedIn'] == 1){
                                        $_POST['isLoggedIn'] = 'true';
                                }
                                elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
                                        $_POST['isLoggedIn'] = 'false';
                                }
                        }
                        $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
                        if(isset($data['response']['response']['hdfc_response'][0]->response) && !empty($data['response']['response']['hdfc_response'][0]->response)){
                                $redirectUrl = $data['response']['response']['hdfc_response'][0]->response->redirectUrl;
                                redirect($redirectUrl);
                        }
                        else{
                                redirect(base_url());
                        }       
                }else{
                        redirect(base_url());
                }
        }
        public function hdfcEmiResponse(){
                if(isset($_POST)){
                        $paymentconfig = $this->config->item('hdfcEmiResponse');
                        $authorized = $this->session->userdata('authorized');
                        if(isset($authorized) && !empty($authorized)){
                                $_POST['userId'] = $authorized['Id'];
                                if($authorized['isLoggedIn'] == 1){
                                        $_POST['isLoggedIn'] = 'true';
                                }
                                elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
                                        $_POST['isLoggedIn'] = 'false';
                                }
                        }
                        $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
                        if(isset($data['response']['response']['hdfc_emi_response'][0]->response) && !empty($data['response']['response']['hdfc_emi_response'][0]->response)){
                                $redirectUrl = $data['response']['response']['hdfc_emi_response'][0]->response->redirectUrl;
                                redirect($redirectUrl);
                        }
                        else{
                                redirect(base_url());
                        }       
                }else{
                        redirect(base_url());
                }
        }
        public function innovitiPayment(){
                $last = $this->uri->total_segments();
                $itemcode = $this->uri->segment($last);
                if(isset($itemcode) && !empty($itemcode)){
                        $url = $this->config->item('curl_base_url').'innoviti-pay/'.$itemcode;
                        $params = array();
                        $authorized = $this->session->userdata('authorized');
                        if(isset($authorized) && !empty($authorized)){
                                $params['userId'] = $authorized['Id'];
                                if($authorized['isLoggedIn'] == 1){
                                        $params['isLoggedIn'] = 'true';
                                }
                                elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
                                        $params['isLoggedIn'] = 'false';
                                }
                        $this->mcurl->add_call('innoviti','get',$url,$params);
                        $response = $this->mcurl->execute($url);
                        $data['response'] = $response['innoviti']['response'];
                $response = $this->magento_model->payment_submit($data);
                if(isset($response) && !empty($response)){
                        $innoviti = $response[0]->response;
                        $image = './assets/images/loading.gif';
                        echo '<html>
                                                <head>
                                                 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
                                                 <title>m.saholic.com: Redirecting to Innoviti Payment Page</title>
                                                </head>
                                                <body>
                                                    <div style="text-align:center; margin-top:200px;">Please wait while we redirect you to the Payment Gateway.</div>
                                                 <div align="center" class="img">
                                                  <img title="loading" alt="loading" src="'.$image.'">
                                                 </div>
                                                 <div style="display:none">
                                                  <form  method="post" action="'.$innoviti->action.'" name="frmTransaction" id="frmTransaction">  
                                                                <input name="merchantId" type="hidden" value="'.$innoviti->merchantId.'" />
                                                                <input name="subMerchantId" type="hidden" value="'.$innoviti->subMerchantId.'" />
                                                                                <!-- Transaction Details -->
                                                                <input name="orderId" type="hidden" value="'.$innoviti->orderId.'" />
                                                                <input name="amt" type="hidden" value="'.$innoviti->amt.'" />   
                                                                <input name="cur" type="hidden" value="INR" />
                                                                <input name="processingCode" type="hidden" value="'.$innoviti->processingCode.'" />
                                                                <input name="proSku" type="hidden" value="'.$innoviti->proSku.'" />
                                                                <input name="Cname" type="hidden" value="'.$innoviti->Cname.'" /></td>
                                                                <input name="mobile" type="hidden" value="'.$innoviti->mobile.'" />
                                                                <input name="emailId" type="hidden" value="'.$innoviti->emailId.'" />     
                                                                <input name="redirUrl" type="hidden" value="'.$innoviti->redirUrl.'" />
                                                                <input name="chksum" type="hidden" value="'.$innoviti->chksum.'" />
                                                                <input name="isCtx" type="hidden" value="NO" />
                                                        <input name="submitted" value="Submit" type="submit" />&nbsp; 
                                                          </form>
                                                    </div><script type="text/javascript">
                                                    document.getElementById("frmTransaction").submit();
                                                </script></body></html>';
                }
                        }else{
                                redirect(base_url());
                        }
                        
                }else{
                        redirect(base_url());
                }
        }
        public function innovitiResponse(){
                if(isset($_POST)){
                        $paymentconfig = $this->config->item('innovitiResponse');
                        $authorized = $this->session->userdata('authorized');
                        if(isset($authorized) && !empty($authorized)){
                                $_POST['userId'] = $authorized['Id'];
                                if($authorized['isLoggedIn'] == 1){
                                        $_POST['isLoggedIn'] = 'true';
                                }
                                elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
                                        $_POST['isLoggedIn'] = 'false';
                                }
                        }
                        $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
                        if(isset($data['response']['response']['innoviti_response'][0]->response) && !empty($data['response']['response']['innoviti_response'][0]->response)){
                                $redirectUrl = $data['response']['response']['innoviti_response'][0]->response->redirectUrl;
                                redirect($redirectUrl);
                        }
                        else{
                                redirect(base_url());
                        }       
                }else{
                        redirect(base_url());
                }
        }
        public function paymenterror(){
                        $authorized = $this->session->userdata('authorized');
                        if(isset($authorized) && !empty($authorized)){
                                $data = array();
                                $paymentconfig = $this->config->item('paymenterror');
                                $this->lessphp->object()->ccompile('assets/css/shipping.less','assets/css/shipping.css');
                                $data['stylesheet'] = 'shipping.css';
                                $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
                                $this->layout->view('checkout/checkout_view',$data);
                        }else{
                                redirect(base_url());
                        }
        }
        public function shipping()
        {

                $data = array();
                $authorized = $this->session->userdata('authorized');
                if($authorized['isLoggedIn'] != 1){
                        $this->session->set_userdata('location','shipping');
                        redirect(base_url()."login");
                }
                $shippingconfig = $this->config->item('shipping');
                if(!isset($_POST['submit']))
                {
                        $authorized = $this->session->userdata('authorized');
                                if(isset($authorized) && !empty($authorized)){
                                        $_GET['userId'] = $authorized['Id'];
                                        $_GET['Id'] = $authorized['cartId'];
                                        if($authorized['isLoggedIn'] == 1){
                                                $_GET['isLoggedIn'] = 'true';
                                        }
                                        elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
                                                $_GET['isLoggedIn'] = 'false';
                                        }
                                }
                        $this->lessphp->object()->ccompile('assets/css/shipping.less','assets/css/shipping.css');
                        $data['stylesheet'] = 'shipping.css';
                        $data['title'] = 'Saholic';
                        $cache = getFileCache('pickup');
                        if(isset($cache) && !empty($cache)){
                                unset($shippingconfig['response'][1]);
                                $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$shippingconfig);
                                $data['response']['response']['pickup'] = $cache;
                        }else{
                                $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$shippingconfig);
                        if(isset($data['response']['response']['pickup']) && !empty($data['response']['response']['pickup']))
                        setFileCache($data['response']['response']['pickup'], 'pickup',900);
                        }
                        $carts = $data['response']['response']['carts'][0];
                        $shipping = $data['response']['response']['shipping_process'][0]; 
                        if((isset($carts) && !empty($carts)) && (isset($shipping) && !empty($shipping))){
                                $this->layout->view('checkout/checkout_view',$data);
                        }else{
                                redirect(base_url()."cart");
                        }
                }
                if(isset($_POST['submit']))
                {
                        unset($shippingconfig['response'][1]);  
                        $data = $this->get_shipping_billing($_POST);
                        $this->session->set_userdata($data);
                        $authorized = $this->session->userdata('authorized');
                        if(isset($authorized) && !empty($authorized)){
                                $_POST['userId'] = $authorized['Id'];
                                $_POST['Id'] = $authorized['cartId'];
                                        if($authorized['isLoggedIn'] == 1){
                                                $_POST['isLoggedIn'] = 'true';
                                        }
                                        elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
                                                $_POST['isLoggedIn'] = 'false';
                                        }
                                }
                        //$data['stylesheet'] = 'shipping.less';
                        $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$shippingconfig);
                        //$this->layout->view('checkout/checkout_view',$data);
                        redirect(base_url()."shipping");
                        
                }
                
        }

        public function get_shipping_billing($data=array()){
                $billing =array();
                $shipping =array();
                if (isset($data) && !empty($data)) {
                        $shipping=array('name'  => $data['name'],'line1' => $data['line1'],'line2' => $data['line2'], 'city' => $data['city'], 'pin' => $data['pin'], 'phonenumber' => $data['phone']);
                        return array('shipping'=>$shipping,'billing'=>$billing);
                }
        }

        public function delete($addressId){
                $shippingconfig = $this->config->item('shipping_delete');
                $_GET['addressId'] = $addressId;
                $authorized = $this->session->userdata('authorized');
                if(isset($authorized) && !empty($authorized)){
                        $_GET['userId'] = $authorized['Id'];
                        $_GET['Id'] = $authorized['cartId'];
                        if($authorized['isLoggedIn'] == 1){
                                $_GET['isLoggedIn'] = 'true';
                        }
                        elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
                                $_GET['isLoggedIn'] = 'false';
                                }
                        }
                        $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$shippingconfig);
                        print_r($data['response']);
                }

        public function changeAddress($addressId,$type){
                if(isset($addressId) && isset($type)){
                $shippingconfig = $this->config->item('shipping_change');
                $_GET['addressId'] = $addressId;
                $_GET['addressType'] = $type;
                $authorized = $this->session->userdata('authorized');
                if(isset($authorized) && !empty($authorized)){
                        $_GET['userId'] = $authorized['Id'];
                        $_GET['Id'] = $authorized['cartId'];
                        if($authorized['isLoggedIn'] == 1){
                                $_GET['isLoggedIn'] = 'true';
                        }
                        elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
                                $_GET['isLoggedIn'] = 'false';
                                }
                        }
                        $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$shippingconfig);
                        $this->session->set_userdata('addressId',$addressId);
                        echo json_encode($data['response']['response']['changeAddress'][0]);
                }
        }
        public function changeCaptcha(){
                $captchaDisplay = $this->session->userdata('captchaDisplay');
                //if(isset($captchaDisplay) && $captchaDisplay == 1){
                        $captcha = $this->captcha_model->generateCaptcha();
                        $this->session->set_userdata('captcha',$captcha['word']);
                        unset($captcha['word']);
                        unset($captcha['time']);
                        unset($captcha['name']);
                        echo json_encode($captcha);
                //}
        }
        public function insuranceInfo($bday,$gname,$addressId){
        if((isset($bday) && !empty($bday)) && (isset($gname) && !empty($gname)) && (isset($addressId) && !empty($addressId))){
                if(isset($gname) && !empty($gname)){
                        $gname = str_replace('-',' ',$gname);
                        $gname = ltrim($gname);
                        $gname = rtrim($gname);
                        $_GET['guardianName'] = $gname;
                }
                if(isset($bday) && !empty($bday)){
                        $dob = explode('-',$bday);
                        //$dob = array_reverse($dob);
                        $temp1 = $dob[1];
                        $temp2 = $dob[0];
                        $dob[0] = $temp1;
                        $dob[1] = $temp2;

                        $dob = implode('/', $dob);
                        $_GET['dob'] = $dob; 
                } 
                $insuranceconfig = $this->config->item('insurance_info');
                $_GET['addressId'] = $addressId;
                $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$insuranceconfig);
                if(isset($data['response']['response']['insuranceInfo'][0]->response) && (!empty($data['response']['response']['insuranceInfo'][0]->response))) {
                        echo json_encode($data['response']['response']['insuranceInfo'][0]);
                }
        }
  }
  public function pickupSpot($id){
        if(isset($id) && !empty($id) && is_numeric($id)){
                $this->session->set_userdata('hotspotId',$id);
                $response['msg'] = 'sucess';
                echo json_encode($response);
        }
  }

}


/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */