<?php
// demo_payment.php - Demo payment that simulates PhonePe flow
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');

if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { 
    http_response_code(200); 
    exit(); 
}

// Mock successful payment response
$input = json_decode(file_get_contents('php://input'), true);

if (!$input) {
    echo json_encode(['success' => false, 'message' => 'Invalid JSON']);
    exit;
}

$amount = isset($input['amount']) ? $input['amount'] : 100;

// Return a demo payment page URL
echo json_encode([
    'success' => true,
    'paymentUrl' => 'https://astro.siddharthnahar.in/astro_admin/api/demo_payment_page.php?amount=' . $amount,
    'message' => 'Demo payment URL generated successfully',
    'amount' => $amount,
    'transactionId' => 'TXN_' . time(),
    'debug' => [
        'input' => $input,
        'timestamp' => time(),
        'status' => 'READY_FOR_PAYMENT'
    ]
]);
?>
