<?php
$root = dirname(__DIR__, 4);
require $root.'/vendor/autoload.php';
$app = require $root.'/bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();

use App\Models\PaymentGateway;
use App\Services\PaymentVerificationService;

$payload = '{"event":"payment.captured","payload":{"payment":{"entity":{"id":"pay_live_001","order_id":"order_live_001"}}}}';
$sig = hash_hmac('sha256', $payload, 'live-secret');

PaymentGateway::query()->updateOrCreate(
    ['code' => 'razorpay'],
    ['name' => 'Razorpay', 'is_enabled' => true, 'environment' => 'sandbox', 'config_json' => ['webhook_secret' => 'live-secret']]
);

$svc = app(PaymentVerificationService::class);
$log = $svc->verifyWebhook('razorpay', $payload, ['x-razorpay-signature' => $sig]);
echo $log->status.PHP_EOL;
