<?php
// Gateway server-to-server auto-withdraw callback/webhook.
define('GAME_API_SKIP_MAINTENANCE', true);
require __DIR__ . '/../includes/db.php';
require __DIR__ . '/../includes/propay_gateway_helper.php';

$payload = $_POST;
if (empty($payload)) {
    $raw = file_get_contents('php://input');
    $json = json_decode($raw, true);
    if (is_array($json)) { $payload = $json; }
}
if (empty($payload) && !empty($_GET)) { $payload = $_GET; }

$result = propay_apply_withdraw_callback($conn, $payload);
http_response_code(intval($result['http_code'] ?? 200));
header('Content-Type: application/json; charset=utf-8');
echo json_encode(array('status' => !empty($result['success']), 'message' => $result['message'] ?? 'OK'), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
?>
