Javascript 条带错误400-不能多次使用条带标记

Javascript 条带错误400-不能多次使用条带标记,javascript,php,stripe-payments,Javascript,Php,Stripe Payments,我在我的stripe仪表板上不断收到错误代码400。看起来im多次使用相同的条带标记,这会产生错误。下面是我的代码 Js: var handler=StripeCheckout.configure({ 键:“pk_测试”*****************, 图像:'/img/documentation/checkout/marketplace.png', 令牌:函数(令牌){ /*$.post(“php/charge.php”,{stripeToken:token.id},函数(数据,状态){

我在我的stripe仪表板上不断收到错误代码400。看起来im多次使用相同的条带标记,这会产生错误。下面是我的代码

Js:


var handler=StripeCheckout.configure({
键:“pk_测试”*****************,
图像:'/img/documentation/checkout/marketplace.png',
令牌:函数(令牌){
/*$.post(“php/charge.php”,{stripeToken:token.id},函数(数据,状态){
console.log(“数据:+数据+”\n状态:+状态);
});*/
警报(token.used);//警报为false
$.post(“php/charge.php”,{stripeToken:token.id});
警报(token.used);//警报仍然为false
}
});
$('#myButton')。在('单击')上,函数(e){
//打开带有更多选项的签出
handler.open({
名称:“演示站点”,
描述:“2个小部件”,
货币:“cad”,
金额:2000
});
e、 预防默认值();
});
//关闭页面导航上的签出
$(窗口).on('popstate',function()){
handler.close();
});
Php:



有人能告诉我为什么不能向客户收费吗?我如何多次使用密钥?

您确实使用了两次令牌

首先,在创建客户时。 第二,在尝试刷卡时

相反,您可以创建一个客户,然后在创建费用时将
$customer->id
传递给Stripe:

$charge = \Stripe\Charge::create(array(
  "amount" => 1000, // amount in cents, again
  "currency" => "cad",
  "customer" => $customer->id,
  "description" => "Example charge")
);

您必须创建客户以向其多次收费

1) 将信用卡令牌添加到customer并创建customer

2) 使用客户Id向用户收费

if (isset($_POST['stripeToken'])){

        $token = $_POST['stripeToken'];

// Create a Customer
$customer = \Stripe\Customer::create(array(
  "source" => $token,
  "description" => "Example customer")
);


有关更多帮助,请访问:

也许stripe从那时起更改了API,但现在如果要使用客户id,您必须提供“客户”而不是“来源”。因此,数组将是:数组('amout'=>1000,'currency'=>cad','customer'=>$customer->id,'description'=>example charge')如果我们想多次使用同一张卡,是否必须创建客户?如果使用一次性收费,则需要客户id,然后在之后立即创建订阅日锚。
$charge = \Stripe\Charge::create(array(
  "amount" => 1000, // amount in cents, again
  "currency" => "cad",
  "customer" => $customer->id,
  "description" => "Example charge")
);
if (isset($_POST['stripeToken'])){

        $token = $_POST['stripeToken'];

// Create a Customer
$customer = \Stripe\Customer::create(array(
  "source" => $token,
  "description" => "Example customer")
);
// Charge the Customer instead of the card
\Stripe\Charge::create(array(
  "amount" => 1000, # amount in cents, again
  "currency" => "usd",
  "customer" => $customer->id)
);
    }