<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>LG-Pay Gateway Test</title>
  <style>
    body { font-family: Arial, sans-serif; padding: 20px; max-width: 600px; margin: auto; }
    input, select { padding: 10px; margin: 5px 0; width: 100%; }
    button { padding: 10px 20px; }
    .response { margin-top: 20px; padding: 10px; border: 1px solid #ddd; background: #f9f9f9; }
  </style>
</head>
<body>

  <h2>LG-Pay Gateway Test</h2>

  <form id="payin-form">
    <label>Merchant Key</label>
    <input type="text" name="merchant_key" value="abc123xyz" required>

    <label>Amount</label>
    <input type="number" name="amount" value="100" required>

    <label>Currency</label>
    <select name="currency">
      <option value="USDT">USDT</option>
      <option value="INR">INR</option>
      <option value="pkr">PKR</option>
      <option value="ETH">ETH</option>
    </select>

    <label>Transaction ID</label>
    <input type="text" name="txn_id" value="txn_test_001" required>

    <button type="submit">Submit Pay-in</button>
  </form>

  <div class="response" id="response-box" style="display:none;"></div>

  <script>
    document.getElementById('payin-form').addEventListener('submit', async function(e) {
      e.preventDefault();

      const form = e.target;
      const formData = new URLSearchParams(new FormData(form));
      const responseBox = document.getElementById('response-box');
      responseBox.style.display = 'none';
      responseBox.innerHTML = '';

      try {
        const res = await fetch('https://fastpay.rdnslvhost.in.net/api/payin.php', {
          method: 'POST',
          headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
          body: formData
        });

        const result = await res.json();
        responseBox.style.display = 'block';
        responseBox.innerHTML = '<pre>' + JSON.stringify(result, null, 2) + '</pre>';

        if (result.status === 'redirect' && result.payment_url) {
          setTimeout(() => {
            window.location.href = result.payment_url;
          }, 2000);
        }
      } catch (error) {
        responseBox.style.display = 'block';
        responseBox.innerHTML = '<strong>Error:</strong> ' + error.message;
      }
    });
  </script>

</body>
</html>
