public function savebooking($shp_id)
{
try {
$ship_data = $this->get_shipment($shp_id);
if (empty($ship_data['shp_ep_ref'])) {
$faddr = $this->address_model->get_booking_addr($ship_data['shp_from']);
$from_address = \EasyPost\Address::create_and_verify(array('name' => $faddr['adr_contact'], 'street1' => $faddr['adr_street1'], 'street2' => $faddr['adr_street2'], 'city' => $faddr['city_name'], 'state' => $faddr['state_name'], 'zip' => $faddr['adr_zip'], 'country' => 'US', 'phone' => $faddr['adr_phone'], 'email' => $faddr['adr_email']));
$taddr = $this->address_model->get_booking_addr($ship_data['shp_to']);
$to_address = \EasyPost\Address::create(array('name' => $taddr['adr_contact'], 'street1' => $taddr['adr_street1'], 'street2' => $taddr['adr_street2'], 'city' => $taddr['city_name'], 'state' => $taddr['state_name'], 'zip' => $taddr['adr_zip'], 'country' => $taddr['cnt_code'], 'phone' => $taddr['adr_phone'], 'email' => $taddr['adr_email']));
$custom_info = array("description" => $ship_data['shp_desc'], "quantity" => $ship_data['shp_quantity'], "weight" => $ship_data['shp_weight'], "value" => $ship_data['shp_value'], "origin_country" => 'US', "eel_pfc" => $ship_data['shp_eelpfc']);
if ($ship_data['shp_type'] == 'document') {
$parcel = \EasyPost\Parcel::create(array("predefined_package" => 'DHLExpressEnvelope', "weight" => $ship_data['shp_weight']));
} else {
$parcel = array("length" => $ship_data['shp_length'], "width" => $ship_data['shp_width'], "height" => $ship_data['shp_height'], "weight" => $ship_data['shp_weight']);
$custom_info['customs_items'] = $this->get_shipping_customs($shp_id);
}
$shipment = \EasyPost\Shipment::create(array("to_address" => $to_address, "from_address" => $from_address, "parcel" => $parcel, "customs_info" => $custom_info, "carrier_accounts" => array(array('id' => 'ca_2bafcd3ab9b34db9a4de8040f143917f'))));
$ship_array = $shipment->__toArray(true);
$this->update_ep_ref($ship_array['id'], $shp_id);
} else {
$shipment = \EasyPost\Shipment::retrieve($ship_data['shp_ep_ref']);
}
$ship_array = $shipment->__toArray(true);
if (!empty($ship_array['messages'])) {
return $ship_array['messages'][0]['message'];
}
return $ship_array;
} catch (Exception $ex) {
return $ex->getMessage();
}
}