console.log("💳 Payment Page Loaded");

(function () {

  function injectAndTriggerQR() {

    console.log("🔥 Injecting into page context...");

    let script = document.createElement("script");

    script.textContent = `
      (function() {

        console.log("🚀 Inside Page Context");

        let tries = 0;

        let interval = setInterval(() => {

          tries++;

          try {

            if (typeof submitUpiQrForm === "function") {

              submitUpiQrForm();
              console.log("✅ QR Triggered SUCCESS");

              clearInterval(interval);
              return;

            }

          } catch(e) {}

          if (tries > 20) {
            console.log("❌ QR trigger failed");
            clearInterval(interval);
          }

        }, 800);

      })();
    `;

    document.documentElement.appendChild(script);

  }

  function init() {

    console.log("🚀 Payment Init");

    setTimeout(() => {
      injectAndTriggerQR();
    }, 1500);

  }

  window.addEventListener("load", init);

})();