PHP code example of santosdave / sabre-wrapper

1. Go to this page and download the library: Download santosdave/sabre-wrapper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

santosdave / sabre-wrapper example snippets


// config/app.php
'providers' => [
    // ...
    Santosdave\SabreWrapper\SabreServiceProvider::class,
],

'aliases' => [
    // ...
    'Sabre' => Santosdave\SabreWrapper\Facades\Sabre::class,
]

return [
    /*
    |--------------------------------------------------------------------------
    | Sabre API Environment
    |--------------------------------------------------------------------------
    |
    | This value determines which Sabre API environment to use.
    | Supported: "cert", "prod"
    */
    'environment' => env('SABRE_ENVIRONMENT', 'cert'),

    /*
    |--------------------------------------------------------------------------
    | API Endpoints
    |--------------------------------------------------------------------------
    */
    'endpoints' => [
        'cert' => [
            'rest' => 'https://api.cert.platform.sabre.com',
            'soap' => 'https://webservices.cert.platform.sabre.com'
        ],
        'prod' => [
            'rest' => 'https://api.platform.sabre.com',
            'soap' => 'https://webservices.platform.sabre.com'
        ]
    ],

    /*
    |--------------------------------------------------------------------------
    | API Credentials
    |--------------------------------------------------------------------------
    */
    'credentials' => [
        'username' => env('SABRE_USERNAME'),
        'password' => env('SABRE_PASSWORD'),
        'pcc' => env('SABRE_PCC'),
        'client_id' => env('SABRE_CLIENT_ID'),
        'client_secret' => env('SABRE_CLIENT_SECRET')
    ],

    // ... Full configuration details
];

use Santosdave\SabreWrapper\Facades\Sabre;

// Create shopping request
$request = new BargainFinderMaxRequest();
$request->addOriginDestination(
    'JFK',
    'LHR',
    '2024-03-15'
);

// Execute search
$results = Sabre::shopping()->bargainFinderMax($request);

// Access results
foreach ($results->getOffers() as $offer) {
    echo $offer['total_fare']['amount'];
}

// Create order
$request = new OrderCreateRequest();
$request->setOffer($offerId, [$offerItemId])
    ->addPassenger(
        'PAX1',
        'John',
        'Doe',
        '1990-01-01',
        'ADT',
        'CONTACT1'
    );

$order = Sabre::order()->createOrder($request);

// Fulfill order
$fulfillRequest = new OrderFulfillRequest($order->getOrderId());
$fulfillRequest->setPaymentCard(
    $cardNumber,
    $expirationDate,
    $vendorCode,
    $cvv,
    $contactInfoRefId
);

$result = Sabre::order()->fulfillOrder($fulfillRequest);

// REST Service (default)
$restShopping = Sabre::shopping();

// SOAP Service
$soapShopping = Sabre::shopping(ServiceFactory::SOAP);


// Get service health status
$health = Sabre::health()->checkStatus();

// Get detailed metrics
$metrics = Sabre::health()->getMetrics();

// Check current rate limit status
$status = Sabre::getRateLimitStatus();

// Handle rate limit exceeded
try {
    $results = Sabre::shopping()->bargainFinderMax($request);
} catch (SabreRateLimitException $e) {
    $retryAfter = $e->getRetryAfter();
    $resetTime = $e->getReset();
}

// Enable caching for specific requests
$results = Cache::remember('flight_search_' . md5(serialize($params)), 300, function () use ($request) {
    return Sabre::shopping()->bargainFinderMax($request);
});

use Santosdave\SabreWrapper\Facades\Sabre;

// 1. Shop for Offers
$shopRequest = new BargainFinderMaxRequest();
$shopRequest
    ->addOriginDestination(
        'JFK',
        'LHR',
        '2024-03-15'
    )
    ->setTravelPreferences([
        'vendorPrefs' => ['AA', 'BA'],
        'cabinPrefs' => ['Y']
    ])
    ->addTraveler('ADT', 1);

$shopResponse = Sabre::shopping()->bargainFinderMax($shopRequest);

// 2. Price Verification
$priceRequest = new OfferPriceRequest();
$priceRequest
    ->addOfferItem($shopResponse->getOffers()[0]['offerId'])
    ->setCreditCard(
        'MC',
        '545251',
        'FDA'
    );

$priceResponse = Sabre::pricing()->priceOffer($priceRequest);

