问题
I'm getting an error when making a charge using a token created from a customer previously created using stripe. I need to be able to charge a user more than once so charges can go to multiple destinations, which is why I'm creating the token. However, when trying to charge anyone using the following code I get the error:
Fatal error: Uncaught exception 'Stripe\Error\InvalidRequest' with message 'No such token: tok_187sfmBqiK1u6WYC3qS20eNu'
$stripe_id and other variables have been assigned in my code, I'm just copy/pasting the main bits:
\Stripe\Stripe::setApiKey("sk_mykey-changedforsecurity"); // authorises secret key
$token = $_POST['stripeToken'];
$customer = \Stripe\Customer::create(array(
"description" => "test customer",
"source" => $token // obtained with Stripe.js
));
$chargetoken = \Stripe\Token::create(
array("customer" => $customer->id),
array("stripe_account" => $stripe_id) // id of the connected account
);
$charge = \Stripe\Charge::create(array(
"amount" => $price,
"currency" => "gbp",
"source" => $chargetoken,
"description" => $title,
"application_fee" => 20,
"destination" => $stripe_id
));
Any help would be very appreciated,
Thanks
回答1:
In stripe, any token you got/create is one time so you can not use token twice. Stripe supports the charges in 3 ways.
- Using card token
- Using token (you are doing)
- Using customer Id
So in your case simply use customer Id instead of the token to charge a customer multiple time. CustomerId will not expire.
So inside charge object use "customer" field
you can see the charge object here stripe
来源:https://stackoverflow.com/questions/37059349/how-to-make-multiple-payments-using-a-token-created-from-a-customer-using-stripe