I been trying to make work Meteor.WrapAsync
I have read Meteor wrapAsync syntax answer, this video https://www.eventedmind.com/feed/meteor-meteor-wrapasync and I just cant figure how to return
the response from the call from Stripe. I'm using console.log
to print the steps, and I been reaching throw number 4 which mean, Im reaching stripe
server and getting the response, but after that I can't see why console.log(5)
its not printing. please if somebody can help me to understand why its the wrapAsyn its not returning the stripe callback?
//this functions are part of an anonymous function and running in the server side of meteor
stripe.charge = function (stripeToken) {
// get a sync version of our API async func
var strypeChargeSync = Meteor.wrapAsync(stripe.charge.process);
// call the sync version of our API func with the parameters from the method call
console.log("1");
var response = strypeChargeSync(stripeToken);
console.log("5" + response); ///// this never get print / log
return response;
}
stripe.charge.process = function(stripeToken){
var _stripe = StripeAPI(stripeKey);
console.log("2");
var charge = _stripe.charges.create({
amount: 1000, // amount in cents, again
currency: "cad",
card: stripeToken.id,
description: "paid@whatever"
}, function(err, charge) {
if (err && err.type === 'StripeCardError') {
alert("Sorry we couldn't charge the money: " + err);
//console.log(err);
}else{
console.log("4");
//console.log(charge);
return charge;
}
});
console.log("3");
}
//current output 1,2,3,4 but never 5 :(
EDIT
this is how I end having the Stripe function thanks for the support
var syncFunction = Meteor.wrapAsync(_stripe.charges.create, _stripe.charges);
var response = syncFunction({
amount: 1000, // amount in cents, again
currency: "cad",
card: stripeToken.id,
description: "paid@whatever"
});