【问题标题】:Why isn't my form submitting?为什么我的表单没有提交?
【发布时间】:2014-04-08 10:56:34
【问题描述】:

我正在使用带有自定义按钮的 Stripe 结帐,并且无法在成功返回令牌后提交我的表单。

这是我的 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 开发者工具中,这是我通过 Stripe Checkout 成功提交测试凭据后出现的错误:

Uncaught ReferenceError: response is not defined (index):120
StripeCheckout.configure.token (index):120
onToken checkout.js:3
rpc.methods.setToken checkout.js:4
e.message checkout.js:3
(anonymous function)"

【问题讨论】:

  • 您的代码中似乎有错误。看来您在调用 response 之前忘记给它赋值了?

标签: python django stripe-payments


【解决方案1】:

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

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

希望对您有所帮助, 拉里

PS 我在 Stripe 工作。

【讨论】:

    猜你喜欢
    • 2014-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多