dongza3124 2015-06-10 02:54
浏览 34
已采纳

条带错误400 - 不能多次使用条带令牌

I keep receiving error code 400 on my stripe dashboard. It seems like im using the same stripe token more than once and this produces an error. Below is my code.

Js:

    <script src="https://checkout.stripe.com/checkout.js"></script>
    <script>

    var handler = StripeCheckout.configure({
        key: 'pk_test_******************',
        image: '/img/documentation/checkout/marketplace.png',
        token: function(token) {
          /*$.post("php/charge.php",{stripeToken:token.id},function(data,status){
              console.log("Data: "+ data+"
Status: "+status);
          });*/
          alert(token.used);//alerts false
          $.post("php/charge.php",{stripeToken:token.id});
          alert(token.used);// still alerts false
        }
      });

      $('#myButton').on('click', function(e) {
        // Open Checkout with further options
        handler.open({
          name: 'Demo Site',
          description: '2 widgets',
          currency: "cad",
          amount: 2000
        });
        e.preventDefault();
      });

      // Close Checkout on page navigation
      $(window).on('popstate', function() {
        handler.close();
      });
    </script>

Php:

<?php
  require_once('config.php');

  $token  = $_POST['stripeToken'];

  $customer = \Stripe\Customer::create(array(
      'email' => 'test@test.com',
      'card'  => $token
  ));

  //try {
    $charge = \Stripe\Charge::create(array(
      "amount" => 1000, // amount in cents, again
      "currency" => "cad",
      "source" => $token,
      "description" => "Example charge")
    );
    //}catch(\Stripe\Error\Card $e) {
      // The card has been declined
    //}
?>

Can anyone tell my why I cant charge a customer? How am I using a key multiple times?

  • 写回答

2条回答 默认 最新

  • dougongyou7364 2015-06-10 03:15
    关注

    You do use the token twice.

    First, when creating the customer. Second, when trying to charge the card.

    Instead, you can create a customer and and then pass $customer->id to Stripe when you create the charge:

    $charge = \Stripe\Charge::create(array(
      "amount" => 1000, // amount in cents, again
      "currency" => "cad",
      "customer" => $customer->id,
      "description" => "Example charge")
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c