How to make multiple payments using a token created from a customer using stripe?

偶尔善良 提交于 2019-12-12 03:26:34

问题


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.

  1. Using card token
  2. Using token (you are doing)
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!