<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Razorpay.aspx.cs" Inherits="Integration_Integration_Razorpay" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
            <asp:HiddenField ID="RazorpayKeyId" runat="server" />
            <asp:HiddenField ID="Razorpayamount" runat="server" visible="true"/>
            <asp:HiddenField ID="Razorpayname" runat="server" />
            <asp:HiddenField ID="Razorpayemail" runat="server" />
            <asp:HiddenField ID="Razorpaycontact" runat="server" />
            <asp:HiddenField ID="Razorpayorderid" runat="server" />
            <asp:HiddenField ID="RazorpayCollectionGroup" runat="server" />
     <script src="https://checkout.razorpay.com/v1/checkout.js"></script> 
   <button id="rzp-button1" onclick="CallButtonEvent();">Pay</button>
<script>

    var Razorpayorderid = document.getElementById('Razorpayorderid').value
    if (Razorpayorderid != null) {
        var options = {
            "key": document.getElementById('RazorpayKeyId').value, // Enter the Key ID generated from the Dashboard
            "amount": document.getElementById('Razorpayamount').value, // Amount is in currency subunits. Default currency is INR. Hence, 50000 refers to 50000 paise
            "currency": "INR",
            "name": document.getElementById('Razorpayname').value,
            "description": document.getElementById('RazorpayCollectionGroup').value,
            "image": "https://razorpay.com/favicon.png",
            "email": document.getElementById('Razorpayemail').value,
            "contact": document.getElementById('Razorpaycontact').value,
            "order_id": document.getElementById('Razorpayorderid').value,
            "prefill": {
                "name": document.getElementById('Razorpayname').value,
                "email": document.getElementById('Razorpayemail').value,
                "contact": document.getElementById('Razorpaycontact').value
            },
            "callback_url": "/Pages/OnlinePayment/PaymentStatus.aspx",

        };
    }
    var rzp1 = new Razorpay(options);
    rzp1.on('payment.failed', function (response) {
        alert(response.error.code);
        alert(response.error.description);
        alert(response.error.source);
        alert(response.error.step);
        alert(response.error.reason);
        alert(response.error.metadata.order_id);
        alert(response.error.metadata.payment_id);
    });
    document.getElementById('rzp-button1').onclick = function (e) {
        rzp1.open();
        e.preventDefault();
    }

</script>
<script type="text/javascript">
    function CallButtonEvent() {
      
        debugger;
        var btn = document.getElementById('rzp-button1');
        btn.click();
             
    }
    </script>

    </div>
    </form>
</body>
</html>
