【问题标题】:How to access braintree functionality from Meteor server如何从 Meteor 服务器访问 Braintree 功能
【发布时间】:2014-04-04 22:42:43
【问题描述】:

我正在尝试在我的 Meteor 应用程序中使用 Braintree,并按照 this blog post on the subject 的说明制作了一个本地软件包 this Braintree packaging,并且安装顺利。

现在,我有这个代码:

// defined in server/fixtures.js
Gateway = braintree.connect({
    environment: braintree.Environment.Sandbox,
    merchantId: "secret",
    publicKey: "secret",
    privateKey: "secret"
});

它抛出了这个错误:

ReferenceError: braintree is not defined
(etc....)

然后我尝试按照the Braintree documentation 的建议加入这一行,但它只是抛出一个“require”未定义的错误。

var braintree = require("braintree");

Braintree 文档使用 Express 方法来实现一切,但这在这里帮助不大。

我之前引用的包将它定义为 server.js 并使用这一行:

Braintree = Npm.require("braintree");

所以我尝试将引用更改为 Braintree 而不是 braintree,但这未定义完全相同的方式。

我如何在 Braintree 使用它?

提前致谢!

【问题讨论】:

    标签: meteor braintree


    【解决方案1】:

    服务器包要求使用api.export 导出包外使用的符号。看起来您引用的包是在流星v0.6.5 之前构建的。我记得,EventedMind 上的this video 解释了所有这些是如何工作的。我怀疑您的问题的解决方案只是让您的 package.js 看起来像:

    Package.on_use(function (api) {
      api.export('Braintree');
      api.use(...);
      api.add_files(...);
    });
    

    【讨论】:

    • 我收到了这个:package.js:1:24: api is not defined。我把这行放在本地包中,你的意思是对的吗?
    • 我也尝试将其放在Package.on_use,但得到:TypeError: Cannot read property 'Environment' of undefined
    • 哦,等一下,我想我刚刚开始工作了,Package.on_use 是正确的,我只需要将您的行更改为 api.export('Braintree'); 大写,因为这是包使用的。
    • 是的,就是这样,你的行需要在Package.on_use 内,并且需要将 Braintree 大写,至少要使用这个包。非常感谢您的帮助!
    • 我很高兴你能成功。 :) 我更新了更具体的答案。
    猜你喜欢
    • 2016-07-14
    • 1970-01-01
    • 1970-01-01
    • 2020-03-24
    • 2020-12-07
    • 1970-01-01
    • 1970-01-01
    • 2016-06-04
    • 1970-01-01
    相关资源
    最近更新 更多