Question

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!

Était-ce utile?

La solution

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(...);
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top