WaForgeDevelopers

Data feed quickstarts

Laravel

The waforge/laravel-feed package for Laravel 10, 11 and 12 serves the manifest and the feed routes, verifies every signature, blocks replays and formats the answers. You map your models; that is all.

You need: a Laravel app on HTTPS (port 443) on the domain you add in WaForge, and the four values from Dashboard, Data feeds, Your website (feed secret, key id, tenant id, verification token). What are these?

1. Install the package #

The package is not on Packagist. Download laravel.zip and install it as a local Composer path repository:

Terminal
unzip laravel.zip                                   # creates waforge-laravel/
mkdir -p packages && mv waforge-laravel packages/waforge-laravel-feed
composer config repositories.waforge path packages/waforge-laravel-feed
composer require waforge/laravel-feed:^1.0
php artisan vendor:publish --tag=waforge-config     # creates config/waforge.php

The service provider is auto-discovered. It registers the waforge.signature middleware and the routes below.

2. Paste your values #

.env
WAFORGE_FEED_SECRET=wf_fs_...        # secret: never commit it
WAFORGE_KEY_ID=fs_...
WAFORGE_TENANT=wf_tn_...
WAFORGE_VERIFY=wfv_...
WAFORGE_CURRENCY=QAR                 # ISO 4217 code of your prices
# Optional:
# WAFORGE_FEED_SECRET_PREVIOUS=wf_fs_...   # accept the old secret too while you rotate
# WAFORGE_BASE_URL=https://shop.example.com/waforge   # only behind a proxy that changes the public URL
Terminal
php artisan config:clear

3. The routes you now have #

RouteSigned?Answers
GET /.well-known/waforge.json and GET /waforge/manifestNo (public, no secrets)The manifest: tenant, verification token, base URL, capabilities
GET /waforge/catalog/search?q=&limit=&cursor=YesProducts matching name or SKU, ttl 300
GET /waforge/products/{id}YesOne product, ttl 60, or 404
GET /waforge/products/by-sku/{sku}YesOne product by SKU, or 404
POST /waforge/availabilityYesStock for 1 to 50 items, ttl 30
POST /waforge/orders/lookupYesOrder status if the phone matches, else 404, ttl 0

The routes do not use the web middleware group: no session, no cookies, no CSRF, and the raw body stays intact for the signature. Change the /waforge prefix with 'prefix' in config/waforge.php; set 'orders_enabled' => false to stop offering order lookups.

4. Map your data #

Option A: the Eloquent handler (no code)

Edit the eloquent section of config/waforge.php with your model classes and column names:

config/waforge.php
'business' => [
    'name' => env('APP_NAME', 'My Shop'),
    'currency' => env('WAFORGE_CURRENCY', 'QAR'),
    'prices_include_tax' => true,
    'default_locale' => 'en',
    'locales' => ['en', 'ar'],
    'timezone' => env('APP_TIMEZONE', 'UTC'),
],

'handler' => WaForge\Feed\Handlers\EloquentFeedHandler::class,

'eloquent' => [
    'products' => [
        'model' => App\Models\Product::class,
        'url' => 'https://shop.example.com/products/{id}',
        'columns' => ['id' => 'id', 'sku' => 'sku', 'name' => 'name', 'price' => 'price',
                      'stock' => 'stock', 'description' => 'description', 'image' => 'image_url'],
    ],
    'orders' => [ // null disables order lookups
        'model' => App\Models\Order::class,
        'columns' => ['number' => 'number', 'phone' => 'phone', 'status' => 'status', 'placed_at' => 'created_at'],
    ],
],

'low_stock' => 3, // at or below this quantity, status is "low_stock"
'status_map' => [ // your order status => WaForge status
    'pending' => 'pending', 'paid' => 'confirmed', 'processing' => 'processing', 'shipped' => 'shipped',
    'delivered' => 'delivered', 'completed' => 'delivered', 'cancelled' => 'cancelled', 'refunded' => 'refunded',
],

Prices are sent as decimal strings with 2 decimals ("249.00"). Order lookups compare the last 9 digits of the phone on the order with the customer's WhatsApp number and answer the same 404 when the order is unknown or the phone differs.

Option B: your own handler (any data source)

Implement WaForge\Feed\Contracts\FeedHandler when your data is not one Eloquent model per table, or comes from an ERP or another API. Then set 'handler' => App\Feeds\ShopFeed::class in config/waforge.php.

app/Feeds/ShopFeed.php
<?php

namespace App\Feeds;

use App\Models\Order;
use App\Models\Product;
use WaForge\Feed\Contracts\FeedHandler;

class ShopFeed implements FeedHandler
{
    public function searchCatalog(string $q, int $limit, ?string $cursor): array
    {
        $rows = Product::where('is_published', true)
            ->where(fn ($w) => $w->where('name', 'like', "%{$q}%")->orWhere('sku', 'like', "%{$q}%"))
            ->orderBy('id')
            ->when($cursor, fn ($w) => $w->where('id', '>', (int) base64_decode($cursor)))
            ->limit($limit + 1)->get();

        return [
            'items' => $rows->take($limit)->map(fn (Product $p) => $this->product($p))->values()->all(),
            'next_cursor' => $rows->count() > $limit ? base64_encode((string) $rows[$limit - 1]->id) : null,
        ];
    }

    public function getProduct(string $id): ?array
    {
        $p = Product::where('is_published', true)->find($id);

        return $p ? $this->product($p) : null;
    }

    public function getProductBySku(string $sku): ?array
    {
        $p = Product::where('is_published', true)->firstWhere('sku', $sku);

        return $p ? $this->product($p) : null;
    }

