| 13633 |
anikendra |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* UserUrl Model
|
|
|
4 |
*
|
|
|
5 |
* @property User $User
|
|
|
6 |
*/
|
|
|
7 |
class PythonApi {
|
|
|
8 |
var $useTable = false;
|
|
|
9 |
|
|
|
10 |
public function postCategoryDiscounts($data=null) {
|
| 13946 |
anikendra |
11 |
//Configure::load('live');
|
| 13633 |
anikendra |
12 |
$apihost = Configure::read('pythonapihost');
|
|
|
13 |
$url = $apihost."storeorder";
|
|
|
14 |
if(!empty($data)) {
|
|
|
15 |
//$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']);
|
|
|
16 |
print_r($data);die;
|
|
|
17 |
$jsonVar = json_encode($params);
|
|
|
18 |
return $this->make_request($url,$jsonVar);
|
|
|
19 |
}else{
|
|
|
20 |
$result = array('success'=>false,'message'=>'Empty order array');
|
|
|
21 |
return $result;
|
|
|
22 |
}
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
public function postOrders($order=null) {
|
| 13946 |
anikendra |
26 |
//Configure::load('live');
|
| 13633 |
anikendra |
27 |
$apihost = Configure::read('pythonapihost');
|
|
|
28 |
$url = $apihost."storeorder";
|
|
|
29 |
if(!empty($order)) {
|
|
|
30 |
$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']);
|
|
|
31 |
$jsonVar = json_encode($params);
|
|
|
32 |
return $this->make_request($url,$jsonVar);
|
|
|
33 |
}else{
|
|
|
34 |
$result = array('success'=>false,'message'=>'Empty order array');
|
|
|
35 |
return $result;
|
|
|
36 |
}
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
public function make_request($url,$fields,$format='json'){
|
| 13698 |
anikendra |
40 |
//$this->log($url,'pythonapi');
|
|
|
41 |
//$this->log($fields,'pythonapi');
|
| 13633 |
anikendra |
42 |
$fields_string = '';
|
|
|
43 |
//open connection
|
|
|
44 |
$ch = curl_init();
|
|
|
45 |
//set the url, number of POST vars, POST data
|
|
|
46 |
curl_setopt($ch,CURLOPT_URL, $url);
|
|
|
47 |
curl_setopt($ch,CURLOPT_RETURNTRANSFER , true);
|
|
|
48 |
if(!empty($fields)) {
|
|
|
49 |
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields);
|
|
|
50 |
}
|
|
|
51 |
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
|
52 |
'Content-Type: application/json',
|
|
|
53 |
'Content-Length: ' . strlen($fields))
|
|
|
54 |
);
|
|
|
55 |
//execute post
|
|
|
56 |
$result = curl_exec($ch);
|
|
|
57 |
//close connection
|
|
|
58 |
curl_close($ch);
|
|
|
59 |
switch($format){
|
|
|
60 |
case 'json':
|
|
|
61 |
$response = json_decode($result,1);
|
|
|
62 |
break;
|
|
|
63 |
}
|
|
|
64 |
return $response;
|
|
|
65 |
}
|
|
|
66 |
}
|