I am trying to get Braintree Payments to work in the Meteor app. I was stuck in an attempt to return the result of creating a marker (server side, through the Meteor method), which will be used on the client side.
I tried this:
/server/braintree.js
Meteor.methods({
createClientToken: function() {
var token = gateway.clientToken.generate({
customerId: this.userId
}, function(err, response) {
clientToken = response.clientToken
return clientToken
}
)
console.log(token)
return token
}
})
which returns true.
I also tried this:
Meteor.methods({
createClientToken: function() {
var clientToken
gateway.clientToken.generate({
customerId: this.userId
}, function(err, response) {
clientToken = response.clientToken
}
)
console.log(clientToken)
return clientToken
}
})
What returns undefined.
function(err, response)called asynchronously, yes? If so, this will be the explanation of the problem. It seems like trying to return a value from an asynchronous function is a bit of a sore point in Javascript. I read some SO answers to it (like this , this, and this ), but no one seems to have led me in the right direction.
, , , , Meteor wrapAsync, ? ( SO- ), " , .
.
Update:
Braintree Meteor . ( @Nick Tomlin )