<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RazorpayBridge.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="RazorpayReceiptBook" runat="server" />
            <asp:HiddenField ID="RazorpaySubMerchantId" runat="server" />
            <script src="https://checkout.razorpay.com/v1/checkout.js"></script>
            <%--<asp:Button ID="PayOnlineFeeButton" Text="Pay Online Fee" CssClass="btn fas red" runat="server"  OnClientClick="return CallButtonEvent();" />--%>
            <button id="rzp-button1" onclientclick="return 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('RazorpayReceiptBook').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
                        },
                        "notes": {
                            "submerchant_id": document.getElementById('RazorpaySubMerchantId').value
                        },
                        "callback_url": "/Pages/OnlinePayment/OnlinePaymentStatus.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() {
                    var btn = document.getElementById('rzp-button1');
                    btn.click();
                }
            </script>
        </div>
    </form>
</body>
</html>
