misujon / laravel-duffel
A fully featured Laravel package for integrating with Duffelโs Flight and Hotel Booking APIs. Provides an elegant, service-oriented structure for searching flights, creating orders, managing offers, and booking hotels using Duffel's modern travel APIs โ all with built-in error handling, logging, and
Requires
- php: >=8.0
- guzzlehttp/guzzle: ^7.0
- illuminate/support: ^9.0|^10.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2025-05-31 07:48:31 UTC
README
A Laravel-ready package to integrate Duffel's Flights, Seat Maps, Airlines, Airports, Aircraft, and Cities APIs with clean service-based methods.
๐ Installation
1. Install via Composer
composer require misujon/laravel-duffel
2. Publish Configuration
php artisan vendor:publish --provider="Misujon\\LaravelDuffel\\LaravelDuffelServiceProvider" --tag="config"
3. Set Environment Variables
In your Laravel app's .env
file:
DUFFEL_API_KEY=your_duffel_access_token_here DUFFEL_API_URL=https://api.duffel.com/ DUFFEL_API_VERSION=v2 DUFFEL_URL_PREFIX="air"
4. (Optional) Add Facade Aliases
In config/app.php
under aliases:
'Duffel' => Misujon\LaravelDuffel\Facades\Duffel::class,
โ๏ธ FlightService Methods
1. searchFlights(array $searchData)
Description: Search available flights.
Parameters Example:
[ 'slices' => [ ['origin' => 'DXB', 'destination' => 'LHR', 'departure_date' => '2025-07-15'], ], 'passengers' => [ ['type' => 'adult'], ['type' => 'child', 'age' => 8], ], 'cabin_class' => 'economy', ]
Usage:
$response = Duffel::searchFlights($searchData);
2. getFlightOffer(string $offerId)
Description: Fetch a specific flight offer.
Usage:
$response = Duffel::getFlightOffer('off_0000AtXxW8gsgU0dRswvHG');
3. fetchSeatMaps(string $offerId)
Description: Fetch seat maps for a flight offer.
Usage:
$response = Duffel::fetchSeatMaps('off_0000AtXxW8gsgU0dRswvHG');
Returns `` if no seat maps found.
๐ ResourceService Methods
Class for Resource Service
Use all the methods by importing the class
Misujon\LaravelDuffel\Facades\DuffelResource;
1. getAirlines()
Fetch list of airlines.
$response = DuffelResource::getAirlines();
2. getSingleAirline(string $airlineId)
Fetch a specific airline by ID.
$response = DuffelResource::getSingleAirline('arl_0000A3BCD');
3. getAircrafts()
Fetch list of aircrafts.
$response = DuffelResource::getAircrafts();
4. getSingleAircraft(string $aircraftId)
Fetch a specific aircraft.
$response = DuffelResource::getSingleAircraft('arc_0000Abc123');
5. getAirports()
Fetch list of airports.
$response = DuffelResource::getAirports();
6. getSingleAirport(string $airportId)
Fetch a specific airport.
$response = DuffelResource::getSingleAirport('apt_0000AbcXYZ');
7. getCities()
Fetch list of cities.
$response = DuffelResource::getCities();
8. getSingleCity(string $cityId)
Fetch a specific city.
$response = DuffelResource::getSingleCity('cit_0000Abcd987');
๐ OrderService Methods
Class for Resource Service
Use all the methods by importing the class
Misujon\LaravelDuffel\Facades\OrderService;
1. listOrders()
Get a list of all created orders.
Duffel::listOrders();
2. createOrder(array $data)
Create a new flight order.
Duffel::createOrder([ 'selected_offers' => ['off_xxxx'], 'payments' => [[ 'type' => 'balance', 'amount' => '100.00', 'currency' => 'USD' ]], 'passengers' => [ ['id' => 'pas_xxxx'] ] ]);
3. listOrderServices(string $orderId)
List available services for a given order.
Duffel::listOrderServices('ord_xxxx');
4. getOrder(string $orderId)
Get the details of a specific order.
Duffel::getOrder('ord_xxxx');
5. updateOrder(string $orderId, array $data)
Update metadata for a specific order.
Duffel::updateOrder('ord_xxxx', [ 'metadata' => [ 'purpose' => 'client booking' ] ]);
6. addServiceToOrder(string $orderId, array $data)
Add a service (e.g. bag or seat) to an order.
Duffel::addServiceToOrder('ord_xxxx', [ 'services' => [ ['id' => 'ase_xxxx'] ] ]);
๐ Example Usage
use Duffel; class FlightController extends Controller { public function search() { $searchData = [...]; return Duffel::searchFlights($searchData); } public function airline($id) { return Duffel::getSingleAirline($id); } public function createOrder() { return Duffel::createOrder([...]); } }
๐ License
This package is open-sourced software licensed under the MIT license.
๐ฌ Contributing
Pull requests, issues, and feature suggestions are welcome! Let's build together!
โ Support Me
Hi there! ๐ I'm a passionate Full Stack Web Developer with over 5 years of experience crafting powerful, efficient, and creative web solutions. From building robust APIs with PHP/Laravel and Python/Django, to designing dynamic frontend applications with React, Vue, and Next.js, I thrive on solving complex problems and delivering top-quality results.
I specialize in data scraping, API integrations, responsive UI/UX, and full-cycle project management using Agile methodologies. Every project I work on is built with care, innovation, and a strong commitment to excellence. If you enjoy my work, find it useful, or simply want to support an independent developer on their journey โ feel free to buy me a coffee!
Your support truly means a lot and helps me keep doing what I love every day. ๐
Thank you for being awesome! ๐