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