Laravel package to interact with the TCPOS Web Order and Delivery API

1.0.0 2025-05-28 11:09 UTC

This package is auto-updated.

Last update: 2025-05-28 11:12:55 UTC


README

This package provides a Laravel 10+ interface for the TCPOS Web Order and Delivery API.

Requirements

  • PHP >= 8.3
  • Laravel >= 10

Installation

composer require upgradelabs/tcpos
php artisan vendor:publish --provider="Upgradelabs\\TCPOS\\TCPOSServiceProvider" --tag="config"

Configuration

Publish the config file with:

php artisan vendor:publish --provider="Upgradelabs\\TCPOS\\TCPOSServiceProvider" --tag="config"

Then in your .env:

TCPOS_API_URL=https://api.example.com
TCPOS_API_TOKEN=your_token_here
TCPOS_TIMEOUT=10

Configuration file (config/tcpos.php):

return [
    'base_uri' => env('TCPOS_API_URL', 'http://localhost:17777'),
    'timeout'  => env('TCPOS_TIMEOUT', 10),
    'token'    => env('TCPOS_API_TOKEN'),
];

Usage

1. Using the Facade

use TCPOS;

// Retrieve shop list
$shops = TCPOS::getShops();

// Fetch configuration for shop ID 5 as of today
$config = TCPOS::getShopConfiguration(5, now()->toIso8601String());

// List articles for shop ID 5, group ID 2, page 1
$articles = TCPOS::getArticles(5, 2, 50, 1);

2. Dependency Injection

You can inject the client directly into services or controllers:

use Upgradelabs\TCPOS\Client;

class OrderController extends Controller
{
    protected Client $tcpos;

    public function __construct(Client $tcpos)
    {
        $this->tcpos = $tcpos;
    }

    public function index()
    {
        return $this->tcpos->getShops();
    }
}

3. Creating and Confirming an Order

$orderData = [
    'customerId' => 123,
    'date'       => now()->toIso8601String(),
    'shopId'     => 1,
    'orderType'  => 'takeaway',
    'itemList'   => [
        ['article' => ['id' => 3994, 'quantity' => 1]],
    ],
];

// Calculate prices and taxes
$calculated = TCPOS::calculateOrder($orderData);

// Create the order
$created = TCPOS::createOrder($orderData);

// Confirm the order
$confirmed = TCPOS::confirmOrder([
    'orderId' => $created['orderId'],
    'confirmationData' => [...],
]);

4. Error Handling

All methods throw an exception on HTTP or API-level errors:

use Illuminate\Support\Facades\Log;

try {
    $shops = TCPOS::getShops();
} catch (\Exception $e) {
    Log::error('TCPOS API error: ' . $e->getMessage());
    abort(500, 'Unable to retrieve shops.');
}

5. Customizing at Runtime

Override timeout or base URI:

app()->make(Upgradelabs\TCPOS\Client::class)
    ->setTimeout(30)
    ->setBaseUri('https://staging-api.example.com');

6. Testing

Run the full test suite:

vendor/bin/phpunit

Endpoints

All available endpoints are exposed via facade TCPOS or injected Client. See src/Http/Client.php for the complete method list.