Aller au contenu

omnifood/ubereats Référence de l’API

Étage
Fournisseur · Omnifood
Version
1.x
Suite de conformité
non branchée
Vérifié en réel
Non vérifié en réel
Licence
MIT
composer require omnifood/ubereats:1.x-dev

Lue dans les fichiers PHP du paquet au commit c567fbf9c19e : ses espaces de noms, classes, interfaces et énumérations, leurs constantes, propriétés et méthodes publiques avec leur PHPDoc, et les options que prennent ses fabriques. Rien n’en est exécuté.

Omnifood\UberEats

  • Api class

    The Uber Eats Marketplace APIs (api.uber.com), thin: JSON calls with a Bearer token from Uber's OAuth (client credentials, 30 days), held until it dies - Uber allows 100 token requests an hour - and Uber's errors, {"code", "message"}, as Omnifood's; 401 and 403 as UnauthorizedException.

    7 methods · 6 constants

  • UberEatsPlatform class

    A store on Uber Eats, through the Marketplace APIs (https://developer.uber.com/docs/eats/introduction): the Order Fulfillment API Suite (/v1/delivery/order, for stores on webhooks version 1.0.0), the Store API Suite (status), the Menu API (upload, items suspended), the holiday hours (Store API, previous version), the webhooks signed with the client secret, and the merchant's consent to link the store (OAuth, scope eats.pos_provisioning).

    24 methods · 2 constants

  • UberEatsPlatformFactory class

    Uber Eats, through the Marketplace APIs (Order Fulfillment, Store, Menu):

    11 options

Omnifood\UberEats

Api class

final class Api Api.php:21

The Uber Eats Marketplace APIs (api.uber.com), thin: JSON calls with a Bearer token from Uber's OAuth (client credentials, 30 days), held until it dies - Uber allows 100 token requests an hour - and Uber's errors, {"code", "message"}, as Omnifood's; 401 and 403 as UnauthorizedException.

const PLATFORM = 'ubereats'
const BASE_URI = 'https://api.uber.com'
const TOKEN_URL = 'https://auth.uber.com/oauth/v2/token'
const SANDBOX_BASE_URI = 'https://test-api.uber.com'
const SANDBOX_TOKEN_URL = 'https://sandbox-login.uber.com/oauth/v2/token'
const SCOPES = ['eats.store', 'eats.order', 'eats.store.orders.read', 'eats.store.status.write']

Orders, the store and the menu, its status (each must be granted to the application by Uber).

Api::__construct()

public function __construct(readonly ?string $clientId = null, readonly ?string $clientSecret = null, ?Token $token = null, readonly array $scopes = self::SCOPES, readonly string $baseUri = self::BASE_URI, readonly string $tokenUrl = self::TOKEN_URL, ?HttpClientInterface $http = null)

Api::request()

public function request(string $method, string $path, array $query = [], array|object|null $json = null): array
Returns

the answer, [] when it has none (204)

Api::token()

public function token(): Token

Api::heldToken()

public function heldToken(): ?Token

Api::refresh()

public function refresh(): Token

Api::grant()

public function grant(array $fields): Token

A token from the token endpoint, the client's id and secret added.

Api::clientId()

public function clientId(): ?string

UberEatsPlatform class

final class UberEatsPlatform implements OrdersInterface, MenuInterface, StoreInterface, NotifiableInterface, RefreshableInterface, OAuthInterface UberEatsPlatform.php:50

A store on Uber Eats, through the Marketplace APIs (https://developer.uber.com/docs/eats/introduction): the Order Fulfillment API Suite (/v1/delivery/order, for stores on webhooks version 1.0.0), the Store API Suite (status), the Menu API (upload, items suspended), the holiday hours (Store API, previous version), the webhooks signed with the client secret, and the merchant's consent to link the store (OAuth, scope eats.pos_provisioning).

A new order (orders.notification) must be accepted or denied within 11.5 minutes, or Uber cancels it. Only the application that is the store's order manager may accept, deny or cancel.

const AUTHORIZE_URL = 'https://auth.uber.com/oauth/v2/authorize'
const PROVISIONING_SCOPES = ['eats.pos_provisioning']

UberEatsPlatform::__construct()

public function __construct(readonly Api $api, readonly ?string $storeId = null, readonly ?string $clientSecret = null, readonly string $language = 'en_us', readonly bool $taxInclusive = true, readonly Validator $validator = new Validator())

UberEatsPlatform::getName()

public function getName(): string

UberEatsPlatform::getChannel()

public function getChannel(): Channel

UberEatsPlatform::capabilities()

public function capabilities(): Capabilities

A modifier group's options are items of the menu; the allergens are free strings at Uber (the EU-14 names are sent), the dietary labels VEGAN, VEGETARIAN, GLUTEN_FREE.

UberEatsPlatform::order()

public function order(string $ref): Order

UberEatsPlatform::orders()

public function orders(?\DateTimeImmutable $since = null): array

The store's orders created since then (the last 24 hours by default; Uber keeps 60 days), newest first.

UberEatsPlatform::accept()

public function accept(string $ref, ?\DateTimeImmutable $readyAt = null): void

Accepted; $readyAt tells Uber when it will be ready for the courier.

UberEatsPlatform::deny()

public function deny(string $ref, DenyReason $reason, ?string $note = null): void

UberEatsPlatform::ready()

public function ready(string $ref): void

UberEatsPlatform::cancel()

public function cancel(string $ref, DenyReason $reason, ?string $note = null): void

UberEatsPlatform::updateReadyTime()

public function updateReadyTime(string $ref, \DateTimeImmutable $readyAt): void

A new time the order will be ready at (accepted, not yet ready, the courier not on the way).

UberEatsPlatform::pushMenu()

public function pushMenu(Menu $menu): void

The store's menu replaced whole (Menu::$hours are its service hours: the store's are the union of its menus'). Items marked unavailable are suspended afterwards with setAvailability().

UberEatsPlatform::menuPayload()

public function menuPayload(Menu $menu): array
Returns

the JSON the upload takes for $menu

UberEatsPlatform::setAvailability()

public function setAvailability(string $itemRef, bool $available, ?\DateTimeImmutable $until = null): void

Suspended until $until - Uber needs an end: a year from now when none is given -, or available again (a suspension in the past).

UberEatsPlatform::status()

public function status(): StoreStatus

UberEatsPlatform::pause()

public function pause(?\DateTimeImmutable $until = null, ?string $reason = null): void

UberEatsPlatform::resume()

public function resume(): void

UberEatsPlatform::setHours()

public function setHours(Hours $hours): void

The dates apart (Hours::$exceptions) as Uber's holiday hours, all of them at once (each call replaces the previous ones); a closed date is 00:00 - 00:00. The week is not set here: at Uber it is the menu's service hours (Menu::$hours, pushMenu()).

UberEatsPlatform::notify()

public function notify(string $body, array $headers): Notification

A webhook from Uber, checked: X-Uber-Signature is the lowercase hex HMAC-SHA256 of the raw body with the client secret. It carries the event and the resource's id, not the order: order($notification->reference) reads it. Notification::$id is Uber's event_id (events are retried, and come out of order). The endpoint answers 200, empty.

UberEatsPlatform::token()

public function token(): ?Token

UberEatsPlatform::refresh()

public function refresh(): Token

A new client-credentials token (30 days), for the site to keep and give back as access_token / token_expires_at.

UberEatsPlatform::authorizationUrl()

public function authorizationUrl(string $redirectUri, string $state, array $scopes = []): string

Where to send the merchant to link their store to the application (scope eats.pos_provisioning); the token exchange() gives is for the provisioning calls only, not for the orders.

UberEatsPlatform::exchange()

public function exchange(string $code, string $redirectUri): Token

UberEatsPlatform::toOrder()

public function toOrder(array $o): Order

An order as the Order Fulfillment API gives it, as an Order: the prices are in payment.payment_detail (tax included), by cart item.

UberEatsPlatformFactory class

final class UberEatsPlatformFactory extends PlatformFactory UberEatsPlatformFactory.php:27

Uber Eats, through the Marketplace APIs (Order Fulfillment, Store, Menu):

options: client_id: '%env(default::UBEREATS_CLIENT_ID)%' # the Developer Dashboard application's client_secret: '%env(default::UBEREATS_CLIENT_SECRET)%' # also the key of the webhooks' signature store_id: '%env(default::UBEREATS_STORE_ID)%' # the store's id at Uber scopes: [eats.store, eats.order, eats.store.orders.read, eats.store.status.write] access_token: ~ # a token kept by the site (refresh(), token()), and when it dies: token_expires_at: ~ # ATOM; Uber allows 100 token requests an hour language: en_us # the menu's texts' translation key tax_inclusive: true # prices include VAT (vat_rate_percentage), else tax_rate sandbox: false # test-api.uber.com / sandbox-login.uber.com base_uri: ~ token_url: ~

Options

OptionDefault
client_idnull
client_secretnull
store_idnull
scopesApi::SCOPES
access_tokennull
token_expires_atnull
language'en_us'
tax_inclusivetrue
sandboxfalse
base_urinull
token_urlnull