0
我正在使用Stripe checkout自定義按鈕,並且無法在成功返回令牌後讓它提交表單。爲什麼我的表單沒有提交?
這裏是我的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的開發者工具這是顯示出來後,我順利地通過條紋結帳提交我的測試證書的錯誤:
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'賦值? – BWStearns