2015-01-20 54 views
11

我目前正在嘗試實施標準的條紋付款結帳對話框。當我在文檔(https://stripe.com/docs/checkout)中描述的包括短文件<script>中時,應該顯示的按鈕不被呈現。使用角度路線時不顯示條紋結賬按鈕

當我將它放在我的頂層index.html文件中時,會顯示按鈕。當我把它放到一個局部區域時,它會在碰到特定路線時顯示出來。我認爲這是因爲它不執行Javascript,因爲它在路徑中時不會在頁面加載時發生。

有沒有什麼我可以做到讓這個工作在路線中,或者我應該只是實現一個自定義表單,指向stripe.js庫?謝謝。

+2

嘿。你有沒有想過這個?我在Rails應用中遇到同樣的問題。它之前在工作,我不知道爲什麼它停止工作。 – Loubot 2015-02-16 13:45:52

回答

4

問題是,js不會按照您的建議觸發。一種解決方案是簡單地在您的index.html文件中包含Stripe checkout.js,然後觸發Stripe彈出窗口以在您的控制器(或其他地方)打開。

在您的index.html(或等同物)

<script src="https://checkout.stripe.com/checkout.js"></script> 
<!-- Angular script(s) --> 

在您的控制器(或其它地方)

var handler = StripeCheckout.configure({ 
    key: 'pk_test_6pRNASCoBOKtIshFeQd4XMUh', 
    image: '/img/documentation/checkout/marketplace.png', 
    locale: 'auto', 
    token: function(token) { 
    // Use the token to create the charge with a server-side script. 
    // You can access the token ID with `token.id` 
    } 
}); 

handler.open({ 
    name: 'Stripe.com', 
    description: '2 widgets', 
    amount: 2000 
}); 

// handler.close(); 

這是每次條紋文檔適配於:https://stripe.com/docs/checkout#integration-custom