't1', 'tariffId' => 2181, 'seatAreaCode' => 'STANDING', 'price' => '150.00', ], [ 'ref' => 't2', 'tariffId' => 2181, 'seatAreaCode' => 'STANDING', 'price' => '150.00', ], ]; $orderCustomFields = [ 'additionalTermsAccepted' => 'Y', ]; $ticketsCustomFields = [ 't1' => [ 'uuid' => null, // de completat cu uuid-ul primit de la apelul /lockSeats 'participantName' => 'Mihai Popescu', ], 't2' => [ 'uuid' => null, 'participantName' => 'Ioana Popescu', ], ]; $totalPrice = 0; $shippingMethod = 'PrintAtHome'; $paymentMethod = 'FreeTicket'; $customerInfo = [ 'phone' => '0720123456', 'email' => 'mihai.popescu@example.com', ]; // do the dance try { // login $result = callApi($apiBaseUrl. '/login', null, [ 'key' => $credentials['app_key'], 'secret' => $credentials['app_secret'], ]); print_r($result); $authToken = $result['authToken']; // lockSeats $result = callApi($apiBaseUrl. '/lockSeats', $authToken, [ 'eventId' => $eventId, 'seats' => $seats, ]); print_r($result); $bookingRef = $result['bookingRef']; $lockedSeats = $result['seats'] ?? []; // prepareOrder // asociez customField-urile de fiecare loc blocat foreach ($lockedSeats as $seatData) { if (isset($ticketsCustomFields[$seatData['ref']])) { $ticketsCustomFields[$seatData['ref']]['uuid'] = $seatData['uuid']; } } $result = callApi($apiBaseUrl. '/prepareOrder', $authToken, [ 'bookingRef' => $bookingRef, 'totalPrice' => $totalPrice, 'shippingMethod' => $shippingMethod, 'paymentMethod' => $paymentMethod, 'customerInfo' => $customerInfo, 'customFields' => [ 'order' => $orderCustomFields, 'tickets' => array_values($ticketsCustomFields), ], ]); print_r($result); // currentBooking info $result = callApi($apiBaseUrl. '/currentBooking', $authToken, [ 'bookingRef' => $bookingRef, ]); print_r($result); // confirmOrder $result = callApi($apiBaseUrl. '/confirmOrder', $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; }