PHP code example of flairuk / laravel-uber
1. Go to this page and download the library: Download flairuk/laravel-uber 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/ */
flairuk / laravel-uber example snippets
use FLAIRUK\Uber\Facades\Uber;
// 1. Redirect the user to Uber
$pkce = Uber::oauth()::pkce(); // optional; S256
session(['uber_state' => $state = Str::random(40), 'uber_verifier' => $pkce['verifier']]);
return redirect(Uber::oauth()->authorizeUrl(['profile', 'request', 'offline_access'], $state, codeChallenge: $pkce['challenge']));
// 2. On the callback
abort_unless(hash_equals(session('uber_state'), $request->state), 403);
$token = Uber::oauth()->exchangeCode($request->code, codeVerifier: session('uber_verifier'));
$user->update(['uber_token' => $token->toArray()]); // store it, encrypted
// 3. Use it
$uber = Uber::withToken($user->uber_token); // a string, an AccessToken or the stored array
if ($uber->token()->isExpired()) {
$user->update(['uber_token' => ($fresh = Uber::oauth()->refresh($uber->token()))->toArray()]);
$uber = Uber::withToken($fresh);
}
Uber::oauth()->pushAuthorizationRequest($scopes, $state, loginHint: ['email' => $user->email]); // PAR
Uber::oauth()->authorizeUrlFor($requestUri);
Uber::oauth()->revoke($token);
Uber::oauth()->certs(); // JWKS for verifying ID tokens (cached)
Uber::identity()->me(); // OpenID profile (/v3/me), with a user token
$rides = Uber::withToken($token)->rides();
$rides->products(51.5074, -0.1278);
$rides->priceEstimates(51.5074, -0.1278, 51.4700, -0.4543);
$rides->timeEstimates(51.5074, -0.1278);
$fare = $rides->estimate(['product_id' => $productId, 'start_latitude' => 51.5074, /* ... */]);
$ride = $rides->request(['fare_id' => $fare['fare']['fare_id'], 'product_id' => $productId, /* ... */]);
$rides->find($ride['request_id']);
$rides->current();
$rides->cancel($ride['request_id']);
$rides->receipt($ride['request_id']);
$rides->me();
$rides->paymentMethods();
$rides->history()->lazy(); // every past trip, page by page
Uber::sandbox()->withToken($token)->rides()->sandbox()->setStatus($requestId, 'accepted');
Uber::sandbox()->withToken($token)->rides()->sandbox()->setProduct($productId, surgeMultiplier: 2.2);
$estimate = Uber::guestRides()->estimates([
'pickup' => ['latitude' => 51.5074, 'longitude' => -0.1278],
'dropoff' => ['latitude' => 51.4700, 'longitude' => -0.4543],
]);
$trip = Uber::guestRides()->create([
'guest' => ['first_name' => 'Jane', 'last_name' => 'Doe', 'phone_number' => '+447700900000'],
'pickup' => ['latitude' => 51.5074, 'longitude' => -0.1278],
'dropoff' => ['latitude' => 51.4700, 'longitude' => -0.4543],
'product_id' => $estimate[0]['product']['product_id'],
'fare_id' => $estimate[0]['estimate_info']['fare_id'],
]);
Uber::guestRides()->find($trip['request_id']);
Uber::guestRides()->trips('ACTIVE')->lazy();
Uber::guestRides()->message($trip['request_id'], 'At the main entrance');
Uber::guestRides()->cancel($trip['request_id']);
Uber::guestRides()->zones($lat, $lng);
Uber::guestRides()->autocomplete('Heathrow Terminal 5');
Uber::health()->create($trip); // identical calls under /v1/health
Uber::health()->widgetToken($userId); // for Uber's booking and tracking widgets
$run = Uber::sandbox()->guestRides()->sandbox()->createRun([...]);
$guests = Uber::sandbox()->guestRides()->inSandboxRun($run['run_id']);
$guests->create($trip);
Uber::sandbox()->guestRides()->sandbox()->driverState($run['run_id'], $driverId, 'ACCEPT');
$store = ['street_address' => ['20 W 34th St'], 'city' => 'New York', 'state' => 'NY', 'zip_code' => '10001', 'country' => 'US'];
$quote = Uber::direct()->quote(['pickup_address' => $store, 'dropoff_address' => $customer]); // arrays are JSON-encoded for you
$delivery = Uber::direct()->create([
'quote_id' => $quote['id'],
'pickup_name' => 'Store', 'pickup_address' => $store, 'pickup_phone_number' => '+15555555555',
'dropoff_name' => 'Jane', 'dropoff_address' => $customer, 'dropoff_phone_number' => '+15555555556',
'manifest_items' => [['name' => 'Bouquet', 'quantity' => 1, 'size' => 'medium']],
'idempotency_key' => $order->uuid,
]);
Uber::direct()->find($delivery['id']);
Uber::direct()->list(['filter' => 'ongoing'])->lazy();
Uber::direct()->update($delivery['id'], ['tip_by_customer' => 300]);
Uber::direct()->cancel($delivery['id'], 'customer_called_to_cancel');
Uber::direct()->proofOfDelivery($delivery['id']); // base64 image in ['document']
Uber::direct()->refund([...]);
Uber::direct()->stores($lat, $lng);
Uber::direct()->createTest($delivery); // the robot courier completes it by itself
Uber::forCustomer($otherCustomerId)->direct()->find($id);
Uber::direct()->organizations()->create([...]);
Uber::direct()->organizations()->invite($orgId, [...]);
Uber::direct()->businessLocations($orgId)->list()->lazy();
Uber::direct()->businessLocations($orgId)->update($locationId, ['name' => 'Soho']);
// Stores
Uber::eats()->stores()->list()->lazy();
Uber::eats()->stores()->find($storeId);
Uber::eats()->stores()->setStatus($storeId, 'OFFLINE', reason: 'Kitchen closed');
Uber::eats()->stores()->setHolidayHours($storeId, ['2026-12-25' => ['open_time_periods' => []]]);
// Menus (sent gzip-compressed)
Uber::eats()->menus()->replace($storeId, $menu);
Uber::eats()->menus()->updateItem($storeId, $itemId, ['suspension_info' => [...]]);
// Orders: accept or deny within 11.5 minutes of orders.notification
Uber::eats()->orders()->find($orderId, expand: ['carts', 'deliveries', 'payment']);
Uber::eats()->orders()->accept($orderId, ['ready_for_pickup_time' => now()->addMinutes(15)]);
Uber::eats()->orders()->deny($orderId, ['type' => 'STORE_CLOSED', 'info' => 'Closed early']);
Uber::eats()->orders()->ready($orderId);
Uber::eats()->orders()->forStore($storeId, ['state' => 'OFFERED'])->lazy();
// Stores still on the previous order API
Uber::eats()->legacyOrders()->accept($orderId);
// Promotions, reports, Paymentless Checkout, your own couriers
Uber::eats()->promotions()->create($storeId, [...]);
Uber::eats()->reports()->create('ORDER_HISTORY_REPORT', now()->subWeek(), now(), [$storeId]); // link arrives by webhook
Uber::eats()->payments()->charge([...]); // an idempotency key is added
Uber::eats()->couriers()->location([...]);
$merchant = Uber::withToken($merchantToken)->eats();
$merchant->stores()->list();
$merchant->integrations()->activate($storeId, ['is_order_manager' => true, 'integrator_store_id' => $ourId]);
Uber::business()->receipts()->find($orderId); // business.receipts
Uber::business()->vouchers()->create([...]); // organizations.voucher_programs
Uber::business()->vouchers()->generateCodes($programId, 50);
Uber::business()->employees()->create([...]); // business.employees
Uber::business()->employeeTrips()->create([...]); // business.trips
Uber::business()->organizations()->create([...]); // business.organizations
Uber::business()->statements()->find($statementId); // business.statements
Uber::business()->consentUrl($scopes, $redirectUri, 'Acme Travel'); // third-party consent
Uber::identity()->organization($rootOrgId)->createUser([...]);
Uber::identity()->organization($rootOrgId)->users()->lazy();
Uber::withToken($driverToken)->drivers()->trips()->lazy(); // Drivers API
Uber::vehicleSuppliers()->vehicles()->create([...]); // Uber for Suppliers
Uber::vehicleSuppliers()->shifts()->save($earnerId, $start, $end);
Uber::withToken($adsToken)->ads($accountId)->campaigns()->lazy(); // Uber Ads (login.uber.com OAuth)
Uber::aiSolutions()->translate('en_US', 'fr_FR', 'Your driver is here');
Uber::payments()->confirmDeposit($depositId); // Uber Pay (payment providers)
Uber::identity()->linkAccount($yourUserId); // account linking
Uber::get('v1/some/endpoint', ['q' => 1], scopes: ['some.scope']);
Uber::post('v1/some/endpoint', $body, scopes: ['some.scope']);
Uber::withToken($token)->send('PUT', 'v1/thing', ['json' => $body, 'headers' => [...]]);
use FLAIRUK\Uber\Events\WebhookReceived;
Event::listen('uber.orders.notification', function (WebhookEvent $event) {
AcceptOrder::dispatch($event->resourceId()); // queue it: answer Uber fast
});
Event::listen('uber.event.delivery_status', fn (WebhookEvent $event) => $event->status()); // Direct
Event::listen(WebhookReceived::class, fn (WebhookReceived $received) => logger($received->event->type));
use FLAIRUK\Uber\Exceptions\{AuthenticationException, ConflictException, NotFoundException, RateLimitException, UberException, ValidationException};
try {
Uber::direct()->create($delivery);
} catch (ValidationException $e) { // 400 / 422: $e->errorCode, e.g. "address_undeliverable"
} catch (ConflictException $e) { // 409: duplicate_delivery, surge, current_trip_exists…
$e->metadata['delivery_id'] ?? $e->surgeConfirmationUrl();
} catch (RateLimitException $e) { // 429
$this->release($e->retryAfter());
} catch (AuthenticationException $e) { // 401 / 403, or a refused token request
} catch (NotFoundException $e) { // 404
} catch (UberException $e) { // anything else; $e->response for the raw response
}
Uber::sandbox()->guestRides()->estimates($route);
Uber::locale('fr_FR')->withToken($token)->rides()->products($lat, $lng);
Uber::forCustomer($customerId)->direct()->list();
Uber::guestRides()->forOrganization($orgId)->trips();
Http::fake([
'auth.uber.com/oauth/v2/token' => Http::response(['access_token' => 'test', 'expires_in' => 3600]),
'api.uber.com/v1/customers/*/deliveries' => Http::response(['id' => 'del_test', 'status' => 'pending']),
]);
bash
php artisan uber:status --scope=eats.deliveries