How to charge a particular card on a customer with Stripe.com

ajbraus picture ajbraus · Nov 27, 2013 · Viewed 11.1k times · Source

A customer object can have many cards in Stripe.com. How do you charge an existing card?

I've tried a few things, but the stripe api for some reason borks when to get an old customer token and a new card token instead of just creating a new card on that customer. So I've gone the route of retrieving all the customer's cards, then selecting one by radio button, then submitting the token of the chosen card into a charge

      charge = Stripe::Charge.create(
        :amount => "#{@subscription.price}",
        :currency => "usd",
        :card => params[:existing_card_id],
        :description => "Subscription for #{current_user.email}"
      )

but I get the error

Stripe::InvalidRequestError: Invalid token id: card_24j3i2390s9df

Answer

ajbraus picture ajbraus · Nov 27, 2013

I figured this out.

With existing card tokens you have to send in the customer token as well

     charge = Stripe::Charge.create(
        :amount => "#{@subscription.price}",
        :currency => "usd",
        :customer => current_user.stripe_customer_id,
        :card => params[:existing_card_id],
        :description => "Subscription for #{current_user.email}"
      )