Search by

kcabor / kcabor-laravel

Abbfem

Official Laravel package for the Kcabor Developer API: service provider, facade, webhook route with signature check and events, Artisan commands and a test fake.

v1.0.0 2026-11-29 11:35 UTC

This package is auto-updated.

Last update: 2026-11-29 11:38:09 UTC


README

Packagist CI License: MIT

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

The official Laravel package for the Kcabor Developer API (https://api.kcabor.com/v1). It wraps kcabor/kcabor-php, so retries, idempotency keys, typed exceptions, pagination and the webhook signature check all come from the SDK.

  • Laravel 12 and 13 (PHP 8.2+; Laravel 13 needs PHP 8.3+).
  • A Kcabor facade and an injectable Kcabor\KcaborClient singleton.
  • A webhook route that verifies Kcabor-Signature, skips duplicates and fires Laravel events.
  • kcabor:ping and kcabor:webhook:test Artisan commands.
  • Kcabor::fake() for tests.

Install

composer require kcabor/kcabor-laravel

The service provider and the Kcabor facade alias are discovered automatically. Add your keys to .env:

KCABOR_SECRET_KEY=kc_test_sk_...
KCABOR_WEBHOOK_SECRET=whsec_...

Test or live comes from the key: kc_test_sk_… is the sandbox and kc_live_sk_… is live. Both use the same host, so there is no separate switch. Check it works:

php artisan kcabor:ping

Configuration

Publish the file only if you want to change the defaults:

php artisan vendor:publish --tag=kcabor-config
Key Env Default
secret_key KCABOR_SECRET_KEY none Business secret key. Required to use the client
base_url KCABOR_BASE_URL SDK default (https://api.kcabor.com/v1) Override the API host
timeout KCABOR_TIMEOUT SDK default (30 s) Seconds per attempt
max_retries KCABOR_MAX_RETRIES SDK default (2) Retries on 429, 5xx and network errors
webhook.secret KCABOR_WEBHOOK_SECRET none Endpoint signing secret (whsec_…)
webhook.enabled KCABOR_WEBHOOK_ENABLED true Register the webhook route
webhook.path KCABOR_WEBHOOK_PATH kcabor/webhook Route path
webhook.middleware [] Extra middleware, for example a throttle
webhook.tolerance KCABOR_WEBHOOK_TOLERANCE 300 Seconds a signature timestamp may be off
webhook.log KCABOR_WEBHOOK_LOG false Log the type and id of each verified event
webhook.dedupe_ttl 1440 Minutes an event id is remembered (24 h)
webhook.cache_store KCABOR_WEBHOOK_CACHE_STORE default store Cache store used for de-duplication

Usage

Resources are the SDK's resource properties, called like methods on the facade. See the PHP SDK README for every method.

use Kcabor\Laravel\Facades\Kcabor;

$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',
]);

$delivery = Kcabor::deliveries()->create(
    ['quote_id' => $quote->id, 'reference' => 'ORDER-1001'],
    ['idempotency_key' => 'order-1001'],
);

echo $delivery->tracking_url;

Accessors: account, deliveryQuotes, deliveries, errands, rides, bills, billing, stores, catalogue, storeOrders, webhookEndpoints, events and sandbox. The facade also forwards environment(), isTest() and request().

Or inject the client:

use Kcabor\KcaborClient;

public function __construct(private KcaborClient $kcabor) {}

It is also bound as app('kcabor'). Errors are the SDK's typed exceptions (Kcabor\Exception\InvalidRequestException, BillingException, RateLimitException, and so on).

Webhooks

The package registers POST /kcabor/webhook (route name kcabor.webhook). In the Kcabor developer console, add an endpoint pointing at https://your-app.example/kcabor/webhook and copy its signing secret to KCABOR_WEBHOOK_SECRET.

For each request it:

  1. Verifies Kcabor-Signature: t=…,v1=… (HMAC-SHA256 of "{t}.{raw body}", 300 s tolerance) with the SDK. A bad or missing signature gets 400.
  2. Skips an event id it saw in the last 24 hours (the API delivers at least once), using your cache.
  3. Fires the Laravel events below and answers 200.

