EasyPost\Address::create_and_verify PHP Method

create_and_verify() public static method

create and verify an address
public static create_and_verify ( mixed $params = null, string $apiKey = null ) : mixed
$params mixed
$apiKey string
return mixed
    public static function create_and_verify($params = null, $apiKey = null)
    {
        $class = get_class();
        if (!isset($params['address']) || !is_array($params['address'])) {
            $clone = $params;
            unset($params);
            $params['address'] = $clone;
        }
        $requestor = new Requestor($apiKey);
        $url = self::classUrl($class);
        list($response, $apiKey) = $requestor->request('post', $url . '/create_and_verify', $params);
        if (isset($response['address'])) {
            $verified_address = Util::convertToEasyPostObject($response['address'], $apiKey);
            if (!empty($response['message'])) {
                $verified_address->message = $response['message'];
                $verified_address->_immutableValues[] = 'message';
            }
            return $verified_address;
        } else {
            return Util::convertToEasyPostObject($response, $apiKey);
        }
    }

Usage Example

Beispiel #1
0
 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();
     }
 }
All Usage Examples Of EasyPost\Address::create_and_verify