Meteor - React - Stripe:如何导入Stripe

时间:2017-06-03 00:53:59

标签: reactjs meteor stripe-payments

在Meteor / React应用程序中,我需要从mrgalaxy:stripe导入Stripe。我试过了:

import { Stripe }  from 'meteor/mrgalaxy:stripe';

但它返回:

TypeError: Cannot read property 'setPublishableKey' of undefined 

在服务器文件夹中我创建了stripe.js文件,其中添加了以下内容:

import { Meteor } from 'meteor/meteor';
import { Stripe }  from 'meteor/mrgalaxy:stripe';

Meteor.startup(function(){
  Stripe.setPublishableKey(Meteor.settings.public.StripePub);
});

2 个答案:

答案 0 :(得分:1)

基于此测试,github存储库中没有导入语句

Tinytest.add('Stripe client is available', function(test){
  test.isTrue(Stripe != null);
});

我猜测包含这个包只是将Stripe变量添加到全局范围。

stripe_client.html页面似乎是程序包中唯一的客户端代码,只包含以下html代码段。

<head>
  <script type="text/javascript" src="https://js.stripe.com/v2/"></script>
  <script type="text/javascript" src="https://checkout.stripe.com/checkout.js"></script>
</head>

因此,我认为你的导入只是覆盖了全局变量。您是否尝试删除导入声明? (请原谅我几乎完全不了解流星 - 我可能会离开这里。)

答案 1 :(得分:0)

帮助我的是添加了这个软件包&#34; stripe&#34;:&#34; ^ 4.9.0&#34;除了mrgalaxy :.meteor / packages中的条带

之外,还要进入package.json