

function CreateRechargeRequest() {
    var Amount = $("#Amount").val();
    var UTRNumber = $("#UTRNumber").val();    
    if ((Amount == '0') || (Amount == "")) {
        MyAlert("Error", "Please Enter Amount", "error");
        return;
    }
    if (parseFloat(Amount) < 0) {
        MyAlert("Error", "Please Enter Amount Greater Than Zero", "error");
        return;
    }
    if ((UTRNumber.trim() == "")) {
        MyAlert("Error", "Please Enter UTR Number", "error");
        return;
    }

    $("#NEFTForm").submit();
}
function InsertAmount(Amt) {
    $("#SAmount").val(Amt).trigger("input");

     $("#StripeValue").val(Amt);
}
function GetTotal(fee) {
    debugger
    var amount = 0;
    if ($("#SAmount").val() != 0) {
        amount = $("#SAmount").val();
        var tax = (fee / 100) * amount;
        var total = parseFloat(tax) + parseFloat(amount);
        $("#Tax").val(tax);
        $("#RAmount").val(total);
        $("#StripeValue").val(amount);
    } else {
        $("#Tax").val(0);
        $("#RAmount").val(0);
        $("#StripeValue").val(0);
    }
}
function DisplayNEFTModal() {
    $.ajax({
        url: "/Billing/AccountDetails",
        method: "GET",
        success: function (response) {
            if (response.success) {
                debugger

                document.getElementById("Bank").innerHTML = response.response.BankName;
                document.getElementById("AccName").innerHTML = response.response.AccountName;
                document.getElementById("AccNo").innerHTML = response.response.AccountNumber;
                document.getElementById("SortCode").innerHTML = response.response.SortCode;
            }
        },
        error: function (err) {
            console.alert(err);
        }
    });
    $("#RechargeModal").modal("hide");
    $("#NeftModal").modal("show");

}
function GetTotalForNEFT(commission) {
    debugger
    var amount = 0;
    if ($.isNumeric($("#MAmount").val())) {
        amount = $("#MAmount").val();
        var tax = (commission / 100) * amount;
        var total = parseFloat(tax) + parseFloat(amount);
        $("#Amount").val(total);
    }
    else {
        $("#Amount").val("0");
    }

}












$(document).ready(function () {
   
    var stripe= Stripe('pk_test_kODgqBU7Yt6ig4YGCRCSvvx100kHRG4oPD');
    var checkoutButton = document.getElementById('checkout-button01');
    checkoutButton.addEventListener('click', function () {
        var input = { Amount: parseInt($("#StripeValue").val()) };
        // Create a new Checkout Session using the server-side endpoint you
        // created in step 3.
        $("#checkout-button01").prop('disabled', true);
        fetch('/Billing/CreateCheckoutSession', {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(input)
        })
            .then(function (response) {
                return response.json();
            })
            .then(function (session) {
                return stripe.redirectToCheckout({ sessionId: session.id });
            })
            .then(function (result) {
                // If `redirectToCheckout` fails due to a browser or network
                // error, you should display the localized error message to your
                // customer using `error.message`.
                if (result.error) {
                    alert(result.error.message);
                }
            })
            .catch(function (error) {
                alert(error);
            });
    });  
});









