条纹错误400 -不能使用条纹令牌多于一次


Stripe Error 400 - Cannot use stripe token more than once

我一直在我的条纹仪表板上收到错误代码400。似乎我使用相同的条纹令牌不止一次,这会产生一个错误。下面是我的代码。

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+"'nStatus: "+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
    //}
?>

谁能告诉我为什么我不能向客户收费?我如何多次使用一个键?

您确实使用了两次令牌。

首先,在创建客户时。第二,当你试图刷卡时。

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

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

您必须创建客户以多次收取费用。

1)向客户添加信用卡令牌并创建客户

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

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)
);
    }

更多帮助请访问:https://stripe.com/docs/tutorials/charges

相关文章: