A PHP client for authenticating with Uber using OAuth 2.0 and consuming the API.
This package is intended to be used for communicating with the Uber API after you've secured an access token from your users. To authenticate users and retrieve access tokens, use stevenmaguire/oauth2-uber.
Via Composer
$ composer require stevenmaguire/uber-php
Note that the required version of PHP is 5.5. If you want use library with PHP 5.4 you should use 1.2.0 version.
$client = new Stevenmaguire\Uber\Client(array(
'access_token' => 'YOUR ACCESS TOKEN',
'server_token' => 'YOUR SERVER TOKEN',
'use_sandbox' => true, // optional, default false
'version' => 'v1.2', // optional, default 'v1.2'
'locale' => 'en_US', // optional, default 'en_US'
));
Please review the Sandbox documentation on how to develop and test against these endpoints without making real-world Requests and being charged.
$products = $client->getProducts(array(
'latitude' => '41.85582993',
'longitude' => '-87.62730337'
));
https://developer.uber.com/docs/riders/references/api/v1.2/products-get
$product = $client->getProduct($productId);
https://developer.uber.com/docs/riders/references/api/v1.2/products-product_id-get
$estimates = $client->getPriceEstimates(array(
'start_latitude' => '41.85582993',
'start_longitude' => '-87.62730337',
'end_latitude' => '41.87499492',
'end_longitude' => '-87.67126465'
));
https://developer.uber.com/docs/riders/references/api/v1.2/estimates-price-get
$estimates = $client->getTimeEstimates(array(
'start_latitude' => '41.85582993',
'start_longitude' => '-87.62730337'
));
https://developer.uber.com/docs/riders/references/api/v1.2/estimates-time-get
$promotions = $client->getPromotions(array(
'start_latitude' => '41.85582993',
'start_longitude' => '-87.62730337',
'end_latitude' => '41.87499492',
'end_longitude' => '-87.67126465'
));
https://developer.uber.com/docs/riders/ride-promotions/introduction
This feature is only available since version 1.1
.
$client->setVersion('v1.2'); // or v1.1
$history = $client->getHistory(array(
'limit' => 50, // optional
'offset' => 0 // optional
));
https://developer.uber.com/docs/riders/references/api/v1.2/history-get
$profile = $client->getProfile();
https://developer.uber.com/docs/riders/references/api/v1.2/me-get
$attributes = array('applied_promotion_codes' => 'PROMO_CODE');
$profileResponse = $client->setProfile($attributes);
https://developer.uber.com/docs/riders/references/api/v1.2/me-patch
$paymentMethods = $client->getPaymentMethods();
https://developer.uber.com/docs/riders/references/api/v1.2/payment-methods-get
$placeId = 'home';
$place = $client->getPlace($placeId);
https://developer.uber.com/docs/riders/references/api/v1.2/places-place_id-get
$placeId = 'home';
$attributes = array('address' => '685 Market St, San Francisco, CA 94103, USA');
$place = $client->setPlace($placeId, $attributes);
https://developer.uber.com/docs/riders/references/api/v1.2/places-place_id-put
$request = $client->requestRide(array(
'start_latitude' => '41.85582993',
'start_longitude' => '-87.62730337',
'end_latitude' => '41.87499492',
'end_longitude' => '-87.67126465',
'product_id' => '4bfc6c57-98c0-424f-a72e-c1e2a1d49939', // Optional
'surge_confirmation_id' => 'e100a670', // Optional
'payment_method_id' => 'a1111c8c-c720-46c3-8534-2fcd' // Optional
));
Upfront fares means the total fare is known before the ride is taken.
- An end location is required
- There is no surge confirmation flow
- The user should specify a fare_id to confirm consent to the upfront fare
- The user should specify the number of seats that are required for shared products (like UberPOOL)
- In the products endpoint
GET /products
, products will have theupfront_fare_enabled
field set totrue
. - Use the ride request estimate endpoint
POST /requests/estimate
with theproduct_id
to get afare_id
. Thefare_id
can be used to lock down an upfront fare and arrival time for a trip. Thefare_id
expires after two minutes. If thefare_id
is expired or not valid, we return a 422 error. - Request the ride using the ride request endpoint
POST /requests
with thefare_id
returned in the previous step.
https://developer.uber.com/docs/riders/ride-requests/tutorials/api/best-practices#upfront-fares
If the ride request is using a product that has a surge multiplier, the API wrapper will throw an Exception and provide a response body that includes a surge confirmation ID.
try {
$request = $client->requestRide(array(
'product_id' => '4bfc6c57-98c0-424f-a72e-c1e2a1d49939',
'start_latitude' => '41.85582993',
'start_longitude' => '-87.62730337',
'end_latitude' => '41.87499492',
'end_longitude' => '-87.67126465'
));
} catch (Stevenmaguire\Uber\Exception $e) {
$body = $e->getBody();
$surgeConfirmationId = $body['meta']['surge_confirmation']['surge_confirmation_id'];
}
$request = $client->getCurrentRequest();
https://developer.uber.com/docs/riders/references/api/v1.2/requests-current-get
$request = $client->getRequest($requestId);
https://developer.uber.com/docs/riders/references/api/v1.2/requests-request_id-get
$requestDetails = array(
'end_address' => '685 Market St, San Francisco, CA 94103, USA',
'end_nickname' => 'da crib',
'end_place_id' => 'home',
'end_latitude' => '41.87499492',
'end_longitude' => '-87.67126465'
);
$updateRequest = $client->setCurrentRequest($requestDetails);
https://developer.uber.com/docs/riders/references/api/v1.2/requests-current-patch
$requestId = '4bfc6c57-98c0-424f-a72e-c1e2a1d49939'
$requestDetails = array(
'end_address' => '685 Market St, San Francisco, CA 94103, USA',
'end_nickname' => 'da crib',
'end_place_id' => 'home',
'end_latitude' => '41.87499492',
'end_longitude' => '-87.67126465'
);
$updateRequest = $client->setRequest($requestId, $requestDetails);
https://developer.uber.com/docs/riders/references/api/v1.2/requests-request_id-patch
$requestEstimate = $client->getRequestEstimate(array(
'product_id' => '4bfc6c57-98c0-424f-a72e-c1e2a1d49939',
'start_latitude' => '41.85582993',
'start_longitude' => '-87.62730337',
'end_latitude' => '41.87499492', // optional
'end_longitude' => '-87.67126465', // optional
));
https://developer.uber.com/docs/riders/references/api/v1.2/requests-estimate-post
$map = $client->getRequestMap($requestId);
https://developer.uber.com/docs/riders/references/api/v1.2/requests-request_id-map-get
$receipt = $client->getRequestReceipt($requestId);
https://developer.uber.com/docs/riders/references/api/v1.2/requests-request_id-receipt-get
$request = $client->cancelCurrentRequest();
https://developer.uber.com/docs/riders/references/api/v1.2/requests-current-delete
$request = $client->cancelRequest($requestId);
https://developer.uber.com/docs/riders/references/api/v1.2/requests-request_id-delete
$attributes = array(
'reminder_time' => '1429294463',
'phone_number' => '555-555-5555',
'event' => array(
'time' => '1429294463',
'name' => 'Frisbee with friends',
'location' => 'Dolores Park',
'latitude' => '37.759773',
'longitude' => '-122.427063',
),
'product_id' => 'a1111c8c-c720-46c3-8534-2fcdd730040d',
'trip_branding' => array(
'link_text' => 'View team roster',
'partner_deeplink' => 'partner://team/9383',
)
);
$reminder = $client->createReminder($attributes);
https://developer.uber.com/docs/riders/references/api/v1.2/reminders-post
$reminderId = '4bfc6c57-98c0-424f-a72e-c1e2a1d49939';
$reminder = $client->getReminder($reminderId);
https://developer.uber.com/docs/riders/references/api/v1.2/reminders-reminder_id-get
$reminderId = '4bfc6c57-98c0-424f-a72e-c1e2a1d49939';
$attributes = array(
'reminder_time' => '1429294463',
'phone_number' => '555-555-5555',
'event' => array(
'time' => '1429294463',
'name' => 'Frisbee with friends',
'location' => 'Dolores Park',
'latitude' => '37.759773',
'longitude' => '-122.427063',
),
'product_id' => 'a1111c8c-c720-46c3-8534-2fcdd730040d',
'trip_branding' => array(
'link_text' => 'View team roster',
'partner_deeplink' => 'partner://team/9383',
)
);
$reminder = $client->setReminder($reminderId, $attributes);
https://developer.uber.com/docs/riders/references/api/v1.2/reminders-reminder_id-patch
$reminderId = '4bfc6c57-98c0-424f-a72e-c1e2a1d49939';
$reminder = $client->cancelReminder($reminderId);
https://developer.uber.com/docs/riders/references/api/v1.2/reminders-reminder_id-delete
$profile = $client->getDriverProfile();
https://developer.uber.com/docs/drivers/references/api/v1/partners-me-get
$profile = $client->getDriverPayments(array(
'limit' => 50, // optional
'offset' => 0 // optional
));
https://developer.uber.com/docs/drivers/references/api/v1/partners-payments-get
$profile = $client->getDriverTrips(array(
'limit' => 50, // optional
'offset' => 0 // optional
));
https://developer.uber.com/docs/drivers/references/api/v1/partners-trips-get
This feature is only supported for
v1
version of the API.
Rate limiting is implemented on the basis of a specific client's secret token. By default, 1,000 requests per hour can be made per secret token.
When consuming the service with this package, your rate limit status will be made available within the client.
$product = $client->getProduct($productId);
$rateLimit = $client->getRateLimit();
$rateLimit->getLimit(); // Rate limit capacity per period
$rateLimit->getRemaining(); // Requests remaining in current period
$rateLimit->getReset(); // Timestamp in UTC time when the next period will begin
These values will update after each request. getRateLimit
will return null after the client is created and before the first successful request.
https://developer.uber.com/v1/api-reference/#rate-limiting
Modify the status of an ongoing sandbox Request.
These methods will throw
Stevenmaguire\Uber\Exception
when invoked while the client is not in sandbox mode. The underlying API endpoints have no effect unless you are using the sandbox environment.
$request = $client->requestRide(array(
'product_id' => '4bfc6c57-98c0-424f-a72e-c1e2a1d49939',
'start_latitude' => '41.85582993',
'start_longitude' => '-87.62730337',
'end_latitude' => '41.87499492',
'end_longitude' => '-87.67126465'
));
$updateRequest = $client->setSandboxRequest($request->request_id, array('status' => 'accepted'));
https://developer.uber.com/v1/sandbox/#request
Simulate the possible responses the Request endpoint will return when requesting a particular product, such as surge pricing, against the Sandbox.
$product = $client->getProduct($productId);
$updateProduct = $client->setSandboxProduct($productId, array('surge_multiplier' => 2.2, 'drivers_available' => false));
https://developer.uber.com/v1/sandbox/#product-types
$ ./vendor/bin/phpunit
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.