Подтвердить что ты не робот

Stripe Error 400 - Невозможно использовать маркер полосы более одного раза

Я продолжаю получать код ошибки 400 на моей панели. Кажется, что im использует один и тот же токен полосы более одного раза, и это вызывает ошибку. Ниже мой код.

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' => '[email protected]',
      '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
    //}
?>

Может ли кто-нибудь сказать мне, почему я не могу зарядить клиента? Как я использую ключ несколько раз?

4b9b3361

Ответ 1

Вы используете токен дважды.

Во-первых, при создании клиента. Во-вторых, при попытке зарядить карту.

Вместо этого вы можете создать клиента, а затем передать $customer->id в Stripe при создании заряда:

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

Ответ 2

Вам нужно создать клиента, чтобы обвинить его несколько раз.

1) Добавьте токен кредитной карты к клиенту и создайте клиента

2) Используйте идентификатор клиента для зарядки пользователей

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