<?php
require_once __DIR__ . '/../../config/database.php';
require_once __DIR__ . '/../../config/constants.php';
require_once __DIR__ . '/../../includes/functions.php';
require_once __DIR__ . '/../../includes/auth_user.php';

apply_cors();
$authUser = require_user();

if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
    send_error('Method not allowed.', 405);
}

$pdo = getDbConnection();
$stmt = $pdo->prepare(
    'SELECT id, plan_name, amount, gateway, order_id, status, utr_number, created_at
     FROM payment_transactions WHERE user_email = :email ORDER BY created_at DESC'
);
$stmt->execute([':email' => $authUser['email']]);

send_success(['transactions' => $stmt->fetchAll()]);
