Example #1
0
 /**
  * PUT order data to Ginger API.
  *
  * @param Order $order
  * @return Order
  */
 private function putOrder(Order $order)
 {
     try {
         return Order::fromArray($this->httpClient->put("orders/" . $order->id() . "/", ["timeout" => 3, "json" => $order->toArray()])->json());
     } catch (RequestException $exception) {
         if ($exception->getCode() == 404) {
             throw new OrderNotFoundException('No order with that ID was found.', 404, $exception);
         }
         throw new ClientException('An error occurred while updating the order: ' . $exception->getMessage(), $exception->getCode(), $exception);
     }
 }
Example #2
0
 /**
  * Post a new order.
  *
  * @param Order $order
  * @return Order
  */
 private function postOrder(Order $order)
 {
     try {
         $response = $this->httpClient->post('orders/', ['timeout' => 3, 'headers' => ['Content-Type' => 'application/json'], 'body' => json_encode(ArrayFunctions::withoutNullValues($order->toArray()))]);
     } catch (RequestException $exception) {
         throw new ClientException('An error occurred while posting the order: ' . $exception->getMessage(), $exception->getCode(), $exception);
     }
     return Order::fromArray($response->json());
 }