Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';t创建带条纹的信用卡令牌(django)_Javascript_Python_Html_Django_Stripe Payments - Fatal编程技术网

Javascript Can';t创建带条纹的信用卡令牌(django)

Javascript Can';t创建带条纹的信用卡令牌(django),javascript,python,html,django,stripe-payments,Javascript,Python,Html,Django,Stripe Payments,我正在使用django开发一个web应用程序,我正在尝试使用stripe处理付款,我在创建令牌时遇到了问题(我认为这是个问题)。下面是我的签出页面的html/javascript代码 <head> <script type="text/javascript" src="https://js.stripe.com/v2/"></script> </head> <body> <form action="{% url

我正在使用django开发一个web应用程序,我正在尝试使用stripe处理付款,我在创建令牌时遇到了问题(我认为这是个问题)。下面是我的签出页面的html/javascript代码

<head>
    <script type="text/javascript" src="https://js.stripe.com/v2/"></script>
</head>
<body>
     <form action="{% url 'checkout:p' %}" id="payment-form" method="post">
        {% csrf_token %}
        number:<input class="card-number" type='text'>
        cvc:<input class="card-cvc" type='text'>
        month:<input class="card-expiry-month" type='text'>
        year:<input class="card-expiry-year" type='text'>

        <script type="text/javascript">
            $('form').submit((fucnction(){
                var $form = $('#payment-form');
                Stripe.setPublishableKey('pk_test_KaWOobBc2ELxFoSoqmS1gtz2');

                Stripe.card.createToken({
                    number: $('.card-number').val(),
                    cvc: $('.card-cvc').val(),
                    exp_month: $('.card-expiry-month').val(),
                    exp_year: $('.card-expiry-year').val()
                        }, stripeResponseHandler);

                function stripeResponseHandler(status, response) {


                 if (response.error) {
                    // Show the errors on the form
                    $form.find('.payment-errors').text(response.error.message);
                    $form.find('button').prop('disabled', false);
                  } else {
                    // response contains id and card, which contains additional card details
                        var token = response.id;
                    // Insert the token into the form so it gets submitted to the server
                     $form.append($('<input type="text" name="stripeToken" />').val(token));
                    // and submit
                    $form.get(0).submit();
                  }
                }
            });
        </script>
        <input type="text" name="life" value=42>
        <button type="submit">Submit</button>
    </form>

</body>

我收到的错误消息是“您传递了一个空字符串作为‘card’。您应该从请求中删除‘card’参数或提供一个非空值。”我假设这只是意味着我没有正确创建信用卡令牌,但我可能错了。任何帮助都会很好,谢谢。

卡参数不应该是
stripeToken
,它应该是这样的

"card": {
    "id": "card_15EGuS2eZvKYlo2CgNp97XYZ",
    "object": "card",
    "last4": "4242",
    "brand": "Visa",
    "funding": "credit",
    "exp_month": 1,
    "exp_year": 2050,
    "fingerprint": "Xt5EWLLDS7FJjR1c",
    "country": "US",
    "name": null,
    "address_line1": null,
    "address_line2": null,
    "address_city": null,
    "address_state": null,
    "address_zip": null,
    "address_country": null,
    "cvc_check": "pass",
    "address_line1_check": null,
    "address_zip_check": null,
    "dynamic_last4": null,
    "customer": null
  },
您可以在中签出其余参数


您应该在视图中传递
card={'id':stripeToken}

您可以放置
console.log(令牌)吗紧接着
var token=response.id行,然后查看控制台上打印的值是多少?谢谢。我添加并更改了$form.append($('').val('42');对于if和else语句,都可以查看值是否通过post请求发送,我做了if card==42:(重定向到主页),这并不意味着值没有通过post请求发送。我还尝试了console.log(token),但当我单击submit to时,它会刷新页面,我看不到token。谢谢,但随后注释掉
$form.get(0.submit()暂时离开控制台。日志(令牌)
呼叫那里。什么是印刷品?
"card": {
    "id": "card_15EGuS2eZvKYlo2CgNp97XYZ",
    "object": "card",
    "last4": "4242",
    "brand": "Visa",
    "funding": "credit",
    "exp_month": 1,
    "exp_year": 2050,
    "fingerprint": "Xt5EWLLDS7FJjR1c",
    "country": "US",
    "name": null,
    "address_line1": null,
    "address_line2": null,
    "address_city": null,
    "address_state": null,
    "address_zip": null,
    "address_country": null,
    "cvc_check": "pass",
    "address_line1_check": null,
    "address_zip_check": null,
    "dynamic_last4": null,
    "customer": null
  },