PATH:
home
/
lab2454c
/
tripvare.com
/
app
/
Http
/
Controllers
/
booking
<?php namespace App\Http\Controllers\booking; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class BookingController extends Controller { public function initiateBooking() { return view('booking.booking'); } public function getAirports(Request $request) { if($request->get('query')) { /*START OF CODE TO TAKE AIRPORTS DATA FROM API AND STORE TO MYSQL DATABASE */ /* $tt =[]; $after = ''; do{ $ch = curl_init(); if(!empty($after)){ curl_setopt($ch, CURLOPT_URL, "https://api.duffel.com/air/airports?after=$after&limit=200"); } else { curl_setopt($ch, CURLOPT_URL, 'https://api.duffel.com/air/airports'); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate'); $headers = array(); $headers[] = 'Accept-Encoding: gzip'; $headers[] = 'Accept: application/json'; $headers[] = 'Duffel-Version: beta'; $headers[] = 'Authorization: Bearer duffel_test_VG1LEOV9tsyktFaZZA3VISXFVwNpdLeVyUGnqlze_Dz'; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close($ch); $test = json_decode($result, true); array_push($tt, $test); $after = $test['meta']['after'] ?? null; } while($after !== null); foreach($tt as $total){ foreach($total['data'] as $data){ DB::table('airports')->insert([ 'time_zone'=>$data['time_zone'], 'name'=>$data['name'], 'longitude'=>$data['longitude'], 'latitude'=>$data['latitude'], 'airport_id'=>$data['id'], 'icao_code'=>$data['icao_code'], 'iata_country_code'=>$data['iata_country_code'], 'iata_code'=>$data['iata_code'], 'city_name'=>$data['city_name'], 'city'=>null, 'created_at'=>date('Y:m:d H:i:s'), 'updated_at'=>date('Y:m:d H:i:s') ]); } } */ /*END OF CODE TO TAKE AIRPORTS DATA FROM API AND STORE TO MYSQL DATABASE */ //dd($tt); $query = $request->get('query'); $data = DB::table('airports') ->where('name', 'LIKE', "{$query}%") ->get(); return json_encode($data); } } public function showOptions(Request $request) { //dd($request); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.duffel.com/air/offer_requests'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n \"data\": {\n \"slices\": [\n {\n \"origin\": \"$request->origin\",\n \"destination\": \"$request->destination\",\n \"departure_date\": \"$request->departure_date\"\n }\n ],\n \"passengers\": [\n {\n \"type\": \"adult\"\n } ],\n \"cabin_class\": \"$request->cabin_class\"\n }\n}"); curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate'); $headers = array(); $headers[] = 'Accept-Encoding: gzip'; $headers[] = 'Accept: application/json'; $headers[] = 'Content-Type: application/json'; $headers[] = 'Duffel-Version: beta'; $headers[] = 'Authorization: Bearer duffel_test_VG1LEOV9tsyktFaZZA3VISXFVwNpdLeVyUGnqlze_Dz'; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close($ch); //return $result; $data = json_decode($result, true); $offers = $data['data']['offers']; $passengers = $data['data']['passengers']; //dd($data, $data['data']['offers'], $data['data']['passengers']); return view('booking.showOptions', compact('offers')); } public function gotoOrder(Request $request) { // dd(json_decode($request->offers[0], true)); $offer = json_decode($request->offers[0], true); return view('booking.orderList', compact('offer')); } public function order(Request $request){ //dd($request->offers); $offer = json_decode($request->offers[0], true); $offer_id = $offer['id']; $amount = $offer['total_amount']; foreach( $offer['passengers'] as $passenger){ $passenger_id = $passenger['id']; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.duffel.com/air/orders'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n \"data\": {\n \"type\": \"instant\",\n \n \"selected_offers\": [\n \"$offer_id\"\n ],\n \"payments\": [\n {\n \"type\": \"balance\",\n \"currency\": \"USD\",\n \"amount\": \"$amount\"\n }\n ],\n \"passengers\": [\n {\n \"type\": \"adult\",\n \"title\": \"mrs\",\n \"phone_number\": \"$request->phone_number\",\n \n \"id\": \"$passenger_id\",\n \"given_name\": \"$request->given_name\",\n \"gender\": \"$request->gender\",\n \"family_name\": \"$request->family_name\",\n \"email\": \"$request->email\",\n \"born_on\": \"$request->born_on\"\n }\n ],\n \"metadata\": {\n \"payment_intent_id\": \"pit_00009htYpSCXrwaB9DnUm2\"\n }\n }\n}"); curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate'); $headers = array(); $headers[] = 'Accept-Encoding: gzip'; $headers[] = 'Accept: application/json'; $headers[] = 'Content-Type: application/json'; $headers[] = 'Duffel-Version: beta'; $headers[] = 'Authorization: Bearer duffel_test_VG1LEOV9tsyktFaZZA3VISXFVwNpdLeVyUGnqlze_Dz'; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close($ch); //dd($result); $orderData = json_decode($result, true); return view('booking.orderComplete', compact('orderData')); } }
[-] BookingController.php
[edit]
[+]
..