Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe appears to create popup window but closes it on mobile

I'm using Stripe Checkout and everything is working ok with the popup on desktop. When I view the website on mobile (specifically Chrome on vanilla Android 4.3, also tried on Opera for Android with similar result), a popup window appears to open for a brief second but then closes. I never see it and it's not in another open tab either.

I've read this documentation and my code is compliant.

Here's the JavaScript I'm using:

$(document).ready(function() {

    //The actual giving part
    $('a.payamount').click(function(e) {

        window.amountToGive = $(this).data('amount');

        // Open Stripe Checkout with further options
        stripeHandler.open({
            name: campaignName,
            description: 'Give $' + (window.amountToGive / 100) + ' to ' + campaignName,
            amount: window.amountToGive
        });
    });

    var stripeHandler = StripeCheckout.configure({
        key: 'mykeygoeshere',
        image: '/img/g.png',
        locale: 'auto',
        token: function(token) {
            //Add campaign info
            token['campaign_id'] = campaignId;
            token['amount'] = window.amountToGive;

            postStripeData(token);
        }
    });

    // Close Checkout on page navigation
    $(window).on('popstate', function() {
        stripeHandler.close();
    });
});

function postStripeData(token) {
    showLoadingModal();
    $.ajax({
        method: 'POST',
        url: postStripeDataUrl,
        data: token
    })
    .always(function(data_jqXHR, textStatus, jqXHR_errorThrown) {
        if (textStatus.indexOf('error') == -1) {
            //POST'ed ok
            console.log(data_jqXHR);
            window.location.href = data_jqXHR;
        } else {
            alert('Error while posting!');
        }
    });
}

I'm using https://checkout.stripe.com/checkout.js.

I've tried debugging this via the Chrome Developer tools, in which you can see the Android logs, and no error is showing up.

like image 951
zundi Avatar asked Nov 10 '22 03:11

zundi


1 Answers

After a good while of debugging, it seems what's missing is a e.preventDefault(); in the click function:

$('a.payamount').click(function(e) {
    e.preventDefault();
    //... rest of code
like image 118
zundi Avatar answered Nov 14 '22 23:11

zundi