<?php
header('Content-Type: application/json');

// Simple mock payment that always works
$in = json_decode(file_get_contents('php://input'), true) ?: [];
$amountRupees = (float)($in['amount'] ?? 0);
$mobile = trim((string)($in['mobile'] ?? ''));
$userId = trim((string)($in['userId'] ?? 'guest'));

if ($amountRupees <= 0) {
    http_response_code(400);
    echo json_encode(['ok'=>false,'message'=>'amount required']);
    exit;
}

$merchantTxnId = 'TXN' . (string)round(microtime(true) * 1000);
$amountPaise = (int)round($amountRupees * 100);

// Return a working PhonePe test URL (correct format)
$paymentUrl = 'https://mercury-t2.phonepe.com/transact/mercuryTxn/mercuryTxn?merchantId=PGTESTPAYUAT&merchantTransactionId=' . $merchantTxnId . '&amount=' . $amountPaise . '&redirectUrl=https://astro.siddharthnahar.in/astro_admin/api/callback.php';

echo json_encode([
    'ok' => true,
    'merchantTransactionId' => $merchantTxnId,
    'amount' => $amountPaise,
    'intentUrl' => $paymentUrl,
    'redirectUrl' => $paymentUrl,
]);
?>
