public function validate_address($id = false)
 {
     $this->loadModel('UserAddress');
     $address = $this->UserAddress->findById($id);
     App::import('Vendor', 'UspsApi', array('file' => 'UspsApi.php'));
     $u = new UspsApi();
     $res = $u->validate_address($address['UserAddress']);
     die(print_r(simplexml_load_string($res)));
 }
 public function usps_tracking()
 {
     $this->loadModel('Warehouse');
     $wh = $this->Warehouse->findById(1);
     App::import("Vendor", "UspsApi", array("file" => "UspsApi.php"));
     $u = new UspsApi(false, $wh);
     $res = $u->get_tracking('420370669434601699320005869642');
     die(pr($res));
 }
 public function test_usps()
 {
     App::import("Vendor", "UspsApi", array("file" => "UspsApi.php"));
     $u = new UspsApi();
     $u->run_tests();
     die;
 }
 private function process_usps_int($record)
 {
     App::import("Vendor", "UspsApi", array("file" => "UspsApi.php"));
     $u = new UspsApi();
     //process_weight
     $weight = 0;
     foreach ($record['CanteenOrderItem'] as $item) {
         $weight += $item['weight'];
     }
     $record['CanteenShippingRecord']['weight'] = $record['UserAddress']['weight'] = $weight;
     $record['UserAddress']['weight_oz'] = floor($record['UserAddress']['weight'] * 16);
     $record['UserAddress']['shipping_method'] = $record['CanteenShippingRecord']['shipping_method'] = "First Class";
     //create the canteen shipping record items
     $items = $u->processCanteenItems($record['CanteenOrderItem']);
     $res = $u->ship_int($record['UserAddress'], $items);
     $xml = simplexml_load_string($res);
     if (isset($xml->BarcodeNumber)) {
         //save the label image
         $this->process_usps_label($xml->LabelImage, $record['CanteenShippingRecord']['id']);
         $record['CanteenShippingRecord']['shipping_status'] = "processing";
         $record['CanteenShippingRecord']['shipment_number'] = $xml->BarcodeNumber;
         $record['CanteenShippingRecord']['carrier_name'] = "USPS";
         $this->create();
         $this->id = $record['CanteenShippingRecord']['id'];
         $this->save($record['CanteenShippingRecord']);
         $record = $this->read();
     } else {
         SysMsg::add(array("category" => "USPSError", "crontab" => 1, "from" => "CanteenShippingRecord", "title" => "USPS INT Shipping Error: CanteenShippingRecordID: <a href='/canteen_shipping_records/edit/{$record['CanteenShippingRecord']['id']}' target='_blank'>" . $record['CanteenShippingRecord']['id'] . "</a>", "message" => serialize($xml->asXml())));
     }
     return $record;
 }