14

Using Stripe.js, I get a card token that I can then use to charge via:

Stripe::Charge.create(
  :amount => 400,
  :currency => "usd",
  :card => "tok_103rC02eZvKYlo2C2RD5docg", # obtained with Stripe.js,
  :metadata => {'order_id' => '6735'}
)

Can I use the same card token multiple times to charge the customer or is it 1 token/charge and any subsequent charge, I will have to grab a new token?

2 Answers 2

35

Good question! When you use the token in that manner, it's immediately consumed, so it can't be used again. However, you can instead provide that token as the card argument when creating a Customer object in Stripe. Then you can perform multiple charges against that Customer.

Hope that helps. Larry

PS I work on Support at Stripe.

1
  • How come in the official documentation it says the token WILL EXPIRE? It makes no sense what you're saying. Basically you're saying if i create a Customer, then create Card, then get card token, then add to Customer (updateCustomer), then FOREVER I can charge this user by just using Customer ID? I don't believe that's how the documentation says it works. No company does it. It's like blank-check forever.
    – Alan Cruz
    Aug 24, 2021 at 15:43
3

There are two thing. One is token and one is card id. Token can be used one time. Also it has some time limit to use. Card id we get after save the card to cloud. We can use card id multiple time. Token gets generate through Public key. and this can not be use again. So You can use card id for payment multiple time

require_once APPPATH . 'libraries/Stripe.php';
Stripe::setApiKey("***********************"); //Put here your secrect key

//Add card and get token id.

$tokenDetail = Stripe_Token::create(array(
"currency" => "USD",
"card" => array(
"number" => '********', //$credit_card_number,
"exp_month" => '**', //$exp_date_month,
"exp_year" => '**', //$exp_date_year,
"cvc" => '***'//$cvv_number
)
));


$token = $tokenDetail->id;
Stripe::setApiKey("*********************"); ////Put here your secrect key

// Get card id by creating a Customer.
$customer = Stripe_Customer::create(array(
"source" => $tokenDetail->id,
"description" => "For testing purpose",
)
);  

$response = Stripe_Charge::create(array(
"amount" => 100,
"currency" => "usd",
"customer" => $customer->id // obtained with Stripe.js
));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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