Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe is not declining any cards in test mode

I'm using Stripe with Laravel 5.1 and I have everything working except that when I enter a test card number that should be declined, I receive no errors; that is, resonse.errors never exists, even when it should.

I am receiving a token back as if everything went through just fine (example: tok_16Y3wFAMxhd2ngVpHnky8VWX)

The stripeResponseHandler() function is not returning errors in the response no matter what test card I use. Here is the code in question:

var PublishableKey = 'pk_test_Ed0bCarBWsgCXGBtjEnFeBVJ'; // Replace with your API publishable key
Stripe.setPublishableKey(PublishableKey);

/* Create token */
var expiry = $form.find('[name=cardExpiry]').payment('cardExpiryVal');
var ccData = {
    number: $form.find('[name=cardNumber]').val().replace(/\s/g, ''),
    cvc: $form.find('[name=cardCVC]').val(),
    exp_month: expiry.month,
    exp_year: expiry.year
};

Stripe.card.createToken(ccData, function stripeResponseHandler(status, response) {
    console.log(status);
    if (response.error) {
        /* Visual feedback */
        $form.find('[type=submit]').html('Please Try Again');
        /* Show Stripe errors on the form */
        $form.find('.payment-errors').text(response.error.message);
        $form.find('.payment-errors').closest('.row').show();
    } else {
        /* Visual feedback */
        $form.find('[type=submit]').html('Processing <i class="fa fa-spinner fa-pulse"></i>');
        /* Hide Stripe errors on the form */
        $form.find('.payment-errors').closest('.row').hide();
        $form.find('.payment-errors').text("");
        // response contains id and card, which contains additional card details
        console.log(response.id);
        console.log(response.card);
        var token = response.id;
        var email = $form.find('[name=email]').val();
        var formToken = $form.find('[name=_token]').val();
        console.log(email);
        // AJAX - you would send 'token' to your server here.
        console.log(token);
        $.post('/testing', {
            _token: formToken,
            token: token,
            email: email
        }, function (data) {
            console.log(data);
        })
            // Assign handlers immediately after making the request,
            .done(function (data, textStatus, jqXHR) {
                //console.log(data);
                $form.find('[type=submit]').html('Subscription Successful <i class="fa fa-check"></i>').prop('disabled', true);
            })
            .fail(function (jqXHR, textStatus, errorThrown) {
                $form.find('[type=submit]').html('There was a problem').removeClass('success').addClass('error');
                /* Show Stripe errors on the form */
                $form.find('.payment-errors').text('Try refreshing the page and trying again.');
                $form.find('.payment-errors').closest('.row').show();
            });
    }
});

The if (response.error) never fires, even though the card should be declined. I can't understand what I'm doing wrong here that is causing this issue.

I've tried all the test card numbers that should decline from the Stripe docs, but none of them return a response with errors.

Please help me out. Thank you for your time.

like image 521
Caleb Jacobo Avatar asked Aug 10 '15 00:08

Caleb Jacobo


People also ask

Does Stripe charge in test mode?

Give us a try, completely free. We built our unique Test Mode to ensure there's absolutely no cost to trying Collect for Stripe and ensuring it behaves just as you expect before you spend a dime. Stripe does not refund fees when you refund real, non-test charges.

Why is my card being declined when I have money on it Stripe?

Card issuer declines arising from incorrect card information (for example, incorrect card number or expiration date) are best handled by guiding your customer to correct the error or even using another card or payment method.

How do I enable test mode for payment in Stripe?

To begin, you'll need to log in to your Stripe account. Then click on Payments in the menu at the top of the screen. Next, near the top right corner of the screen, toggle on the Test Mode option. This will show you an overview of the test payments you've received in your Stripe account.

How does Stripe test mode work?

Testing paymentsYou can issue cards and simulate purchases using your own Stripe integration in test mode. This allows you to test your integration before you go live without having to make real purchases. You can only use these cards for testing within your Stripe account and not for external purchases.


1 Answers

When you use Stripe.js, Stripe will only verify that the card details look correct and they don't contact the bank at that point. This means that they ensure the card number passes the Luhn Check, that the expiration date is a valid date in the future and that the CVC is a 3-digits (or 4-digits for Amex) number.

It that's the case, the token tok_XXX is created successfully and you can send it to your server. The card would then be declined server-side when you add try to charge it. It would also be declined when you create a customer as Stripe will run a $0 or $1 authorization on the card to make sure it's valid and accepted by the bank.

like image 181
koopajah Avatar answered Dec 24 '22 15:12

koopajah