I have come to a slight impasse with my current Braintree implementation. I am trying to call an API function which in itself is asynchronous and I can’t figure out how to execute Meteor specific code in the callback
Here is a Meteor server method that calls the Braintree BtGateway.subscription.search
function and tries to store the results in a Meteor collection, but no matter what I do it bombs with
Exception in callback of async function: TypeError: keypath.split is not a function
Any pointers what I am doing wrong?
Meteor.methods({
btSubscriptionSearch(planId){
check(planId, String);
if(BtGateway != null) {
var subscriptionSearch = Meteor.wrapAsync(BtGateway.subscription.search, BtGateway.subscription);
// search for a planId
var searchFunction = function(search) {
search.planId().is(planId);
};
// insert the response into a collection
var responseFunction = Meteor.bindEnvironment(function (err, response) {
for(var i in response) {
var subscription = response[i];
var id = Subscriptions.update(
{id: subscription.id},
{
$set: subscription,
$setOnInsert: subscription
},
{upsert: true}
);
console.log(subscription.id+' => '+id);
});
}
);
subscriptionSearch(searchFunction, responseFunction);
} else {
console.log('btSubscriptionSearch Error');
throw new Meteor.Error(1001, 'No Braintree Gateway');
}
},
})