Appearance
Webhooks
The Console tells your app when an order went through and a product is ready. Webhook endpoints are set up by Anikeen on request (URL, event types); you get the signing secret whsec_… - put it into ANIKEEN_CONSOLE_WEBHOOK_SECRET (see Configuration).
The route
php
// routes/web.php or routes/api.php
Route::anikeenConsoleWebhooks('webhooks/anikeen-console');No CSRF exclusion needed - the macro removes the CSRF middleware for this route. The route:
- verifies the
Anikeen-Signaturewithservices.anikeen_console.webhook_secret(anikeen/id'sWebhook::constructEvent(), the same format as Anikeen ID's webhooks) and answers400when it does not match, - ignores events it has already handled (by event id, remembered 3 days in the cache),
- dispatches
Anikeen\Console\Events\WebhookReceivedfor every event, plus a typed event.
Events
Type (Webhooks\EventType) | Event | $event->object |
|---|---|---|
order.completed (ORDER_COMPLETED) | OrderCompleted | Order: checkout confirmed, provisioning started |
order.failed (ORDER_FAILED) | OrderFailed | Order: checkout cancelled, expired or could not be opened |
product.ready (PRODUCT_READY) | ProductReady | Container (or Product): built; status is the live status (container: running) when the Console could read it, else active |
product.failed (PRODUCT_FAILED) | ProductFailed | Product: building one order item failed (refunded); id is null, with order_id, order_item_id, product_id, error |
product.updated (PRODUCT_UPDATED) | ProductUpdated | Product: data.reason is billing_suspended, billing_resumed, rescaled or reinstalled |
product.deleted (PRODUCT_DELETED) | ProductDeleted | Product: deleted; data.reason contract_ended when the contract ended in Anikeen ID |
team.released (TEAM_RELEASED) | TeamReleased | Team: the user removed your app in Anikeen ID; the last event for that team |
webhook.test (WEBHOOK_TEST) | WebhookTest | null (see $event->data) |
Every event has id, type, created, data (the whole data as an array) and object. Event classes live in Anikeen\Console\Events.
Listening
php
use Anikeen\Console\Events\ProductReady;
use Illuminate\Support\Facades\Event;
Event::listen(function (ProductReady $event) {
$server = GameServer::where('console_id', $event->object->id)->first();
$server?->markReady($event->object->status);
});- Listeners may be queued.
- If a listener throws, the endpoint answers
500and forgets the event id, so the Console's retry gets through.
Acting on webhook objects
Resources from webhooks have no API client; bind one to act on them:
php
use Anikeen\Console\Events\ProductReady;
use Anikeen\Console\Facades\AnikeenConsole;
Event::listen(function (ProductReady $event) {
$user = User::whereHas('gameServers', fn ($q) => $q->where('console_id', $event->object->id))->first();
$event->object->withClient(AnikeenConsole::forUser($user))->power('start');
});Format, retries and delivery rules: Webhooks for apps.