Developers
Sign inGet API keys
SDKs/PHP

PHP SDK

Every method on a typed client, arrays in and out, for Laravel, Symfony or plain PHP.

lumora/lumora-phpPackagist370 methods

Install

Shell
composer require lumora/lumora-php

PHP 8.1 or later with the curl and json extensions.

Make a call

Create a client with an access token: an API key (hg_…) from your own business, or an app's OAuth access token (lmo_at_…). Keep it on your server, never in a browser bundle or mobile app.

PHP
<?php
require 'vendor/autoload.php';

use Lumora\Client;

$lumora = new Client(getenv('LUMORA_ACCESS_TOKEN'));

$page = $lumora->orders->listOrders(['page_size' => 50]);
foreach ($page['orders'] ?? [] as $order) {
    echo $order['number'], ' ', $order['totals']['total'], PHP_EOL; // TZS cents
}

Reads that fail on a network error, a rate limit or a server error are retried twice, waiting as long as the API asks; writes are never retried for you, since the API can't tell a repeat from a second request. Pass a base URL to the client to point it somewhere else, such as a local API.

Connect a business with OAuth

When other businesses use your app, they connect it through Lumora's consent screen and you get tokens for their business. The OAuth guide explains each step.

PHP
<?php
use Lumora\OAuth;

$oauth = new OAuth(getenv('LUMORA_CLIENT_ID'), getenv('LUMORA_CLIENT_SECRET'));

// 1. Send the business owner to Lumora to approve your app.
['verifier' => $verifier, 'challenge' => $challenge] = OAuth::createPkce();
$state = OAuth::createState();
$url = $oauth->authorizationUrl('https://yourapp.co.tz/lumora/callback', ['orders.read', 'catalog.write'], $state, $challenge);

// 2. On the callback, swap the code for tokens.
$tokens = $oauth->exchangeCode($_GET['code'], 'https://yourapp.co.tz/lumora/callback', $verifier);

// 3. Before $tokens['expires_at'], refresh. Refresh tokens are single use.
$tokens = $oauth->refresh($tokens['refresh_token']);

Check webhook signatures

Every delivery is signed with your endpoint's secret. Check it against the raw body before you trust the event; the helper also rejects deliveries older than five minutes. See Webhooks.

PHP
<?php
use Lumora\Webhook;
use Lumora\WebhookSignatureException;

$raw = file_get_contents('php://input'); // the exact bytes
try {
    $event = Webhook::verify(getenv('LUMORA_WEBHOOK_SECRET'), $_SERVER['HTTP_HOLYGRAIL_SIGNATURE'] ?? null, $raw);
} catch (WebhookSignatureException $e) {
    http_response_code(400);
    exit;
}
if ($event['type'] === 'order.updated') {
    $order = $event['data']; // the whole order after the change
}
http_response_code(204);

Errors

Failed calls raise one error type with the API's error code, the HTTP status and, when you hit a rate limit, how long to wait. See Errors and rate limits for the codes.

PHP
<?php
use Lumora\LumoraException;

try {
    $lumora->customers->listCustomers();
} catch (LumoraException $e) {
    echo $e->errorCode;  // "permission_denied", "resource_exhausted", ...
    echo $e->status;     // the HTTP status
    echo $e->retryAfter; // seconds, when rate limited
}

Services

Every service in the API reference is a property of the client:

PropertyServiceMethods
$lumora->ordersOrders11
$lumora->catalogCatalog5
$lumora->customersCustomers6
$lumora->inventoryInventory82
$lumora->invoicesInvoices and estimates13
$lumora->storefrontOnline store7
$lumora->locoPesaLoco Pesa9
$lumora->selcomSelcom11
$lumora->roomsRooms24
$lumora->diningDining1
$lumora->appointmentsAppointments9
$lumora->jobsJobs8
$lumora->teamTeam50
$lumora->payrollPayroll38
$lumora->ledgerLedger and cash accounts53
$lumora->expensesExpenses13
$lumora->accountingAccounting7
$lumora->forecastForecast8
$lumora->searchSearch1
$lumora->autopilotAutopilot7
$lumora->auditAudit log2
$lumora->locationsLocations and devices3
$lumora->syncSync and change feed2

Source and versions

The SDK lives in sdks/php in the Lumora repository. Its service layer is regenerated whenever the API changes, and versions follow semantic versioning: a new method is a minor release, and nothing is removed without a major one.