本文介绍了如何从流星服务器访问Braintree功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的Meteor应用程序中使用Braintree,并且已经制作了的说明,安装Braintree包装很好。



现在,我有了以下代码:

  //在server / fixtures.js中定义
网关= braintree.connect({
环境:braintree.Environment.Sandbox,
商人ID:秘密,
publicKey: secret,
privateKey: secret
});

并抛出此错误:

  ReferenceError:未定义braintree 
(等)。

然后,我尝试按照解释了所有这个作品。我怀疑解决您的问题的方法只是使您的 package.js 看起来像这样:

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


I'm trying to use Braintree in my Meteor application, and I've made a local package of this Braintree packaging, following the instructions of this blog post on the subject, and the install went fine.

Now though, I have this code:

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

and it's throwing this error:

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

I then tried throwing in this line as recommended by the Braintree documentation, but it simply throws an error that "require" isn't defined.

var braintree = require("braintree");

The Braintree docs uses Express methodologies to make everything happen, but that's not a lot of help here.

The package I referenced earlier defines it's server.js with this single line:

Braintree = Npm.require("braintree");

so I tried changing my references to Braintree rather than braintree, but this was undefined the exact same way.

How do I get at Braintree to use it?

Thanks in advance!

解决方案

Server packages require that symbols used outside of the package be exported with api.export. It looks like the package you referenced was built prior to meteor v0.6.5. As I recall, this video on EventedMind explains how all of this works. I suspect the solution to your problem is just to make your package.js look something like:

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

这篇关于如何从流星服务器访问Braintree功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 17:30