PHP code example of foodticket / takeaway-pos-client

1. Go to this page and download the library: Download foodticket/takeaway-pos-client 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/ */

    

foodticket / takeaway-pos-client example snippets


'routes_prefix'     => '/takeaway-pos/webhooks',
'routes_middleware' => ['webhooks'],

use Foodticket\Takeaway\Endpoints\TakeawayApi;

$api = new TakeawayApi();

$api->logInClient(
    restaurantId: 'restaurant-uuid',
    orderUrl: 'https://your-app.example/takeaway-pos/webhooks/order',
    aliveUrl: 'https://your-app.example/takeaway-pos/webhooks/keep-alive/restaurant-uuid',
    clientKey: 'your-client-key',
    driverUpdateUrl: null,       // optional — defaults to 'https://nodriverupdates' if omitted
    orderCancelledUrl: null,     // optional — subscribes to orderCancelled events
);

$api->logOutClient(
    restaurantId: 'restaurant-uuid',
);

use Foodticket\Takeaway\Enums\OrderStatus;
use Carbon\Carbon;

$api->setOrderStatus(
    statusUrl: $statusUrl,           // URL provided in the incoming order payload
    id: $orderId,
    status: OrderStatus::CONFIRMED,
    key: $orderKey,
    changedDeliveryTime: Carbon::now()->addMinutes(30), // 

Event::listen('takeaway-pos.keep-alive', function (string $restaurantId) {
    // mark restaurant as online, etc.
});

Event::listen('takeaway-pos.order-created', function (TakeawayWebhook $webhook) {
    $webhook->eventName();    // 'takeaway-pos.order-created'
    $webhook->restaurantId(); // restaurant identifier from the payload
    $webhook->resourceId();   // order id from the payload
    $webhook->payload();      // full raw payload array
});
bash
php artisan vendor:publish --tag=config