【问题标题】:Meteor - React - Stripe: how to import StripeMeteor - React - Stripe:如何导入 Stripe
【发布时间】:2017-11-04 11:21:41
【问题描述】:

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

【问题讨论】:

  • 这个包使用了过期版本的 api 和 npm 包。因为您现在可以直接使用 npm 包并将脚本声明添加到您的 <head> 模板中。

标签: reactjs meteor stripe-payments


【解决方案1】:

基于 github 存储库中没有 import 语句的测试

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

我猜想包含这个包只是在全局范围内添加了一个 Stripe 变量。

stripe_client.html 页面,似乎是包中唯一的客户端代码,仅包含以下 html sn-p。

<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>

因此,我认为您的导入只是覆盖了全局变量。您是否尝试过删除您的导入语句? (请原谅我对流星的几乎完全无知——我可能离这里很远)。

【讨论】:

【解决方案2】:

除了 .meteor/packages 中的 mrgalaxy:stripe 之外,还帮我添加了这个包 "stripe": "^4.9.0" 到 package.json 中

【讨论】:

    猜你喜欢
    • 2016-08-29
    • 2021-04-14
    • 2012-06-21
    • 2021-11-08
    • 2021-03-07
    • 2021-05-28
    • 1970-01-01
    • 2020-10-01
    • 2020-10-13
    相关资源
    最近更新 更多