Subversion Repositories SmartDukaan

Rev

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

<?php
/**
 * UserUrl Model
 *
 * @property User $User
 */
class PythonApi {
        var $useTable = false;

        public function postCategoryDiscounts($data=null) {
                //Configure::load('live');
                $apihost = Configure::read('pythonapihost');
                $url = $apihost."storeorder";
                if(!empty($data)) {
                        //$params = array('sourceId'=>$order['Order']['store_id'],'orderId'=>$order['Order']['id'],'subTagId'=>$order['Order']['sub_tag'],'userId'=>$order['Order']['user_id'],'rawHtml'=>$order['Order']['rawhtml'],'orderSuccessUrl'=>$order['Order']['order_url']);
                        print_r($data);die;
                        $jsonVar = json_encode($params);
                        return $this->make_request($url,$jsonVar);
                }else{
                        $result = array('success'=>false,'message'=>'Empty order array');
                        return $result;
                }
        }

        public function postOrders($order=null) {
                //Configure::load('live');
                $apihost = Configure::read('pythonapihost');
                $url = $apihost."storeorder";
                if(!empty($order)) {
                        $params = array('sourceId'=>$order['Order']['store_id'],'orderId'=>$order['Order']['id'],'subTagId'=>$order['Order']['sub_tag'],'userId'=>$order['Order']['user_id'],'rawHtml'=>$order['Order']['rawhtml'],'orderSuccessUrl'=>$order['Order']['order_url']);
                        $jsonVar = json_encode($params);
                        return $this->make_request($url,$jsonVar);
                }else{
                        $result = array('success'=>false,'message'=>'Empty order array');
                        return $result;
                }
        }

        public function make_request($url,$fields,$format='json'){
                //$this->log($url,'pythonapi');
                //$this->log($fields,'pythonapi');
                $fields_string = '';
                //open connection
                $ch = curl_init();
                //set the url, number of POST vars, POST data
                curl_setopt($ch,CURLOPT_URL, $url);
                curl_setopt($ch,CURLOPT_RETURNTRANSFER , true);
                if(!empty($fields)) {
                        curl_setopt($ch,CURLOPT_POSTFIELDS, $fields);
                }
                curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
                    'Content-Type: application/json',                                                                                
                    'Content-Length: ' . strlen($fields))                                                                       
                );   
                //execute post
                $result = curl_exec($ch);
                //close connection
                curl_close($ch);
                switch($format){
                        case 'json':
                        $response = json_decode($result,1);
                        break;
                }
                return $response;       
        }
}