C. Skjerdal
C. Skjerdal

Reputation: 3099

Stripe Cannot charge a customer that has no active card

I am unable to charge a Stripe customer. While this question has been asked a dozen times in the past, none of their mistakes match my problem.

I am calling this function in node.js as a firebase function

const charge = await stripe.charges.create({
      
        customer : customerId,
        amount : amount,
        currency : currency
    });

Request POST Body

{
  "customer": "cus_JL4hVfDnym2SIk",
  "amount": "500",
  "currency": "usd"
}

I have confirmed all of the values are correct on the Stripe Dashboard. As well I have the Test Card stored on the customer and it is definetly set to default, which I have confirmed on the dashboard as well. I store the card information at a much different step, unlike the other posts handle this all at once.

I would like to just charge the customer who has a stored card on their account. Everything is on test data, test card, etc. Is this an issue using charges api? Or does the test card not work here for some reason?

Error Response Body

{
  "error": {
    "code": "missing",
    "doc_url": "https://stripe.com/docs/error-codes/missing",
    "message": "Cannot charge a customer that has no active card",
    "param": "card",
    "type": "card_error"
  }
}

Upvotes: 0

Views: 545

Answers (1)

Nolan H
Nolan H

Reputation: 7419

Cards added in the Dashboard now use the newer Payment Methods API. The pattern you're using depends on the customer having a default_source (API ref) using the legacy Sources API.

You could attach the test card as a source, but instead I'd suggest changing your integration to use Payment Intents.

If you already have the basic test card added on the customer, you need to provide its id as the payment_method:

const paymentIntent = await stripe.paymentIntents.create({
  amount: 2000,
  currency: 'usd',
  payment_method_types: ['card'],
  payment_method: 'pm_123', // put your ID here
  confirm: true,
});

While this will work for the 4242 test card, the recommended approach is to follow this guide to integrate with Stripe.js and Elements for client-side confirmation that supports Strong Customer Authentication.

Upvotes: 2

Related Questions