如何从流星服务器访问Braintree功能 [英] How to access braintree functionality from Meteor server

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

问题描述

我正在尝试在我的Meteor应用程序中使用Braintree,并且已经制作了 this的本地包按照有关此主题的博文的说明,安装Braintree包装很好。



现在,我有了以下代码:

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

并抛出此错误:

  ReferenceError:未定义braintree 
(等)。

然后,我尝试按照 Braintree文档,但只会引发未定义 require的错误。

  var braintree = require( braintree) ; 

Braintree文档使用Express方法来使所有事情变为现实,但这在这里没有太多帮助。 / p>

我之前引用的程序包使用以下一行定义它是 server.js

  Braintree = Npm.require( braintree); 

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



我如何在Braintree上使用它?



谢谢!

解决方案

服务器软件包要求使用符号使用 api.export 导出软件包外部的内容。您所引用的程序包似乎是在流星 v0.6.5 之前构建的。一个>。我记得,EventedMind上的此视频解释了所有这个作品。我怀疑解决您的问题的方法只是使您的 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功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