HP.*_*HP. 12 javascript stripe-payments ionic-framework ionic2 angular
我使用Angular2,Ionic2和Stripe.js进行付款处理.这个离线带有条带支付网关的线程使用插件https://github.com/Telerik-Verified-Plugins/Stripe/blob/master/doc/index.md,但它不安全,因为你必须在内部嵌入密钥该应用程序.甚至页面也告诉人们不要使用这个插件.
我试着在这里使用node.js版本:
https://www.npmjs.com/package/stripe
但是,我无法弄清楚如何var stripe = require('stripe')(' your stripe API key ');在TypeScript中执行此操作,您必须使用import.
最后,我确实放入<script type="text/javascript" src="https://js.stripe.com/v2/"></script>了index.html,stripe变量全局显示在每个Component中.但是,我觉得这不是正确的方法,因为当stripe我在每个Component或Page中使用它时,对象可能还没有准备好.
使用Angular2和Stripe.js的正确方法是什么?Ionic2特别好看但是可选的.
谢谢
更新1
我尝试npm install stripe然后使用import '../../node_modules/stripe/lib/stripe.js';但仍然有错误:
TypeScript error: /Users/username/Documents/StripePayment/app/pages/home/home.ts(16,23): Error TS2304: Cannot find name 'Stripe'.
Error: Cannot find module '../../node_modules/stripe/lib/stripe.js' from '/Users/username/Documents/StripePayment/app/pages/home'
Run Code Online (Sandbox Code Playgroud)
这是我的VS Code截图,其中包含目录结构:
Mar*_*und 13
在index.html中添加脚本标签,然后在home.ts中导入后添加声明
declare var Stripe: any;
我相信这是在ng2中导入外部库的正确方法
Src:Nic Raboy
那里有更多的信息; 安装外部库的更好方法是从DefinitelyTyped下载typedef 并安装$ typings install
然后你应该可以像往常一样导入
当然,这是在DefinitelyTyped repo中有typedef.但是,Stripe库似乎没有typedef.
| 归档时间: |
|
| 查看次数: |
6960 次 |
| 最近记录: |