Stripe and JS/JSON Error issue

<script>
var handler = StripeCheckout.configure({
    key: '<?php echo STRIPE_PUBLISHABLE_KEY; ?>',
    image: 'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTRLcbELWiURbTD4wHZoO9AWc3VC5MlnjStBxu-MfPzrSUUJ0LG',
    locale: 'auto',
    token: function(token) {
        // You can access the token ID with `token.id`.
        // Get the token ID to your server-side code for use.

        $('#paymentDetails').hide();
        $('#payProcess').val(1);
        $.ajax({
            url: 'stripe_charge.php',
            type: 'POST',
            data: {stripeToken: token.id, stripeEmail: token.email},
            dataType: "json",
            beforeSend: function(){
                $('body').prepend('<div class="overlay"></div>');
                $('#payButton').prop('disabled', true);
                $('#payButton').html('Please wait...');
            },
            success: function(data){
                $('.overlay').remove();
                $('#payProcess').val(0);
                if(data.status == 1){
                    var paidAmount = (data.txnData.amount/100);
                    $('#buynow').hide();
                    $('#txnEmail').html(token.email);
                    $('#orderID').html(data.txnData.id);
                    $('#txnID').html(data.txnData.balance_transaction);
                    $('#pamount').html(paidAmount+' '+data.txnData.currency);
                    $('#paymentDetails').show();
                }else{
                    $('#payButton').prop('disabled', false);
                    $('#payButton').html('Buy Now');
                    alert('Some problem occurred, please try again.');
                }
            },
            error: function() {
                $('#payProcess').val(0);
                $('#payButton').prop('disabled', false);
                $('#payButton').html('Buy Now');
                alert('Some problem occurred, please try again.');
            }
        });
    }
});

var stripe_closed = function(){
    var processing = $('#payProcess').val();
    if (processing == 0){
        $('#payButton').prop('disabled', false);
        $('#payButton').html('Buy Now');
    }
};

var eventTggr = document.getElementById('payButton');
if(eventTggr){
    eventTggr.addEventListener('click', function(e) {
        $('#payButton').prop('disabled', true);
        $('#payButton').html('Please wait...');

        // Open Checkout with further options:
        handler.open({
            name: 'New Ileana',
            description: '<?php echo $productName; ?>',
            amount: '<?php echo $stripeAmount; ?>',
            currency: '<?php echo $currency; ?>',
            closed:	stripe_closed
        });
        e.preventDefault();
    });
}

// Close Checkout on page navigation:
window.addEventListener('popstate', function() {
    handler.close();
});
</script>

The live test script is here.

Despite in the stripe dashboards log things are showing as OK, but still error is shown on the front end.

whole code is here and can be downloaded

Even if I delete this stripe_charge.php still everything remains the same. what deos that mean? the file is not getting called?
url: 'stripe_charge.php',

Error β†’

Some problem occurred, please try again.

error: function() {
                $('#payProcess').val(0);
                $('#payButton').prop('disabled', false);
                $('#payButton').html('Buy Now');
                alert('Some problem occurred, please try again.');
            }

What is the error that you are concerned about?

1 Like

Try filling with sample credit card:

4242 4242 4242 4242


also in DB not getting saved.

This code is executing:

error: function() {
                $('#payProcess').val(0);
                $('#payButton').prop('disabled', false);
                $('#payButton').html('Buy Now');
                alert('Some problem occurred, please try again.');
            }

This is also a concern and may be cause for everything,.

As it’s a problem with Stripe, I recommend that you contact their support services.
https://support.stripe.com/

1 Like

sir, I think my code has some missing dot.