Skip to content

Instantly share code, notes, and snippets.

@AlexFrazer
Created July 7, 2015 12:00
Show Gist options
  • Save AlexFrazer/7bdfc575e66566ea2748 to your computer and use it in GitHub Desktop.
Save AlexFrazer/7bdfc575e66566ea2748 to your computer and use it in GitHub Desktop.
Meteor.methods({
'Order.createShipment': function (order) {
check(order, Orders.simpleSchema());
if (this.userId !== order.userId) {
throw new Meteor.Error(401, "Cannot create shipment for order.");
}
var EasyPost = Easypost(process.env.EASYPOST_KEY);
var response = Async.runAsync(function (done) {
EasyPost.Shipment.create({
to_address: Meteor.users.findOne(this.userId).addresses.shipping,
from_address: Meteor.settings['FROM_ADDRESS'],
parcel: Orders.calculateParcel(order)
}, function (err, shipment) {
// Problem 1 is here.
// Could have used Meteor.wrapAsync() to make a fiber
// however, the error message is oddly formatted.
// I think it makes more sense for it to be err.message alone.
if (err) {
done(err.message.message);
// here is the second problem.
// The getRates() call returns nothing.
// I want to defer buying the shipment until they see the rates.
} else {
done(null, {
id: shipment.id,
rates: shipment.getRates()
})
}
})
});
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment