<script>

    var obj = {};

    $('#upay_payment').on('click', function() {

        obj.cus_name = $('#customer_name').val();
        obj.cus_phone = $('#mobile').val();
        obj.cus_email = $('#email').val() == '' ? 'demo@example.com' : $('#email').val();
        obj.cus_addr1 = $('#address').val();
        obj.amount = $('#amount').val();
        obj.customer_id = $('#customer_id').val();

        console.log('comes here');

        if ($('#mobile').val() != '' && $('#amount').val() != '' && $('#amount').val() != '') {
            $.ajax({
                url: "{{ route('upay-payment-token') }}",
                type: 'GET',
                data: obj,
                success: function(result) {
                    if(result.status == 'error'){
                        toastr.error(result.message);
                    }else{
                        $(location).attr('href', result.message);
                    }
                    console.log(result);
                },
                error: function(err) {
                    toastr.error(err.message);
                }
            });

        } else {
            if($('#mobile').val() == ''){
                toastr.error('Mobile Number is required');
            }
            if($('#amount').val() == ''){
                toastr.error('Amount is required');
            }

        }


    });

</script>
