Subversion Repositories SmartDukaan

Rev

Rev 10603 | Rev 10606 | Go to most recent revision | 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->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
                $data = array();
                $checkoutconfig = $this->config->item('checkout');
                if(!isset($_POST['submit'])){
                unset($checkoutconfig['response'][1]);  
                $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$checkoutconfig);
                $this->layout->view('checkout/checkout_view',$data);
                }
                if(isset($_POST['submit'])){
                        $type = $this->input->post('type');
                        if($type == "member"){
                        unset($checkoutconfig['response'][0]);  
                        $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$checkoutconfig);
                        if(isset($data['response']['response']['login_submit']['authorized'])){
                        $this->session->set_userdata('authorized',$data['response']['response']['login_submit']['authorized']);
                        $this->session->set_flashdata(array('msg'=>$data['response']['response']['login_submit']['msg']));
                        redirect(base_url().$data['response']['response']['login_submit']['redirect']);
                        }
                        else
                        {
                                $this->layout->view(strtolower(__CLASS__).'/checkout_view',$data);
                        }
                        }
                        if($type == 'guest'){
                                redirect(base_url().strtolower(__CLASS__).'/shipping'); 
                        }
                        if($type == 'register'){
                                redirect(base_url().'auth/signup');     
                        }
                }
        }
        // public function billing()
        // {
        //      //standard array
        //      $data = array();
                
        //      $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$this->config->item('billing'));
        //      $this->layout->view('checkout/checkout_view',$data);

        // }
        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';
                        }
                }
        //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('hotspotId');
                $this->session->unset_userdata('addressId');
                $this->layout->view('checkout/checkout_view',$data);
        }
        public function payment()
        {
                //standard array
                //print_r($this->session->all_userdata())
                $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';
                                }
                        }
                        $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['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();
                                echo 'captcha is'.'<br/>';
                                print_r($captcha);
                                $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){
                                                $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;
                        $_POST['payment_option'] = $_POST['payoption'];
                        $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$paymentconfig);
                        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 = base_url().'/images/loading.gif';
                                        $location = $paymentSubmit->response->redirectUrl;
                                        echo '<html><head><meta http-equiv="refresh" content="2;url='.$paymentSubmit->response->redirectUrl.'">
                                        <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;
                                        echo '<html>
                                                <head>
                                                 <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="'.base_url().'assets/images/loading.gif">
                                                 </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="IND"/>
                                           <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="IND"/> 
                                           <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.'" />
                                           <input name="submitted" value="Submit" type="submit" /> 
                                           <input value="Reset" type="reset" />
                                                  </form>
                                                    </div>
                                                    <script type="text/javascript">
                                                     document.getElementById("frmTransaction").submit();
                                                    </script>
                                                  </body>
                                                </html>';
                                }else{
                                        redirect(base_url().'payment');
                                }
                                }
                                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];
                                echo '<html><head><meta http-equiv="refresh" content="2;url='.$redirectUrl.'">
                                        <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="">
                                        </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 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 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;
                        echo '
                                <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="../assets/images/loading.gif">
                                                 </div>
                                <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" />
                                        <script type="text/javascript">
                                                    document.getElementById("frmTransaction").submit();
                                                </script>
                                  </form>';
                }
                        }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');
                                $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';
                        $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);
                        }
                        $this->layout->view('checkout/checkout_view',$data);
                }
                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 shippingmode()
        {
                $data = array();
                $shippingconfig = $this->config->item('shippingmethod');
                if(!isset($_POST['submit']))
                {
                        unset($shippingconfig['response'][1]);
                        $data['response']['address']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$shippingconfig);
                        $this->layout->view('checkout/checkout_view',$data);
                }
                if(isset($_POST['submit']))
                {
                        unset($shippingconfig['response'][0]);
                        $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$shippingconfig);
                        if($data['response']['response']['shippingmethod_submit'][0] == 1){
                        redirect(base_url().strtolower(__CLASS__)."/payment");
                        }
                        else{
                        redirect(base_url().strtolower(__CLASS__)."/shippingmode");     
                        }
                        
                }
        }
        public function review()
        {
                //standard array
                $authorized = $this->session->userdata('authorized');
                if(isset($authorized) and !empty($authorized['id']))
                {
                        //if user logged-in
                        $_GET['customerId'] = $authorized['id'];
                }
                $data = array();
                $data['response']=$this->checkout_model->getCheckoutDetails($this->input->get(),$this->input->post(),$this->config->item('review'));
                if(isset($data['response']['response']['review_process']) && !empty($data['response']['response']['review_process'])){
                $this->layout->view('checkout/checkout_view',$data);
                }
                else{
                        redirect(base_url().strtolower(__CLASS__)."/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);
                        print_r($data['response']['response']['changeAddress'][0]->message);
                }
        }
        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 */