Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
609 views
in Technique[技术] by (71.8m points)

javascript - Stripe Payment: Getting Error as Customer cus_***** does not have a linked card with ID tok_*****

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' => [email protected],
                'description'   => 'my payment',
                'customer'      => $customer_id
              );
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are three different ways to create a charge:

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

  • 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 payment source 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 the ID of a payment source that is already attached to the customer. Payment sources can be cards (ID starts with card_), bank accounts (ID starts with ba_) or sources (ID starts with src_).

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...