对于这种情况,Meteor现在具有Meteor.wrapAsync()。
这是通过Stripe收费并传递回调函数的最简单方法:
var stripe = StripeAPI("key"); Meteor.methods({ yourMethod: function(callArg) { var charge = Meteor.wrapAsync(stripe.charges.create, stripe.charges); charge({ amount: amount, currency: "usd", //I passed the stripe token in callArg card: callArg.stripeToken, }, function(err, charge) { if (err && err.type === 'StripeCardError') { // The card has been declined throw new Meteor.Error("stripe-charge-error", err.message); } //Insert your 'on success' pre here }); }});


