The strip does not reject the cards in test mode

I use Stripe with Laravel 5.1, and everything works for me, except that when I enter the number of the test card to be rejected, I get no errors; i.e. resonse.errors never exists, even if necessary.

I get the token back as if everything went perfectly (example: tok_16Y3wFAMxhd2ngVpHnky8VWX)

The stripeResponseHandler () function does not return errors in the response, no matter which 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(); }); } }); 

If (response.error) never fires, even if the card should be declined. I canโ€™t understand what I am doing wrong here, which causes this problem.

I tried all test card numbers that should deviate from Stripe docs, but none of them return an error response.

Please help me. Thank you for your time.

+8
jquery laravel stripe-payments
source share
1 answer

When you use Stripe.js , Stripe will only check the correctness of the card data and not contact the bank at this point, This means that they ensure that the card number passes Luhn Check , that the expiration date is a valid date in the future and that CVC is a 3-digit (or 4-digit number for Amex).

This is so that the tok_XXX token tok_XXX created successfully, and you can send it to your server. Then the card will be declined on the server side when you add an attempt to charge it. It will also be rejected when creating the client, as Stripe will start authorization on the $ 0 or $ 1 card to make sure that it is valid and accepted by the bank.

+5
source share

All Articles