<script>
    let surjobutton = document.getElementById("surjo_payment");
    surjobutton.addEventListener("click",function(){
        createToken();
    });

    function createToken(){
        var amount = parseFloat($('#amount').val() || 0);
        if (isNaN(amount) || amount <= 0) {
            if (typeof toastr !== 'undefined') {
                toastr.error('Payment amount must be greater than 0');
            }
            return;
        }

       $.ajax({
                url: '{{ route('surjo-execute-payment') }}',
                type: 'GET',
                contentType: 'application/json',
                data: {
                    amount: $('#amount').val(),
                    // for client-payment/{token} page, pass customer id and slug explicitly
                    customerid: $('#customer_id').val(),
                    slug: $('#client_slug').val()
                },
                success: function(data) {
                    // console.log(data);
                    $(location).attr('href', data);
                },
                error: function(err) {

                }
            });
    }


</script>
