<!-- views/payment.ejs -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link
      rel="icon"
      type="image/x-icon"
      href="<%- baseUrl %>/images/favicon.png"
    />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Razorpay Payment Gateway</title>
  </head>
  <body>
    <button id="payButton" style="display: none">Pay with Razorpay</button>
    <h1 align="center">Loading.....</h1>

    <script src="https://checkout.razorpay.com/v1/checkout.js"></script>
    <script>
      var orderId = `<%- orderId %>`;

      var options = {
        key: "<%- RAZOR_PAY_KEY_ID %>",
        amount: 50000,
        currency: "INR",
        name: "Homguru",
        description: "<%- description %>",
        image: "<%- baseUrl %>/images/logo.jpg",
        order_id: orderId,
        handler: function (response) {
          console.log(response);
          //   alert(response.razorpay_payment_id);
          //   alert(response.razorpay_order_id);
          //   alert(response.razorpay_signature);
          window.location.href =
            "/razorpay/success/" +
            response.razorpay_payment_id +
            "?callbackURL=<%- callbackURL %>";
        },
        prefill: {
          name: "<%- user?.firstName %>" + " " + "<%- user?.lastName %>",
          email: "<%- user?.email %>",
        },
        theme: {
          color: "#F37254",
        },
        modal: {
          ondismiss: function () {
            console.log("Payment modal dismissed");
            window.location.href =
              "/razorpay/cancel?callbackURL=<%- callbackURL %>";
          },
          oncancel: function () {
            console.log("Payment cancelled");
            window.location.href =
              "/razorpay/cancel?callbackURL=<%- callbackURL %>";
          },
        },
      };
      console.log(options, "=-=-");

      document.getElementById("payButton").onclick = function () {
        var rzp = new Razorpay(options);
        rzp.open();
      };
      document.getElementById("payButton").click();
    </script>
  </body>
</html>
