Deploy / deploy (push) Successful in 14s
- Migration: shopify_variant_id on products_sizes, shopify_order_id on products_sales - ShopifyService: paginated REST client (2024-10 API) - shopify:map — one-time command to link variants by SKU - shopify:sync — reconciliation command (Shopify is master) - VerifyShopifyWebhook middleware: HMAC-SHA256 verification - ShopifyWebhookController: idempotent orders/paid handler, FIFO inventory deduction - Webhook route: POST /api/webhooks/shopify/orders-paid Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
29 lines
643 B
PHP
29 lines
643 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class VerifyShopifyWebhook
|
|
{
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
$hmac = $request->header('X-Shopify-Hmac-Sha256');
|
|
$secret = config('services.shopify.webhook_secret');
|
|
|
|
if (!$hmac || !$secret) {
|
|
abort(401);
|
|
}
|
|
|
|
$computed = base64_encode(hash_hmac('sha256', $request->getContent(), $secret, true));
|
|
|
|
if (!hash_equals($computed, $hmac)) {
|
|
abort(401);
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|