Search by

kcabor / kcabor-php

Abbfem

Official PHP library for the Kcabor Developer API (deliveries, merchant, errands, rides, bills, webhooks, customer OAuth).

v1.0.0 2026-11-29 10:43 UTC

This package is auto-updated.

Last update: 2026-11-29 11:32:01 UTC


README

Packagist CI License: MIT

Source and issues: https://github.com/Kcabor/kcabor-php

The official PHP library for the Kcabor Developer API (https://api.kcabor.com/v1). It covers deliveries, the merchant API (stores, catalogue, orders), errands, rides, bills, billing, webhooks, events, the sandbox and the customer OAuth API.

  • PHP 8.1+ and Guzzle 7.
  • Test or live is picked from the key prefix: kc_test_sk_… is the sandbox and kc_live_sk_… is live. Both use the same host.
  • Retries 429, 5xx and network errors with exponential backoff, and honours Retry-After.
  • Sends an Idempotency-Key on every POST automatically and reuses it on each retry. You can set your own key.
  • Throws a typed exception for each error type. Every exception carries requestId, errorCode and param.
  • Pagination iterators, a webhook signature check and an OAuth PKCE helper.

Install

composer require kcabor/kcabor-php

Quickstart: your first test delivery

$kcabor = new Kcabor\KcaborClient(getenv('KCABOR_SECRET_KEY')); // kc_test_sk_...

$quote = $kcabor->deliveryQuotes->create([
    'pickup' => ['address' => '12 Adeola Odeku, Victoria Island, Lagos', 'contact' => ['name' => 'Shop', 'phone' => '+2348012345678']],
    'dropoffs' => [['address' => '1 Admiralty Way, Lekki Phase 1, Lagos', 'contact' => ['name' => 'Ada', 'phone' => '+2348098765432']]],
    'delivery_method' => 'motorcycle',
]);

echo $quote->total;              // kobo: 250000 = ₦2,500
echo $quote->expires_at;

$delivery = $kcabor->deliveries->create(
    ['quote_id' => $quote->id, 'reference' => 'ORDER-1001'],
    ['idempotency_key' => 'order-1001'], // optional: your own key makes retries safe across processes
);

echo $delivery->tracking_url;

// Sandbox only: move it along without waiting for the simulator.
$kcabor->sandbox->advanceDelivery($delivery->id, ['status' => 'picked_up']);

Resources

Property Methods
account ping, me
deliveryQuotes create, retrieve
deliveries create, retrieve, all, cancel, redeliver, returnToSender, tip, events, location, proof
errands types, createQuote, retrieveQuote, create, retrieve, all, cancel, approveOverspend, disputeOverspend, events, location, receipt
rides vehicleTypes, createQuote, retrieveQuote, create, retrieve, all, cancel, events, location, tip, rate, receipt
bills services, plans, validateCustomer, purchase, retrievePurchase, purchases, requery
billing balance, transactions, invoices, invoice
stores all, retrieve, update, hours, updateHours, open, close, pause, resume, earnings, balance, payouts
catalogue categories, createCategory, updateCategory, deleteCategory, products, product, createProduct, updateProduct, deleteProduct, updateStock, bulkStock, sync, syncs, retrieveSync
storeOrders all, retrieve, adjustments, accept, reject, ready, cancel, adjust
webhookEndpoints all, create, retrieve, update, remove, test, rollSecret
events all, retrieve
sandbox advanceDelivery, advanceErrand, advanceRide, advanceBillPurchase, createStoreOrder, advanceStoreOrder

Each call returns a Kcabor\KcaborObject. You can read fields as properties or as array keys ($d->status, $d['price']['total']), and ->requestId() gives the request id. If an endpoint has no method yet, $kcabor->request('GET', 'path', $query, $body) calls it.

Money is always an integer in kobo, and times are ISO 8601 strings.

Pagination

foreach ($kcabor->deliveries->all(['limit' => 100, 'status' => 'delivered'])->autoPagingIterator() as $delivery) {
    // fetches the next page with starting_after = meta.next_cursor as you go
}

Errors

use Kcabor\Exception\{InvalidRequestException, BillingException, RateLimitException, KcaborException};

try {
    $kcabor->deliveries->create(['quote_id' => $quoteId]);
} catch (BillingException $e) {          // insufficient_balance, credit_limit_exceeded (402)
} catch (InvalidRequestException $e) {   // quote_expired, address_out_of_coverage, validation_failed...
    error_log($e->errorCode.' '.$e->param.' '.$e->requestId);
} catch (RateLimitException $e) {        // after the SDK's own retries; $e->retryAfter()
} catch (KcaborException $e) {           // everything else, including ApiConnectionException
}
error.type Exception
authentication_error AuthenticationException
permission_error PermissionException
invalid_request_error InvalidRequestException
idempotency_error IdempotencyException
billing_error BillingException
rate_limit_error RateLimitException
api_error ApiErrorException
(no response) ApiConnectionException

Webhooks

$payload = file_get_contents('php://input');           // the RAW body
$header = $_SERVER['HTTP_KCABOR_SIGNATURE'] ?? '';

try {
    $event = Kcabor\Webhook::constructEvent($payload, $header, getenv('KCABOR_WEBHOOK_SECRET')); // whsec_...
} catch (Kcabor\Exception\SignatureVerificationException $e) {
    http_response_code(400);
    exit;
}

if ($event->type === 'delivery.delivered') {
    $delivery = $event->data['object'];
}
http_response_code(200);

The check uses HMAC-SHA256 over "{t}.{raw body}" and compares in constant time. It rejects a timestamp more than 300 seconds old (set this with $tolerance) and accepts any matching v1, which keeps working while you roll a secret. Delivery is at least once, so deduplicate on $event->id.

Customer Ordering API (OAuth 2.0 + PKCE)

use Kcabor\OAuth\{OAuthClient, Pkce};

$oauth = new OAuthClient('kc_test_cli_...', 'https://app.example.com/kcabor/callback'); // add 'client_secret' for confidential apps
$pkce = Pkce::generate();
$state = Pkce::state();
$_SESSION['kcabor'] = ['verifier' => $pkce->verifier, 'state' => $state];
header('Location: '.$oauth->authorizationUrl(['catalogue:read', 'orders:read', 'orders:write'], $state, $pkce));

// Callback: check $_GET['state'] against the session, then
$tokens = $oauth->exchangeCode($_GET['code'], $_SESSION['kcabor']['verifier']);
$customer = new Kcabor\CustomerClient($tokens['access_token']);
$stores = $customer->customer->stores(['address_id' => 12]);
$tokens = $oauth->refresh($tokens['refresh_token']);  // refresh tokens rotate, so store the new one

Options

new Kcabor\KcaborClient($key, [
    'timeout' => 30,          // seconds per attempt
    'connect_timeout' => 10,
    'max_retries' => 2,
    'max_retry_delay' => 30,  // also caps Retry-After
    'base_url' => 'https://api.kcabor.com/v1',
    'http_client' => $guzzle, // your own GuzzleHttp\ClientInterface
]);

Development

composer install
vendor/bin/phpunit   # tests use Guzzle's MockHandler, with no network calls

MIT licensed.