使用角度路径时不显示条带检出按钮

时间:2015-01-20 20:24:51

标签: angularjs stripe-payments

我目前正在尝试实施标准的Stripe Payments结帐对话框。当我放入文档(https://stripe.com/docs/checkout)中描述的简短<script>包含时,应显示的按钮未呈现。

当我把它放在我的顶级index.html文件中时,按钮会显示。当我把它放到一个部分,当它击中一个特定的路线时,它显示,它没有。我认为这是因为它没有执行Javascript,因为它在路由中的页面加载时不会发生。

我有什么办法可以让它在路线中运行,或者我应该只实现一个指向stripe.js库的自定义表单?感谢。

1 个答案:

答案 0 :(得分:6)

问题是js不会像你建议的那样开火。解决方案是在index.html文件中简单地包含条带checkout.js,然后触发条带弹出窗口以与控制器(或其他地方)一起打开。

在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();

这是根据Stripe文档进行的改编:https://stripe.com/docs/checkout#integration-custom