1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Integracao\ControlPay\API; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Exception\RequestException; |
6
|
|
|
use Integracao\ControlPay\AbstractAPI; |
7
|
|
|
use Integracao\ControlPay\Client; |
8
|
|
|
use Integracao\ControlPay\Constants\ControlPayParameterConst; |
9
|
|
|
use Integracao\ControlPay\Contracts\Pedido; |
10
|
|
|
use Integracao\ControlPay\Helpers\SerializerHelper; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class PedidoApi |
14
|
|
|
* @package Integracao\ControlPay\API |
15
|
|
|
*/ |
16
|
|
|
class PedidoApi extends AbstractAPI |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* PedidoApi constructor. |
20
|
|
|
*/ |
21
|
|
|
public function __construct(Client $client) |
22
|
|
|
{ |
23
|
|
|
parent::__construct('pedido', $client); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param Pedido\InserirRequest $inserirRequest |
28
|
|
|
* @return Pedido\InserirResponse |
29
|
|
|
* @throws \Exception |
30
|
|
|
*/ |
31
|
|
|
public function insert(Pedido\InserirRequest $inserirRequest) |
32
|
|
|
{ |
33
|
|
|
try{ |
34
|
|
|
|
35
|
|
|
foreach ($inserirRequest->getProdutosPedido() as $key => $produto) |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
if(empty($produto->getId())) |
38
|
|
|
$inserirRequest->getProdutosPedido()[$key]->setId( |
39
|
|
|
$this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_PRODUTO_ID) |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$this->response = $this->_httpClient->post(__FUNCTION__,[ |
44
|
|
|
'body' => json_encode($inserirRequest), |
45
|
|
|
]); |
46
|
|
|
|
47
|
|
|
return SerializerHelper::denormalize( |
48
|
|
|
$this->response->json(), |
49
|
|
|
Pedido\InserirResponse::class |
50
|
|
|
); |
51
|
|
|
}catch (RequestException $ex) { |
52
|
|
|
$this->requestException($ex); |
53
|
|
|
}catch (\Exception $ex){ |
54
|
|
|
throw new \Exception($ex->getMessage(), $ex->getCode(), $ex); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param Pedido\GetByFiltrosRequest $getByFiltrosRequest |
60
|
|
|
* @return Pedido\GetByFiltrosResponse |
61
|
|
|
* @throws \Exception |
62
|
|
|
*/ |
63
|
|
View Code Duplication |
public function getByFiltros(Pedido\GetByFiltrosRequest $getByFiltrosRequest) |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
try{ |
66
|
|
|
$this->response = $this->_httpClient->post(__FUNCTION__,[ |
67
|
|
|
'body' => json_encode($getByFiltrosRequest), |
68
|
|
|
]); |
69
|
|
|
|
70
|
|
|
return SerializerHelper::denormalize( |
71
|
|
|
$this->response->json(), |
72
|
|
|
Pedido\GetByFiltrosResponse::class |
73
|
|
|
); |
74
|
|
|
}catch (RequestException $ex) { |
75
|
|
|
$this->requestException($ex); |
76
|
|
|
}catch (\Exception $ex){ |
77
|
|
|
throw new \Exception($ex->getMessage(), $ex->getCode(), $ex); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param $pessoaId |
83
|
|
|
* @param $pedidoReferencia |
84
|
|
|
* @return Pedido\GetByPessoaIdByReferenciaResponse |
85
|
|
|
* @throws \Exception |
86
|
|
|
*/ |
87
|
|
View Code Duplication |
public function getByPessoaIdByReferencia($pessoaId, $pedidoReferencia) |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
try{ |
90
|
|
|
$this->response = $this->_httpClient->post(__FUNCTION__,[ |
91
|
|
|
'query' => $this->addQueryAdditionalParameters([ |
92
|
|
|
'pessoaId' => $pessoaId, |
93
|
|
|
'pedidoReferencia' => $pedidoReferencia |
94
|
|
|
]) |
95
|
|
|
]); |
96
|
|
|
|
97
|
|
|
return SerializerHelper::denormalize( |
98
|
|
|
$this->response->json(), |
99
|
|
|
Pedido\GetByPessoaIdByReferenciaResponse::class |
100
|
|
|
); |
101
|
|
|
}catch (RequestException $ex) { |
102
|
|
|
$this->requestException($ex); |
103
|
|
|
}catch (\Exception $ex){ |
104
|
|
|
throw new \Exception($ex->getMessage(), $ex->getCode(), $ex); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param $pessoaVendedorId |
110
|
|
|
* @param $pedidoId |
111
|
|
|
* @return Pedido\GetByPessoaIdByReferenciaResponse |
112
|
|
|
* @throws \Exception |
113
|
|
|
*/ |
114
|
|
View Code Duplication |
public function getPedidosByPessoaId($pessoaVendedorId, $pedidoId) |
|
|
|
|
115
|
|
|
{ |
116
|
|
|
try{ |
117
|
|
|
$this->response = $this->_httpClient->post(__FUNCTION__,[ |
118
|
|
|
'query' => $this->addQueryAdditionalParameters([ |
119
|
|
|
'pessoaVendedorId' => $pessoaVendedorId, |
120
|
|
|
'pedidoId' => $pedidoId |
121
|
|
|
]) |
122
|
|
|
]); |
123
|
|
|
|
124
|
|
|
return SerializerHelper::denormalize( |
125
|
|
|
$this->response->json(), |
126
|
|
|
Pedido\GetByPessoaIdByReferenciaResponse::class |
127
|
|
|
); |
128
|
|
|
}catch (RequestException $ex) { |
129
|
|
|
$this->requestException($ex); |
130
|
|
|
}catch (\Exception $ex){ |
131
|
|
|
throw new \Exception($ex->getMessage(), $ex->getCode(), $ex); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param $pedidoId |
137
|
|
|
* @return Pedido\CancelarResponse |
138
|
|
|
* @throws \Exception |
139
|
|
|
*/ |
140
|
|
View Code Duplication |
public function cancelar($pedidoId) |
|
|
|
|
141
|
|
|
{ |
142
|
|
|
try{ |
143
|
|
|
$this->response = $this->_httpClient->post(__FUNCTION__,[ |
144
|
|
|
'query' => $this->addQueryAdditionalParameters([ |
145
|
|
|
'pedidoId' => $pedidoId |
146
|
|
|
]) |
147
|
|
|
]); |
148
|
|
|
|
149
|
|
|
return SerializerHelper::denormalize( |
150
|
|
|
$this->response->json(), |
151
|
|
|
Pedido\CancelarResponse::class |
152
|
|
|
); |
153
|
|
|
}catch (RequestException $ex) { |
154
|
|
|
$this->requestException($ex); |
155
|
|
|
}catch (\Exception $ex){ |
156
|
|
|
throw new \Exception($ex->getMessage(), $ex->getCode(), $ex); |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param integer $pedidoId |
162
|
|
|
* @return Pedido\GetByIdResponse |
163
|
|
|
* @throws \Exception |
164
|
|
|
*/ |
165
|
|
View Code Duplication |
public function getById($pedidoId) |
|
|
|
|
166
|
|
|
{ |
167
|
|
|
try{ |
168
|
|
|
$this->response = $this->_httpClient->post(__FUNCTION__,[ |
169
|
|
|
'query' => $this->addQueryAdditionalParameters([ |
170
|
|
|
'pedidoId' => $pedidoId |
171
|
|
|
]) |
172
|
|
|
]); |
173
|
|
|
|
174
|
|
|
return SerializerHelper::denormalize( |
175
|
|
|
$this->response->json(), |
176
|
|
|
Pedido\GetByIdResponse::class |
177
|
|
|
); |
178
|
|
|
}catch (RequestException $ex) { |
179
|
|
|
$this->requestException($ex); |
180
|
|
|
}catch (\Exception $ex){ |
181
|
|
|
throw new \Exception($ex->getMessage(), $ex->getCode(), $ex); |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
} |