Reputation: 21553
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?
Upvotes: 14
Views: 8551
Reputation: 205
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
));
Upvotes: 3
Reputation: 2271
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.
Upvotes: 35