The route is not in the web group, so there is no CSRF check. Listeners run during the request, so queue anything slow (ShouldQueue listeners work). If a listener throws, the id is forgotten and the next delivery attempt runs it again.

Events

Every event has type, id, payload (the full decoded event), livemode, object() (the resource, data.object) and action() (the part after the dot).

Event class (Kcabor\Laravel\Events\…) Fired for
WebhookReceived every event
DeliveryWebhook delivery.*
OrderWebhook order.* (store orders)
ErrandWebhook errand.*
RideWebhook ride.*
BillWebhook bill.*
AccountWebhook wallet.*, cod.*, invoice.*, account.*
StoreWebhook store.*, catalogue.*, stock.*
CustomerOrderWebhook customer_order.*, oauth_grant.*

webhook.test (the console's test button) only fires WebhookReceived.

// app/Listeners/MarkOrderDelivered.php
use Kcabor\Laravel\Events\DeliveryWebhook;

public function handle(DeliveryWebhook $event): void
{
    if ($event->type === 'delivery.delivered') {
        Order::where('delivery_id', $event->object()['id'])->update(['status' => 'delivered']);
    }
}

A quick handler without a listener class (wildcards work), for example in a service provider:

Kcabor::webhookHandler('delivery.delivered', fn ($event) => logger($event->id));
Kcabor::webhookHandler('ride.*', fn ($event) => /* ... */);

Try it locally

php artisan kcabor:webhook:test delivery.delivered             # fires the events in-process, no signature
php artisan kcabor:webhook:test delivery.delivered --post      # signs a sample and posts it to your route
php artisan kcabor:webhook:test delivery.delivered --url=https://my-app.test/kcabor/webhook

--post and --url need KCABOR_WEBHOOK_SECRET, and --post uses route('kcabor.webhook'), so set APP_URL. To receive real events locally, expose your site with a tunnel and add that URL as an endpoint.

Commands

Command
kcabor:ping Calls GET /ping and prints the environment, business and server time. Exits 1 on an API error
kcabor:webhook:test {type} [--post] [--url=] [--live] Sends a sample event, in-process or signed over HTTP

Testing

Kcabor::fake() swaps in a real SDK client whose HTTP layer is a queue of canned responses, so nothing leaves your machine.

use Kcabor\Laravel\Facades\Kcabor;
use Kcabor\Laravel\Testing\KcaborFake;

$fake = Kcabor::fake([
    ['id' => 'dq_1', 'total' => 250000],                 // 200, becomes {"data": {...}}
    ['id' => 'dlv_1', 'status' => 'pending'],
    KcaborFake::response(['error' => ['type' => 'invalid_request_error', 'code' => 'quote_expired', 'message' => 'Expired']], 400),
]);

// ... run your code ...

$fake->assertSentCount(2);
$fake->assertSent(fn ($request) => $request->getMethod() === 'POST'
    && str_ends_with($request->getUri()->getPath(), '/deliveries')
    && KcaborFake::json($request)['reference'] === 'ORDER-1001');
$fake->assertNotSent(fn ($request) => $request->getMethod() === 'DELETE');
$fake->assertNothingSent();

Responses are used in order. An array becomes a 200 with that array as data, a Guzzle response is used as is (KcaborFake::response($body, $status) builds one), and a throwable is thrown. Once the queue is empty, calls get an empty 200. Requests are PSR-7 requests; recorded() returns them all. The fake client has no retries, so a queued 500 is thrown straight away.

To test webhook code, post a signed body to the route:

$body = json_encode($event);
$this->call('POST', '/kcabor/webhook', [], [], [], [
    'HTTP_KCABOR_SIGNATURE' => \Kcabor\Webhook::header($body, config('kcabor.webhook.secret')),
    'CONTENT_TYPE' => 'application/json',
], $body)->assertOk();

Development

composer install
vendor/bin/phpunit   # Orchestra Testbench, no network calls

See CONTRIBUTING.md for running the tests before kcabor/kcabor-php is on Packagist.

MIT licensed.