<?php
declare(strict_types=1);
require_once __DIR__ . '/../app/bootstrap.php';
use App\Core\PaymentGateway;
$gateway = 'wallet';
$orderId = (int)($_GET['order_id'] ?? 0);
try {
    if (in_array($gateway, ['cod','wallet'], true)) {
        PaymentGateway::orderForPayment($orderId);
        header('Location: ' . url('public/thank-you.php?order_id=' . $orderId));
        exit;
    }
    $result = PaymentGateway::initiate($orderId, $gateway);
    header('Location: ' . $result['redirect_url']);
    exit;
} catch (Throwable $e) {
    set_flash('error', $e->getMessage());
    header('Location: ' . url('public/thank-you.php?order_id=' . $orderId));
    exit;
}
