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.
jquery laravel stripe-payments
Caleb jacobo
source share