为什么我的表格没有提交?

2024-05-28 23:10:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用带有自定义按钮的条带签出,无法让它在成功返回令牌后提交我的表单。在

以下是我的HTML:

<form id="payment-form" action="{% url 'shipment:confirm' %}" method="POST">
{% csrf_token %}
</form>

<script type="text/javascript" src="https://js.stripe.com/v2/"></script>

<button id="customButton">Join BossBox</button>

<script>
  var handler = StripeCheckout.configure({
    key: 'secrettestkey (I redacted this)',
    image: '/static/shipment/images/logo.png',
    email: "{{ email_address }}",
    token: function(token, args) {
        // get the form by it's ID, you would have to add the id="payment-form" to your HTML
        var $form = $("#payment-form");
        // token contains id, last4, and card type
        var token = response.id;
        // insert the token into the form so it gets submitted to the server
        $form.append("<input type='hidden' name='stripeToken' value='" + token + "' />");
        // and submit
        $form.get(0).submit();
    }
  });

  document.getElementById('customButton').addEventListener('click', function(e) {
    // Open Checkout with further options
    handler.open({
      name: 'MyCompany',
      description: 'Monthly Membership ($29.00)',
      amount: 2900,
    });
    e.preventDefault();
  });
</script>

在Chrome Developers Tools中,这是我通过条带签出成功提交测试凭据后出现的错误:

^{pr2}$

Tags: thetoformtokenidvarhtmltype
1条回答
网友
1楼 · 发布于 2024-05-28 23:10:35

令牌处理函数的第一个参数是token。您可以在token.id中访问令牌ID,而不是在response.id中。在自定义签出集成的Stripe文档中可以看到这样的示例:

(我认为文档中还有其他代码使用response作为参数,这可能是混淆的来源。)

希望有帮助, 拉里

PS我在Stripe工作。在

相关问题 更多 >

    热门问题