我正在尝试在我的Meteor应用程序中使用Braintree,并按照this Braintree packaging的说明创建了this blog post on the subject的本地包,并且安装顺利。
现在,我有这段代码:
// 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来使用它?
提前致谢!
答案 0 :(得分:2)
服务器包要求使用api.export
导出包外部使用的符号。看起来您引用的包是在meteor v0.6.5之前构建的。我记得,EventedMind上的this video解释了所有这些是如何工作的。我怀疑你的问题的解决方案只是让你的package.js
看起来像:
Package.on_use(function (api) {
api.export('Braintree');
api.use(...);
api.add_files(...);
});