<?php

require __DIR__.'/vendor/autoload.php';

$app = require_once __DIR__.'/bootstrap/app.php';
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();

use App\Models\PaymentGateway;

echo "=== Checking Stripe Webhook Configuration ===\n\n";

$gateway = PaymentGateway::where('provider', 'stripe')->first();

if (!$gateway) {
    echo "❌ No Stripe gateway found in database\n";
    exit(1);
}

echo "Gateway Configuration:\n";
echo "  Provider: {$gateway->provider}\n";
echo "  Is Live Mode: " . ($gateway->is_live_mode ? 'Yes' : 'No') . "\n";
echo "  Is Active: " . ($gateway->is_active ? 'Yes' : 'No') . "\n";
echo "\n";

echo "Webhook Secret:\n";
echo "  Test Webhook Secret: " . ($gateway->test_webhook_secret ? '✓ Set' : '❌ NOT SET') . "\n";
if ($gateway->test_webhook_secret) {
    echo "  Value: {$gateway->test_webhook_secret}\n";
}
echo "  Live Webhook Secret: " . ($gateway->live_webhook_secret ? '✓ Set' : '❌ NOT SET') . "\n";
echo "\n";

echo "Current Mode Webhook Secret:\n";
if ($gateway->is_live_mode) {
    echo "  Using: Live Webhook Secret\n";
    echo "  Value: " . ($gateway->live_webhook_secret ?? 'NOT SET') . "\n";
} else {
    echo "  Using: Test Webhook Secret\n";
    echo "  Value: " . ($gateway->test_webhook_secret ?? 'NOT SET') . "\n";
}
echo "\n";

echo "Environment Variable:\n";
$envSecret = env('STRIPE_WEBHOOK_SECRET');
echo "  STRIPE_WEBHOOK_SECRET: " . ($envSecret ? $envSecret : 'NOT SET') . "\n";
