【发布时间】:2014-12-06 23:49:15
【问题描述】:
我一直在努力工作Meteor.WrapAsync 我已经阅读了Meteor wrapAsync syntax 的答案,这个视频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 :(
编辑
感谢支持,这就是我结束 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"
});
【问题讨论】:
-
控制台有错误吗?我猜这是因为您没有将函数绑定到对象:
Meteor.wrapAsync(stripe.charge.process, stripe.charge) -
没有错误,一开始也是这样做的,让我现在再试一次...
标签: javascript meteor stripe-payments