【问题标题】:Integration Stripe Angular, Cannot find name 'Stripe'. Did you mean 'stripe'?集成 Stripe Angular,找不到名称“Stripe”。您指的是 “stripe” 吗?
【发布时间】:2021-08-26 17:23:30
【问题描述】:

我正在尝试将 Stripe 与重定向集成到我的应用程序中,我正在使用 Angular-typescript。

这是我目前在组件中的代码:

var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.onload = function() {
  console.log('Script loaded');
  var stripe = Stripe(MY_PUBLICK_KEY);
  return stripe.redirectToCheckout({ sessionId: SESSION_I_RETURNED_FROM_MY_BACKEND});
}
script.src = 'https://js.stripe.com/v3/';
head.appendChild(script);

但运行上述代码时出现以下错误:

Cannot find name 'Stripe'. Did you mean 'stripe'?

我已经按照下一个指南https://stripe.com/docs/checkout/integration-builder 使用命令npm install --save stripe 安装了软件包

有没有人在集成 Stripe 时遇到过同样的问题?

谢谢!

【问题讨论】:

    标签: angular typescript stripe-payments


    【解决方案1】:

    stripe 包对应于stripe-nodea server-side library。对于客户端 Angular 应用程序,您需要 Stripe.js

    Stripe 有一个可用的模块加载器帮助程序库:@stripe/stripe-js (link) 您可能还想查看社区制作的ngx-stripe 库,但如果您主要使用redirectToCheckout,您可以跳过此。

    【讨论】:

      猜你喜欢
      • 2019-07-12
      • 2021-09-21
      • 1970-01-01
      • 2019-05-14
      • 2014-07-23
      • 1970-01-01
      • 2017-07-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多