2014-03-06 56 views
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)" 
+0

它看起來像你的代碼中有錯誤。看起來你忘了在調用它之前忘記給'response'賦值? – BWStearns

回答

1

你的第一個參數令牌處理功能是token。您可以在token.id中訪問令牌ID,然後訪問response.id。你可以看到這樣的例子在條紋文檔自定義Google Checkout集成:

(我認爲有其他代碼在使用response爲參數的文檔,這可能是在那裏混亂是從哪裏來的。)

希望幫助, 拉里

PS我的條紋工作。

相關問題