简体   繁体   English

条纹表格不会创建任何信用卡

[英]Stripe form does not create any credit card

I'm a beginner with Stripe and i am struggling with the doc, i've tried several tutorials but none of them could make my form work. 我是Stripe的初学者,我在文档中苦苦挣扎,我尝试了一些教程,但是没有一个可以使我的表单正常工作。

The problem is that the form does create a token and a customer (i can see it in my Stripe Dashboard) but it does not create a credit card for that customer and when i try to subscribe that customer to a plan, i get an error. 问题在于该表单确实创建了令牌和一个客户(我可以在“条纹仪表板”中看到它),但没有为该客户创建信用卡,并且当我尝试将该客户订阅计划时,我得到了一个错误。

here is my form's code: 这是我表格的代码:

<body>

    <div id="listblock">

        <div class="lines" id="logo">
            <h2>Pay from here! </h2>
        </div>

        <form action="payment.php" method="post" id="payment-form">
            <input class="card-number" type="text" required placeholder="1234 5678 8765 4321">
            <input class="card-expiry-month" type="number" required placeholder="MM">
            <input class="card-expiry-year" type="number" required placeholder="YY">
            <input class="card-cvc" type="number" required placeholder="CVC">
            <input type="radio" name="plan" value="1" checked>Basic annual subscription (99€/year)
            <input type="radio" name="plan" value="2" checked>Basic monthly subscription (9,99€/month)

            <button class="button" type="submit">Submit Payment</button>
        </form>

    </div>

</body>

<script src="https://js.stripe.com/v2/"></script>
<script src="https://js.stripe.com/v3/"></script>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script>
    Stripe.setPublishableKey('my key is here');

    var $form = $('#payment-form'); // On récupère le formulaire

    $form.submit(function (e) {

        e.preventDefault();
        $form.find('button').prop('disabled', true); // On désactive le bouton submit

        Stripe.card.createToken({

            number:     $('.card-number').val(),
            cvc:        $('.card-cvc').val(),
            exp_month:  $('.card-expiry-month').val(),
            exp_year:   $('.card-expiry-year').val()

        }, function (status, response) {

            if (response.error) { // Ah une erreur !

                // On affiche les erreurs
                $form.find('.payment-errors').text(response.error.message);
                $form.find('button').prop('disabled', false); // On réactive le bouton

            } else { // Le token a bien été créé

                var token = response.id; // On récupère le token
                // On crée un champs cachée qui contiendra notre token
                $form.append($('<input type="hidden" name="stripeToken" />').val(token));
                $form.get(0).submit(); // On soumet le formulaire

            }
        });
    });


</script>

the error given by Stripe's API is: Stripe API给出的错误是:

    {
  "error": {
    "type": "invalid_request_error",
    "message": "This customer has no attached payment source"
  }
}

Thanks for your help ! 谢谢你的帮助 !

As it seems you are just developing your application, you should definitely use the updated version of Stripe which is v3. 看来您只是在开发应用程序,因此绝对应该使用Stripe的更新版本,即v3。

Now, if you want your customer to subscribe in a recurrent payment plan, you should first create a Subscription Plan (Either using the API or from Dashboard), then create Customer . 现在,如果您希望客户订阅定期付款计划,则应首先创建一个订阅计划 (使用API​​或从Dashboard),然后创建Customer To create a customer you need to code like the following: 要创建客户,您需要编写如下代码:

stripe.customers.create({
  email: "jenny.rosen@example.com",
}, function(err, customer) {
  // asynchronously called
});

And then subscribe the customer to the Plan you've already created. 然后为客户订阅您已经创建的计划。 All of it is described in the official doc very nicely, just read it carefully. 所有这些在官方文档中都有很好的描述,请仔细阅读。

Also, if you don't need to implement a recurrent subscription, just want to store the customer information for make later payment, you can just follow this quick start guide , specifically this part . 此外,如果您不需要实施定期订阅,只想存储客户信息以进行以后的付款,则可以按照此快速入门指南 (特别是这一部分)进行操作

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

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