【问题标题】:Stripe Checkout Button Does Not Display When Using Angular Routes使用 Angular 路由时不显示条纹结帐按钮
【发布时间】:2015-01-20 20:24:51
【问题描述】:

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

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

我可以做些什么来让它在路由中工作,还是我应该只实现一个指向 stripe.js 库的自定义表单?谢谢。

【问题讨论】:

  • 嘿。你有想过这个吗?我在 Rails 应用程序中遇到了同样的问题。它以前工作过,我不知道它为什么停止工作。

标签: angularjs stripe-payments


【解决方案1】:

问题是 js 没有按您的建议触发。一个解决方案是简单地将 Stripe checkout.js 包含在您的 index.html 文件中,然后触发 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();

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

【讨论】:

    猜你喜欢
    • 2017-12-28
    • 1970-01-01
    • 2014-04-28
    • 2017-07-03
    • 1970-01-01
    • 1970-01-01
    • 2022-01-12
    • 1970-01-01
    • 2016-06-01
    相关资源
    最近更新 更多