// 3. Create Booking
$bookingRequest = new CreateBookingRequest();
$bookingRequest
    ->setFlightOffer(
        $priceResponse->getOfferId(),
        [$priceResponse->getOfferItemId()]
    )
    ->addTraveler(
        'PAXID1',
        'John',
        'Doe',
        '1990-01-01',
        'ADT'
    )
    ->setContactInfo(
        ['[email protected]'],
        ['1234567890']
    );

$booking = Sabre::booking()->createBooking($bookingRequest);

// 4. Get Booking Details
$bookingDetails = Sabre::booking()->getBooking($booking->getConfirmationId());

// 5. Cancel if needed
$cancelled = Sabre::booking()->cancelBooking(
    $booking->getConfirmationId(),
    true, // retrieveBooking
    true  // cancelAll
);

// 1. Create Order with Advanced Options
$orderRequest = new OrderCreateRequest();
$orderRequest
    ->setOffer($priceResponse->getOfferId(), [$priceResponse->getOfferItemId()])
    ->addPassenger(
        'PAX1',
        'ADT',
        'John',
        'Doe',
        '1990-01-01'
    )
    ->addContactInfo(
        'CI-1',
        ['[email protected]'],
        ['1234567890']
    );

$orderResponse = Sabre::order()->createOrder($orderRequest);

// 2. Order Fulfillment with Payment
$fulfillRequest = new OrderFulfillRequest($orderResponse->getOrderId());
$fulfillRequest
    ->setPaymentCard(
        $cardNumber,
        $expirationDate,
        $vendorCode,
        $cvv,
        'CI-1'
    )
    ->setAmount(161.60, 'USD');

$fulfillResponse = Sabre::order()->fulfillOrder($fulfillRequest);

// 3. Add Ancillary Services
$ancillaryRequest = new AncillaryRequest();
$ancillaryRequest
    ->setTravelAgencyParty($pseudoCityId, $agencyId)
    ->addFlightSegment(
        'SEG1',
        'JFK',
        'LHR',
        '2024-03-15',
        'AA',
        '100',
        'Y'
    );

$ancillaries = Sabre::ancillary()->getAncillaries($ancillaryRequest);

// 4. Seat Assignment
$seatRequest = new SeatAssignRequest($orderResponse->getOrderId());
$seatRequest
    ->addSeatAssignment('PAX1', 'SEG1', '12A')
    ->setPaymentCard(
        $cardNumber,
        $expirationDate,
        $cardCode,
        $cardType,
        50.00,
        'USD'
    );

$seatResponse = Sabre::seat()->assignSeats($seatRequest);

// 5. Order Management
// View Order
$viewRequest = new OrderViewRequest($orderResponse->getOrderId());
$orderDetails = Sabre::order()->viewOrder($viewRequest);

// Change Order
$changeRequest = new OrderChangeRequest($orderResponse->getOrderId());
$changeRequest->addModifyPassengerAction('PAX1', [
    'contactInfo' => ['email' => '[email protected]']
]);
$changeResponse = Sabre::order()->changeOrder($changeRequest);

// Split Order
$splitRequest = new OrderSplitRequest($orderResponse->getOrderId());
$splitRequest->addSplitItem('ITEM1', ['PAX1']);
$splitResponse = Sabre::order()->splitOrder($splitRequest);

// Exchange Order
$exchangeRequest = new OrderExchangeRequest($orderResponse->getOrderId());
$exchangeRequest
    ->addExchangeItem('ITEM1')
    ->setNewItinerary($newFlightDetails)
    ->setPaymentCard(
        $cardNumber,
        $expirationDate,
        $vendorCode,
        $cvv,
        'CI-1'
    );

$exchangeResponse = Sabre::order()->exchangeOrder($exchangeRequest);

try {
    $response = Sabre::booking()->createBooking($request);
} catch (SabreAuthenticationException $e) {
    // Handle authentication errors
    Log::error('Authentication failed', [
        'error' => $e->getMessage(),
        'code' => $e->getCode()
    ]);
} catch (SabreRateLimitException $e) {
    // Handle rate limiting
    Log::warning('Rate limit exceeded', [
        'retry_after' => $e->getRetryAfter()
    ]);
} catch (SabreApiException $e) {
    // Handle general API errors
    Log::error('API error', [
        'message' => $e->getMessage(),
        'details' => $e->getErrorDetails()
    ]);
}
bash
php artisan vendor:publish --provider="Santosdave\SabreWrapper\SabreServiceProvider"