<?php
/**
 * TOPBD API — Payment Initiation & Outbid Transaction Creation
 */

header('Content-Type: application/json; charset=utf-8');
require_once __DIR__ . '/../includes/db.php';
require_once __DIR__ . '/../includes/functions.php';
require_once __DIR__ . '/../includes/ranking.php';
require_once __DIR__ . '/../includes/PaymentManager.php';

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    json_response(['success' => false, 'message' => 'Method not allowed'], 405);
}

$input = json_decode(file_get_contents('php://input'), true) ?: $_POST;

try {
    $result = PaymentManager::initializePayment($input);
    json_response($result);
} catch (Exception $e) {
    json_response(['success' => false, 'message' => $e->getMessage()], 400);
}

