Files
isaaccladandClaude Opus 4.8 2ced61fed0
Deploy Ladill Merchant / deploy (push) Successful in 45s
Push paid menu orders to the Ladill POS kitchen
When a menu (food) storefront order is paid, best-effort POST it to the
merchant's Ladill POS kitchen ingest (config/kitchen.php → KITCHEN_API_URL/KEY)
so it lands on their Kitchen Display alongside dine-in tabs. Failures are logged,
never surfaced — order completion is unaffected; POS ignores orders for accounts
that don't run a POS kitchen.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 23:57:30 +00:00

60 lines
1.9 KiB
PHP

<?php
namespace App\Services\Merchant;
use App\Models\QrCode;
use App\Models\QrSaleOrder;
use Illuminate\Support\Facades\Http;
/**
* Pushes a paid menu (food) storefront order to the merchant's Ladill POS
* Kitchen Display. Best-effort: failures are logged, never surfaced — they must
* not break order completion. POS ignores orders for accounts not running a POS
* kitchen, so this is safe to call for every menu order.
*/
class KitchenPusher
{
public function push(QrSaleOrder $order): void
{
$url = (string) config('kitchen.url');
$key = (string) config('kitchen.key');
if ($url === '' || $key === '') {
return;
}
$order->loadMissing('qrCode', 'merchant');
// Only food menus feed a kitchen.
if (($order->qrCode?->type) !== QrCode::TYPE_MENU || ! $order->merchant) {
return;
}
$items = collect((array) $order->items)
->filter(fn ($i) => strtolower(trim((string) ($i['name'] ?? ''))) !== 'shipping')
->map(fn ($i) => [
'name' => (string) ($i['name'] ?? ''),
'quantity' => max(1, (int) ($i['qty'] ?? 1)),
'unit_price_minor' => (int) round(((float) ($i['price_ghs'] ?? 0)) * 100),
])
->filter(fn ($i) => $i['name'] !== '')
->values()
->all();
if ($items === []) {
return;
}
try {
Http::withToken($key)->acceptJson()->asJson()->timeout(8)
->post($url.'/kitchen/orders', [
'owner' => (string) $order->merchant->public_id,
'reference' => (string) ($order->payment_reference ?: ('QO-'.$order->id)),
'customer_name' => $order->customer_name,
'items' => $items,
]);
} catch (\Throwable $e) {
report($e);
}
}
}