我一直在努力工作Meteor.WrapAsync
我读过了Meteor wrapAsync 语法 https://stackoverflow.com/questions/26058205/meteor-wrapasync-syntax回答这个视频https://www.eventedmind.com/feed/meteor-meteor-wrapasync https://www.eventedmind.com/feed/meteor-meteor-wrapasync我只是不知道如何return
Stripe 的电话回复。我在用着console.log
打印步骤,我已经到达了第 4 号,这意味着,我正在到达stripe
服务器并得到响应,但之后我不明白为什么console.log(5)
它不打印。如果有人可以帮助我理解为什么它的wrapAsyn不返回条带回调?
//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");
}
//当前输出 1,2,3,4 但绝不输出 5 :(
EDIT
这就是我结束 Stripe 功能的方式,感谢您的支持
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"
});