@ -294,7 +294,7 @@ order.setDelivery = (uuid, description, deliveryDate) =>
single : true
} )
order . shipEasyPost = async ( uuid , length , width , height , weight ) => {
order . shipEasyPost = async ( uuid , length , width , height , weight , items ) => {
// Retrieve address
const { address } = await order . findByUUID ( uuid )
const { shipping _from } = await config . getLatestConfig ( )
@ -302,20 +302,53 @@ order.shipEasyPost = async ( uuid, length, width, height, weight ) => {
if ( ! shipping _from ? . easypost _id )
throw new Error ( "Cannot ship - no from address set in config" )
// Create shipment
const epShipment = new easypost . Shipment ( {
to _address : address . easypost _id ,
from _address : shipping _from . easypost _id ,
parcel : { length , width , height , weight }
} )
// Save shipment
await epShipment . save ( )
if ( ! shipping _from ? . phone )
throw new Error ( "Cannot ship - Selected from address has no phone" )
let purchasedShipment ;
try {
// Create shipment
const epShipment = new easypost . Shipment ( {
to _address : address . easypost _id ,
from _address : shipping _from . easypost _id ,
parcel : { length , width , height , weight }
} )
if ( address . country !== 'US' ) {
const customsInfo = new easypost . CustomsInfo ( {
eel _pfc : 'NOEEI 30.37(a)' ,
contents _type : 'merchandise' ,
contents _explanation : 'Goods purchased from societyofsocks.us' ,
customs _certify : true ,
customs _signer : 'Kirk Hamilton' ,
restriction _type : 'none' ,
customs _items : items . map ( ( { item , count } ) => ( {
description : item . customs _description ,
quantity : count ,
value : ( item . price _cents * count / 100 ) . toFixed ( 2 ) ,
weight : item . weight _oz * count ,
hs _tariff _number : item . hs _tariff _number ,
origin _countr : item . customs _origin _country
} ) )
} )
await customsInfo . save ( )
epShipment . customs _info = customsInfo ;
}
// Save shipment
await epShipment . save ( )
// Purchase shipment (lowest USPS rate)
const { tracking _code , id : easypost _id , selected _rate : { rate : price _string } }
= await epShipment . buy ( epShipment . lowestRate ( [ 'USPS' ] ) )
purchasedShipment = await epShipment . buy ( epShipment . lowestRate ( [ 'USPS' ] ) )
} catch ( err ) {
console . log ( err )
throw new Error ( "Cannot purchase shipment - see log for details" )
}
const { tracking _code , id : easypost _id , selected _rate : { rate : price _string } } = purchasedShipment
const price _cents = Math . floor ( parseFloat ( price _string ) * 100 )
// Save tracking code and easypost id