Skip to content

BenMacha/ubereat-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

UberEats PHP SDK

Latest Version on Packagist Total Downloads License CI PHP Version Build Status Code Coverage PHPStan PHP CS Fixer Support Palestine

A modern PHP SDK for the UberEats API, supporting PHP 7.4 and above.

Features

  • πŸš€ Modern PHP 7.4+ with strict typing
  • πŸ”’ Type-safe request/response objects
  • πŸ§ͺ Comprehensive test coverage
  • πŸ“ Detailed documentation
  • πŸ”„ Webhook support
  • πŸ› οΈ PSR-3 logging support
  • 🎯 PSR-12 coding standards
  • πŸ” Static analysis with PHPStan level max

Requirements

  • PHP 7.4 or higher
  • Composer
  • Guzzle HTTP Client
  • PSR-3 Logger (optional)

Documentation

Installation

composer require ubereats/php-sdk

Basic Usage

use UberEats\Client\UberEatsClient;

// Create client instance
$client = new UberEatsClient();

// Authenticate
$token = $client->authenticate(
    clientId: 'your-client-id',
    clientSecret: 'your-client-secret'
);

// Get order details
$order = $client->getOrder('order-id');

// Get store details
$store = $client->getStore('store-id');

Available Methods

Authentication

  • authenticate(string $clientId, string $clientSecret): AccessToken

Orders

  • getOrder(string $orderId): Order
  • acceptOrder(string $orderId, AcceptOrderRequest $request): Order
  • denyOrder(string $orderId, DenyOrderRequest $request): Order
  • cancelOrder(string $orderId, CancelOrderRequest $request): Order

Stores

  • getStore(string $storeId): Store
  • getStores(): StoreCollection

Webhook Handling

use UberEats\Webhook\WebhookHandler;

$handler = new WebhookHandler();
$event = $handler->handle($payload);

switch ($event->type) {
    case 'orders.notification':
        handleOrderNotification($event);
        break;
    case 'orders.scheduled.notification':
        handleScheduledOrder($event);
        break;
    case 'delivery.state_changed':
        handleDeliveryStateChange($event);
        break;
    default:
        throw new \InvalidArgumentException('Unknown event type');
}

Error Handling

The SDK throws UberEatsException for any API errors. Each exception includes:

  • HTTP status code
  • Error message
  • Original response data
try {
    $order = $client->getOrder('invalid-id');
} catch (UberEatsException $e) {
    echo $e->getMessage();
    echo $e->getCode();
}

Development

Testing

composer test

Static Analysis

composer phpstan

Code Style

composer cs-fix

Code Coverage

composer test-coverage

Security

If you discover any security related issues, please email contact@benmacha.tn instead of using the issue tracker.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

Changelog

Please see CHANGELOG.md for more information on what has changed recently.

Credits

License

This package is licensed under the MIT License. See the LICENSE file for details.