Skip to content

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:

  1. verifies the Anikeen-Signature with services.anikeen_console.webhook_secret (anikeen/id's Webhook::constructEvent(), the same format as Anikeen ID's webhooks) and answers 400 when it does not match,
  2. ignores events it has already handled (by event id, remembered 3 days in the cache),
  3. dispatches Anikeen\Console\Events\WebhookReceived for every event, plus a typed event.

Events ​

Type (Webhooks\EventType)Event$event->object
order.completed (ORDER_COMPLETED)OrderCompletedOrder: checkout confirmed, provisioning started
order.failed (ORDER_FAILED)OrderFailedOrder: checkout cancelled, expired or could not be opened
product.ready (PRODUCT_READY)ProductReadyContainer (or Product): built; status is the live status (container: running) when the Console could read it, else active
product.failed (PRODUCT_FAILED)ProductFailedProduct: building one order item failed (refunded); id is null, with order_id, order_item_id, product_id, error
product.updated (PRODUCT_UPDATED)ProductUpdatedProduct: data.reason is billing_suspended, billing_resumed, rescaled or reinstalled
product.deleted (PRODUCT_DELETED)ProductDeletedProduct: deleted; data.reason contract_ended when the contract ended in Anikeen ID
team.released (TEAM_RELEASED)TeamReleasedTeam: the user removed your app in Anikeen ID; the last event for that team
webhook.test (WEBHOOK_TEST)WebhookTestnull (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 500 and 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.

Anikeen Console documentation