首页 文章

条纹'Cannot charge a customer that has no active card'

提问于
浏览
1

这是直接的网站 . 所以我按照教程,但我显然有些不对劲 . 我在服务器上使用SSL .

如果这是他们的代码那么我哪里出错了 . 正确包含jquery,v2.js和stripe .

<!DOCTYPE html>
<html lang="en">
    <head>
      <!-- Stripe.js used; fewer compliance requirements! -->
      <!-- Include Stripe.js, either in your <head> or as a direct descendant of <body>
      at the end of the page -->
      <script type="text/javascript" src="v2.js"></script>
      <script type="text/javascript" src="development-bundle"></script>
      <script type="text/javascript">
        Stripe.setPublishableKey('pk_test_thenthetestkeyidontwanttoshare');
      </script>
      <script>
        function stripeResponseHandler(status, response) {
        // Grab the form:
          var $form = $('#payment-form');

          if (response.error) { // Problem!

            // Show the errors on the form:
            $form.find('.payment-errors').text(response.error.message);
            $form.find('.submit').prop('disabled', false); // Re-enable submission

          } else { // Token was created!

            // Get the token ID:
            var token = response.id;

            // Insert the token ID into the form so it gets submitted to the server:
            $form.append($('<input type="hidden" name="stripeToken">').val(token));

            // Submit the form:
            $form.get(0).submit();
          }
        };
        $(function() {
          var $form = $('#payment-form');
          $form.submit(function(event) {
            // Disable the submit button to prevent repeated clicks:
            $form.find('.submit').prop('disabled', true);

            // Request a token from Stripe:
            Stripe.card.createToken($form, stripeResponseHandler);

            // Prevent the form from being submitted:
            return false;
          });
        });
      </script>
    </head>
    <body>
        <form action="charge.php" method="POST" id="payment-form">
          <span class="payment-errors"></span>

          <div class="form-row">
            <label>
              <span>Card Number</span>
              <input type="text" size="16" data-stripe="number">
            </label>
          </div>

          <div class="form-row">
            <label>
              <span>Expiration (MM/YY)</span>
              <input type="text" size="2" data-stripe="exp_month">
            </label>
            <span> / </span>
            <input type="text" size="4" data-stripe="exp_year">
          </div>

          <div class="form-row">
            <label>
              <span>CVC</span>
              <input type="text" size="3" data-stripe="cvc">
            </label>
          </div>

          <div class="form-row">
            <label>
              <span>Billing Zip</span>
              <input type="text" size="5" data-stripe="address_zip">
            </label>
          </div>

          <input type="submit" class="submit" value="Submit Payment">
        </form>
    </body>
</html>


<?php
    include('stripe/init.php');
    \Stripe\Stripe::setApiKey("sk_test_otherkeyidontwanttoshare");

    // Get the credit card details submitted by the form
    $token = $_POST['stripeToken'];

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

    // Charge the Customer instead of the card
    \Stripe\Charge::create(array(
      "amount" => 1000, // Amount in cents
      "currency" => "usd",
      "customer" => $customer->id)
    );
?>

它给了我这个错误:

致命错误:来自API请求的/home3/blueman/public_html/assistforlife.com/stripe/lib/ApiRequestor.php:114中未捕获的异常'Stripe \ Error \ Card',并显示消息'无法向没有活动卡的客户收费' 'req_9SlHeDVEeYFup4'堆栈跟踪:#0 /home3/blueman/public_html/assistforlife.com/stripe/lib/ApiRequestor.php(266):Stripe \ ApiRequestor-> handleApiError('{\ n“error”:{\ n .. . ',402,Array,Array)#1 /home3/blueman/public_html/assistforlife.com/stripe/lib/ApiRequestor.php(65):Stripe \ ApiRequestor - > _ interpretResponse('{\ n“错误”:{\ n ...',402,Array)#2 /home3/blueman/public_html/assistforlife.com/stripe/lib/ApiResource.php(120):Stripe \ ApiRequestor-> request('post','/ v1 / charges ',Array,Array)#3 /home3/blueman/public_html/assistforlife.com/stripe/lib/ApiResource.php(160):Stripe \ ApiResource :: _ staticRequest('post','/ v1 / charges',Array, NULL)#4 /home3/blueman/public_html/assistforlife.com/stripe /lib/Charge.php(73):Stripe \ ApiResource :: _ create(Array,NULL)#5 / home3 / blueman / p第114行/home3/blueman/public_html/assistforlife.com/stripe/lib/ApiRequestor.php中的ublic_html / assistforlife.com / charge.ph

我写了我自己的代码,它说我的卡的 Value 是“空”我重写它借用别人的代码,它发布了客户,但没有任何收费信息 .

1 回答

  • 1

    在服务器端PHP代码中, $token 必须具有 null 值,因此创建的客户没有付款来源 . 然后,当您尝试使用它来创建费用时,请求将失败"Cannot charge a customer that has no active card" .

    您的表单's code looks correct so I'我不确定为什么 $token 为空 . 我使用开发工具来确保Stripe.js创建的令牌ID( "tok_..." )真的是作为 stripeToken POST参数发送的 .

    根据这条线,一个不相关的说明:

    <script type="text/javascript" src="v2.js"></script>
    

    它看起来像是're locally hosting Stripe.js. Note that in order to be PCI compliant, you must use the version that'托管在Stripe自己的服务器上,位于 https://js.stripe.com/v2/ .

相关问题