Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Kipperman's avatar

Stripe Customer cant be charged with active card

I have posted this question maybe one too many times. But I am still struggling with this error. I am working on the Stripe Checkout Series episode 2 titled Custom Checkout.

I have added the 'e' parameter and added the e.preventDefault() - just as Jeffery has as a fix to the error he received. I am still getting that same error whether I have the e.preventDefault or not.

Here is the code:

document.querySelector('button').addEventListener('click', function(e) { stripe.open({

    name: 'My Book',
    description: 'Book Description',
    zipCode: true,
    amount:4500                        
    
});

e.preventDefault();

});

Here is the error output:

Card in ApiRequestor.php line 112:

Cannot charge a customer that has no active card 1.in ApiRequestor.php line 112 2.at ApiRequestor->handleApiError('{ "error": { "message": "Cannot charge a customer that has no active card", "type": "card_error", "param": "card", "code": "missing" } } ', '402', array('Server' => 'nginx', 'Date' => 'Sat, 03 Dec 2016 19:40:02 GMT', 'Content-Type' => 'application/json', 'Content-Length' => '157', 'Connection' => 'keep-alive', 'Access-Control-Allow-Credentials' => 'true', 'Access-Control-Allow-Methods' => 'GET, POST, HEAD, OPTIONS, DELETE', 'Access-Control-Allow-Origin' => '*', 'Access-Control-Max-Age' => '300', 'Cache-Control' => 'no-cache, no-store', 'Request-Id' => 'req_9g5Xb6TP2RevCk', 'Stripe-Version' => '2016-07-06'), array('error' => array('message' => 'Cannot charge a customer that has no active card', 'type' => 'card_error', 'param' => 'card', 'code' => 'missing'))) in ApiRequestor.php line 259

I have followed episode 1 and 2 to the last detail. Every piece of code matches Jefferys. Could it be version errors? - I am running php 7 and laravel 5.3

Any reason why I am still getting that error?

0 likes
8 replies
ejdelmonico's avatar

You didn't submit the form to stripe with an active card. I believe that is what the message is stating. You should show all of the code like the submit portion and the form.

bashy's avatar

Yeah check the data that's being sent. Could be an issue with the form elements/names.

Kipperman's avatar

Problem is I have followed Jeffery's tutorial to the letter. His works. Mine doesn't. Its the exact same code.

Evermore's avatar

I am experiencing same issues, did u find a fix for this?

cklester's avatar

The problem is that the preventDefault() is NOT WORKING. It bypasses that prevention, activates the default behavior, then we get the error message... because the form doesn't pop up for us, so there's no way to enter the information on the checkout form, so it submits it. Again, the problem is that the default behavior is occurring, despite our using preventDefault().

Also: I'm using Laravel 5.4.

cklester's avatar

OK, I figured this out...

Jeffrey says to do

document.querySelector('button').addEventListener...

But, for me, 'button' wasn't good enough. It was conflicting with another 'button' on the page, maybe... So, what I did was assign an id of 'btn-stripe' to the actual button that pops up the form, changed the line to

document.querySelector('#btn-stripe').addEventListener...

and now it works fine.

DANG! That was easy. :-D

The point is, make sure the selector exists and is unique on your page.

Please or to participate in this conversation.