    public function availability(array $items): array
    {
        return array_map(function (array $i) {
            $qty = Product::whereKey($i['product_id'])->value('stock');
            $status = $qty === null ? 'unknown' : ($qty <= 0 ? 'out_of_stock' : ($qty <= 3 ? 'low_stock' : 'in_stock'));

            return [
                'product_id' => (string) $i['product_id'],
                'variant_id' => $i['variant_id'] ?? null,
                'available' => $qty !== null && $qty >= ($i['quantity'] ?? 1),
                'quantity_available' => $qty,
                'status' => $status,
            ];
        }, $items);
    }

    public function lookupOrder(string $orderNumber, string $phoneE164): ?array
    {
        $o = Order::firstWhere('number', $orderNumber);
        $last9 = fn ($v) => substr(preg_replace('/\D/', '', (string) $v), -9);

        // Same null for "no such order" and "phone does not match": nobody can probe order numbers.
        if (! $o || strlen($last9($phoneE164)) < 9 || $last9($o->phone) !== $last9($phoneE164)) {
            return null;
        }

        return [
            'order_number' => $o->number,
            'status' => $o->status === 'paid' ? 'confirmed' : $o->status, // one of the WaForge statuses
            'status_label' => ucfirst($o->status),
            'placed_at' => $o->created_at->toIso8601String(),
        ];
    }

    private function product(Product $p): array
    {
        $price = number_format((float) $p->price, 2, '.', '');

        return [
            'id' => (string) $p->id,
            'name' => $p->name,
            'currency' => 'QAR',
            'price' => $price,
            'url' => route('products.show', $p),
            'images' => array_values(array_filter([$p->image_url])),
            'description_text' => strip_tags((string) $p->description),
            'variants' => [['id' => (string) $p->id, 'sku' => $p->sku, 'price' => $price, 'available' => $p->stock > 0]],
        ];
    }
}

How the signature middleware works #

You do not need to write this: it ships in the package as waforge.signature. It is shown so you know exactly what runs before your handler, and so you can reuse it on routes of your own.

src/Http/Middleware/VerifyWaForgeSignature.php (excerpt)
public function handle(Request $request, Closure $next)
{
    // 1. Refuse bodies over 1 MB before doing anything else.
    if ((int) $request->server('CONTENT_LENGTH', 0) > 1048576 || strlen($request->getContent()) > 1048576) {
        return self::problem(413, 'invalid_request', 'Body larger than 1 MB');
    }
    // 2. HMAC over the exact path + query and the raw body, 300 s window, current or previous secret.
    $header = (string) $request->header('WaForge-Signature', '');
    $ok = Signature::verify($header, (array) config('waforge.secrets'), $request->method(),
        $request->getRequestUri(), $request->getContent());
    // 3. Replay guard: the same t + v1 is accepted once (atomic Cache::add, 600 s).
    if ($ok) {
        $p = Signature::parse($header);
        $ok = Cache::add('waforge:seen:'.((int) $p['t']).':'.$p['v1'], 1, 600);
    }

    return $ok ? $next($request) : self::problem(401, 'unauthorized', 'Invalid, expired or replayed WaForge-Signature');
}

Use it on your own route: Route::get('/waforge/booking/slots', ...)->middleware('waforge.signature');. The replay guard needs a shared cache store (Redis, database or file) when you run several servers.

5. Test it #

First check the routes and the public manifest:

Terminal
php artisan route:list --path=waforge
curl -s https://shop.example.com/.well-known/waforge.json

Then add a feature test to your own suite. It signs a request exactly like WaForge does:

tests/Feature/WaForgeFeedTest.php (Pest)
<?php

use WaForge\Feed\Signature;

beforeEach(fn () => config(['waforge.secrets' => ['wf_fs_test_secret']]));

function waforgeGet(string $path)
{
    $header = Signature::header('wf_fs_test_secret', 'fs_test', time(), 'GET', $path, '');

    return test()->get($path, ['WaForge-Signature' => $header]);
}

it('answers a signed catalog search', function () {
    waforgeGet('/waforge/catalog/search?q=card&limit=3')
        ->assertOk()
        ->assertJsonStructure(['data' => ['items'], 'as_of', 'ttl']);
});

it('refuses an unsigned request', function () {
    $this->get('/waforge/catalog/search?q=card')->assertStatus(401);
});

Finally, in WaForge: Dashboard, Data feeds, your website, Verify domain, add test values (a search word and a real product id), then Run checks. See Testing and the feed checker.

6. Push changes (recommended) #

Tell WaForge when stock or a price changes, so its short cache is dropped and the next answer is read live:

app/Observers/ProductObserver.php
<?php

namespace App\Observers;

use App\Models\Product;
use WaForge\Feed\WaForge;

class ProductObserver
{
    public function updated(Product $p): void
    {
        if ($p->wasChanged('stock')) {
            dispatch(fn () => WaForge::sendEvent('stock.changed', ['product_id' => (string) $p->id, 'quantity_available' => $p->stock]));
        }
        if ($p->wasChanged('price')) {
            dispatch(fn () => WaForge::sendEvent('price.changed', ['product_id' => (string) $p->id, 'price' => (string) $p->price]));
        }
    }
}

WaForge::sendEvent() signs the event with your first secret and posts it to WAFORGE_EVENTS_URL (default https://waforge.online/api/v1/connect/events). It returns true on a 2xx. Register the observer in a service provider with Product::observe(ProductObserver::class).

Behind a proxy or CDN? The signature covers the path and query your app receives. If a proxy rewrites the path (adds or strips a prefix), the signature fails with 401. Keep the path unchanged, and set WAFORGE_BASE_URL to your public feed URL if the manifest shows the wrong host.