In testing mode when I create a new customer and tries for payment, i got this error.

Customer cus_7Zz2BCnybIZLGw does not have a linked card with ID tok_17Kp8GAwLkQPB7OqrrM73VVI

Im using card number : 4242424242424242 exp_month :12 exp_year 2016

The return response is,

Array
(
    [charge_status] => 
    [error_info] => Array
        (
            [type] => invalid_request_error
            [message] => Customer cus_7Zz2BCnybIZLGw does not have a linked card with ID tok_17Kp8GAwLkQPB7OqrrM73VVI.
            [param] => card
            [code] => missing
        )

    [message] => Customer cus_7Zz2BCnybIZLGw does not have a linked card with ID tok_17Kp8GAwLkQPB7OqrrM73VVI.
)

Input Charge Data is,

 $customer = Stripe_Customer::create(array(
      'account_balance' => 100,
      'source' => $token,
      'email' => strip_tags(trim($email))
    )
  );

$customer_id = $customer->id;

$charge   = array(
                'card'          => 4242424242424242, 
                'amount'        => 100, 
                'currency'      => 'cad', 
                'receipt_email' => test@test.com,
                'description'   => 'my payment',
                'customer'      => $customer_id
              );

1 Answers 11

up vote 43 down vote accepted

There are three different ways to create a charge:

  • with the source parameter only. In this case, source needs to be a token ID (created by Checkout or Stripe.js), i.e. a string that starts with tok_.

  • with the customer parameter only. In this case, customer needs to be a customer ID, i.e. a string that starts with cus_. The customer's default card will be charged.

  • with both the customer and source parameters. In this case, customer needs to be a customer ID as in the previous case, but source should be a card ID, i.e. a string that starts with card_. The card object should belong to the customer.

In your case, you're passing a token ID in the source parameter along with a customer ID in the customer parameter.

If this is a new card, you should first use the token to create a card on the customer, then create the charge with the card ID. If the card was already saved for this customer, then you don't need to collect the card information again (and thus don't need to create a token at all).

1 upvote
  flag
Perfect! Thank you so much Ywain :) – Sree
upvote
  flag
@Ywain what about when using an Apple Pay token? It seems like it's not possible to associate Apple Pay transactions with a customer account and have them use the Price Sheet and TouchID UI each time. Either I turn the token to a card and then it behaves just like a stored card and not like Apple Pay, or I get a new token each time and there is no charge history attached to the customer account. – emkman
2 upvote
  flag
@emkman: I suppose you could use Apple Pay to create a new token each time, attach the token to the existing customer object, create the charge using the customer object then delete the card from the Apple Pay token. That way you can use Apple Pay to authenticate each transaction and still keep a charge history on the customer object. – Ywain
upvote
  flag
@Ywain. Just reading through this, and while it is helpful, it unfortunately does not explain why the error happened based on the original question (maybe I missed something obvious). – IonicBurger
upvote
  flag
@IonicBurger The OP provided a customer ID in the customer parameter and a token ID in the source parameter. When providing both the customer and source parameters, source must be a card ID. If source is a token ID, then no customer parameter should be passed. – Ywain
upvote
  flag
@Ywain - ok great, very clear, much appreciated! – IonicBurger

Not the answer you're looking for? Browse other questions tagged or ask your own question.