28
votes

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
2

2 Answers

44
votes

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}"
      )
9
votes

This answer help to ME apply the same solution in PHP for charge an specific credit card customer, other than the default credit card. Here the pieces:

JSON:

{
  "charge": {
    "amount":122,
    "currency":"usd",
    "customer":"cus_7hVsgytCc79BL7",
    "card":"card_17SENFJ4sx1xVfmD8skoSjNs"
  }
}

PHP

    $item = $params->request->getJsonRawBody();
    $new_charge = \Stripe\Charge::create(array(
      "amount" => $this->ConvertAmount($item->charge->amount),
      "currency" => $item->charge->currency,
      "customer" => $item->charge->customer,
      "card" => $item->charge->card
    ));
    return $new_charge;