1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: a.moreira |
5
|
|
|
* Date: 20/10/2016 |
6
|
|
|
* Time: 09:51 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Integracao\ControlPay\API; |
10
|
|
|
|
11
|
|
|
use GuzzleHttp\Exception\RequestException; |
12
|
|
|
use Integracao\ControlPay\AbstractAPI; |
13
|
|
|
use Integracao\ControlPay\Client; |
14
|
|
|
use Integracao\ControlPay\Helpers\SerializerHelper; |
15
|
|
|
use Integracao\ControlPay\Contracts; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class VenderApi |
19
|
|
|
* @package Integracao\ControlPay\API |
20
|
|
|
*/ |
21
|
|
View Code Duplication |
class VendaApi extends AbstractAPI |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* VenderApi constructor. |
26
|
|
|
*/ |
27
|
|
|
public function __construct(Client $client = null) |
28
|
|
|
{ |
29
|
|
|
parent::__construct('venda', $client); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param Contracts\Venda\VenderRequest $venderRequest |
34
|
|
|
* @return Contracts\Venda\VenderResponse |
35
|
|
|
* @throws \Exception |
36
|
|
|
*/ |
37
|
|
|
public function vender(Contracts\Venda\VenderRequest $venderRequest) |
38
|
|
|
{ |
39
|
|
|
try{ |
40
|
|
|
$response = $this->_httpClient->post(__FUNCTION__,[ |
41
|
|
|
'body' => json_encode($venderRequest), |
42
|
|
|
]); |
43
|
|
|
|
44
|
|
|
return SerializerHelper::denormalize( |
45
|
|
|
$response->json(), |
46
|
|
|
Contracts\Venda\VenderResponse::class |
47
|
|
|
); |
48
|
|
|
}catch (RequestException $ex) { |
49
|
|
|
$responseBody = $ex->getResponse()->json(); |
50
|
|
|
throw new \Exception($responseBody['message']); |
51
|
|
|
}catch (\Exception $ex){ |
52
|
|
|
throw new \Exception($ex->getMessage(), $ex->getCode(), $ex); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// /** |
|
|
|
|
57
|
|
|
// * API Provavelmente descontinuada |
58
|
|
|
// * |
59
|
|
|
// * @return Contracts\Venda\ConsultarVendasResponse |
60
|
|
|
// * @throws \Exception |
61
|
|
|
// */ |
62
|
|
|
// public function consultarVendas(array $ids = []) |
63
|
|
|
// { |
64
|
|
|
// try{ |
65
|
|
|
// $response = $this->_httpClient->post(__FUNCTION__, [ |
66
|
|
|
// 'body' => json_encode(array_map(function($id){ |
67
|
|
|
// return [ |
68
|
|
|
// 'Id' => (string)$id |
69
|
|
|
// ]; |
70
|
|
|
// },$ids)) |
71
|
|
|
// ]); |
72
|
|
|
// |
73
|
|
|
// return SerializerHelper::denormalize( |
74
|
|
|
// $response->json(), |
75
|
|
|
// Contracts\Venda\ConsultarVendasResponse::class |
76
|
|
|
// ); |
77
|
|
|
// }catch (RequestException $ex) { |
78
|
|
|
// $responseBody = $ex->getResponse()->json(); |
79
|
|
|
// throw new \Exception($responseBody['message']); |
80
|
|
|
// }catch (\Exception $ex){ |
81
|
|
|
// throw new \Exception($ex->getMessage(), $ex->getCode(), $ex); |
82
|
|
|
// } |
83
|
|
|
// } |
84
|
|
|
|
85
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.