baseUrl = self::BASE_URL_TEST; else $this->baseUrl = self::BASE_URL_PROD; } public function createOrder(CreateOrderRequest $request): CreateOrderResponse|string { $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $this->baseUrl.'createOrder', CURLOPT_POST => 1, CURLOPT_USERNAME => $this->username, CURLOPT_PASSWORD => $this->password, CURLOPT_HTTPHEADER => ['Content-Type: application/json'], CURLOPT_POSTFIELDS => json_encode($request, JSON_THROW_ON_ERROR), ]); $response = json_decode(curl_exec($curl)); $code = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); if ($code == 200) { $ret = new CreateOrderResponse(); $ret->hwbNumber = $response->hwbNumber; $ret->orderStatus = OrderStatus::from($response->orderStatus); $ret->pickupDate = new \DateTime($response->pickupDate); $ret->deliveryDate = new \DateTime($response->deliveryDate); $ret->hwbOrPackageLabel = $response->hwbOrPackageLabel; $ret->barcodes = array_map(function ($item) { return $item->barcode; }, $response->package); return $ret; } return $response->message; } }