简体   繁体   English

Stripe '无法向没有活动卡的客户收费'

[英]Stripe 'Cannot charge a customer that has no active card'

This is straight off the website.这是直接从网站上删除的。 So I followed the tutorial but I obviously got something wrong.所以我按照教程进行了操作,但显然我做错了。 I have it on server with SSL.我在带有 SSL 的服务器上安装了它。

If this is their code then where did I go wrong.如果这是他们的代码,那么我哪里出错了。 jquery, v2.js and stripe are properly included. 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)
    );
?>

It gives me this error:它给了我这个错误:

Fatal error: Uncaught exception 'Stripe\\Error\\Card' with message 'Cannot charge a customer that has no active card' in /home3/blueman/public_html/assistforlife.com/stripe/lib/ApiRequestor.php:114 from API request 'req_9SlHeDVEeYFup4'致命错误:未捕获的异常“Stripe\\Error\\Card”在 /home3/blueman/public_html/assistforlife.com/stripe/lib/ApiRequestor.php:114 from API request 中带有消息“无法向没有活动卡的客户收费” req_9SlHeDVEeYFup4'
Stack trace:堆栈跟踪:
#0 /home3/blueman/public_html/assistforlife.com/stripe/lib/ApiRequestor.php(266): Stripe\\ApiRequestor->handleApiError('{\\n "error": {\\n...', 402, Array, Array) #0 /home3/blueman/public_html/assistforlife.com/stripe/lib/ApiRequestor.php(266): Stripe\\ApiRequestor->handleApiError('{\\n "error": {\\n...', 402, Array , 数组)
#1 /home3/blueman/public_html/assistforlife.com/stripe/lib/ApiRequestor.php(65): Stripe\\ApiRequestor->_interpretResponse('{\\n "error": {\\n...', 402, Array) #1 /home3/blueman/public_html/assistforlife.com/stripe/lib/ApiRequestor.php(65): Stripe\\ApiRequestor->_interpretResponse('{\\n "error": {\\n...', 402, Array )
#2 /home3/blueman/public_html/assistforlife.com/stripe/lib/ApiResource.php(120): Stripe\\ApiRequestor->request('post', '/v1/charges', Array, 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) #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/public_html/assistforlife.com/charge.ph in /home3/blueman/public_html/assistforlife.com/stripe/lib/ApiRequestor.php on line 114 #4 /home3/blueman/public_html/assistforlife.com/stripe /lib/Charge.php(73): Stripe\\ApiResource::_create(Array, NULL) #5 /home3/blueman/public_html/assistforlife.com/charge.第 114 行 /home3/blueman/public_html/assistforlife.com/stripe/lib/ApiRequestor.php 中的 ph

I wrote my own code and it said that the value for my card was "null" I re-wrote it borrowing somebody else's code and it posted the customer but not any of the charge information.我写了我自己的代码,它说我的卡的价值是“空”我重新写了借用别人的代码,它发布了客户,但没有发布任何收费信息。

In your server-side PHP code, $token must have a null value, so the customer is created without a payment source.在您的服务器端 PHP 代码中, $token必须具有null值,因此创建的客户没有付款来源。 Then when you try to use it to create a charge, the request fails with "Cannot charge a customer that has no active card".然后,当您尝试使用它来创建费用时,请求失败并显示“无法向没有活动卡的客户收费”。

Your form's code looks correct so I'm not sure why $token is empty.您的表单代码看起来正确,所以我不确定为什么$token为空。 I'd recommend using your browser's dev tools to make sure that the token ID ( "tok_..." ) created by Stripe.js is really sent as the stripeToken POST parameter.我建议使用浏览器的开发工具来确保由 Stripe.js 创建的令牌 ID ( "tok_..." ) 确实作为stripeToken POST 参数发送。

On an unrelated note, according to this line:在一个不相关的注释上,根据这一行:

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

it look like you're locally hosting Stripe.js.看起来您在本地托管 Stripe.js。 Note that in order to be PCI compliant, you must use the version that's hosted on Stripe's own servers, at https://js.stripe.com/v2/ .请注意,为了符合 PCI 标准,您必须使用在 Stripe 自己的服务器上托管的版本, https://js.stripe.com/v2/https://js.stripe.com/v2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM