$credentials['app_key'], 'secret' => $credentials['app_secret'], ]); print_r($result); $authToken = $result['authToken']; // 2. events $result = callApi($apiBaseUrl. '/events', $authToken, [ 'authToken' => $authToken ]); print_r($result); $eventId = $result['events'][0]['id']; // 3. eventTariffs $result = callApi($apiBaseUrl. '/eventTariffs', $authToken, [ 'authToken' => $authToken, 'eventId' => $eventId ]); print_r($result); $tariffId = $result['tariffs'][0]['id']; $seatAreaCode = $result['tariffs'][0]['areas'][0]; $price = $result['tariffs'][0]['price']; // 4. lockSeats $result = callApi($apiBaseUrl. '/lockSeats', $authToken, [ 'authToken' => $authToken, 'eventId' => $eventId, 'seats' => [ [ 'tariffId' => $tariffId, 'seatAreaCode' => $seatAreaCode, 'price' => $price, ], ], ]); print_r($result); $bookingRef = $result['bookingRef']; // 5. prepareOrder $result = callApi($apiBaseUrl. '/prepareOrder', $authToken, [ 'authToken' => $authToken, 'bookingRef' => $bookingRef, 'totalPrice' => $price, 'customerInfo' => [ 'phone' => '0720123456', 'email' => 'aaa@example.com', ], ]); print_r($result); // 6. confirmOrder $result = callApi($apiBaseUrl. '/confirmOrder', $authToken, [ 'authToken' => $authToken, 'bookingRef' => $bookingRef ]); print_r($result); } catch (Exception $e) { echo $e->getMessage(), PHP_EOL; exit -1; } echo 'Done.', PHP_EOL; function callApi($url, $authToken, $data) { echo $url. PHP_EOL; $ch = curl_init($url); $data_json = json_encode($data); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $headers = [ 'Content-Type: application/json', 'Content-Length: '. strlen($data_json), ]; if ($authToken) { $headers[] = 'Authorization: Bearer '. $authToken; } curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); if ($result === false) { die('cURL error: ' . curl_error($ch). PHP_EOL); } $result = json_decode($result, true); if (isset($result['error'])) { throw new Exception("API error: [{$result['error']}] {$result['message']}"); } return $result; }