pagantis /
orders-api-client
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Pagantis\OrdersApiClient\Method; |
||
| 4 | |||
| 5 | use Httpful\Http; |
||
| 6 | use Httpful\Request; |
||
| 7 | use Httpful\Response; |
||
| 8 | use Pagantis\OrdersApiClient\Exception\ClientException; |
||
| 9 | use Pagantis\OrdersApiClient\Model\Order; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Class GetOrderMethod |
||
| 13 | * |
||
| 14 | * @package Pagantis\OrdersApiClient\Method |
||
| 15 | */ |
||
| 16 | class GetOrderMethod extends AbstractMethod |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * Get Order Endpoint |
||
| 20 | */ |
||
| 21 | const ENDPOINT = '/orders'; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var string $orderId |
||
| 25 | */ |
||
| 26 | protected $orderId; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @param string $orderId |
||
| 30 | * |
||
| 31 | * @return GetOrderMethod |
||
| 32 | */ |
||
| 33 | public function setOrderId($orderId) |
||
| 34 | { |
||
| 35 | $this->orderId = $orderId; |
||
| 36 | |||
| 37 | return $this; |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @return $this|AbstractMethod |
||
| 42 | * @throws \Httpful\Exception\ConnectionErrorException |
||
| 43 | * @throws \Pagantis\OrdersApiClient\Exception\HttpException |
||
| 44 | * @throws ClientException |
||
| 45 | */ |
||
| 46 | public function call() |
||
| 47 | { |
||
| 48 | if (is_string($this->orderId)) { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 49 | $this->prepareRequest(); |
||
| 50 | return $this->setResponse($this->request->send()); |
||
| 51 | } |
||
| 52 | throw new ClientException('Please set OrderId'); |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @return bool|Order |
||
| 57 | * |
||
| 58 | * @throws \Exception |
||
| 59 | */ |
||
| 60 | public function getOrder() |
||
| 61 | { |
||
| 62 | $response = $this->getResponse(); |
||
| 63 | if ($response instanceof Response) { |
||
|
0 ignored issues
–
show
|
|||
| 64 | $order = new Order(); |
||
| 65 | $order->import($this->getResponse()->body); |
||
| 66 | return $order; |
||
| 67 | } |
||
| 68 | |||
| 69 | return false; |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * prepareRequest |
||
| 74 | */ |
||
| 75 | protected function prepareRequest() |
||
| 76 | { |
||
| 77 | if (!$this->request instanceof Request) { |
||
|
0 ignored issues
–
show
|
|||
| 78 | $this->request = $this->getRequest() |
||
| 79 | ->method(Http::GET) |
||
| 80 | ->uri( |
||
| 81 | $this->apiConfiguration->getBaseUri() |
||
| 82 | . self::ENDPOINT |
||
| 83 | . self::SLASH |
||
| 84 | . $this->orderId |
||
| 85 | ) |
||
| 86 | ; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 90 |