EasyPost\Shipment::create PHP Method

create() public static method

create a shipment
public static create ( mixed $params = null, string $apiKey = null ) : mixed
$params mixed
$apiKey string
return mixed
    public static function create($params = null, $apiKey = null)
    {
        if (!isset($params['shipment']) || !is_array($params['shipment'])) {
            $clone = $params;
            unset($params);
            $params['shipment'] = $clone;
        }
        return self::_create(get_class(), $params, $apiKey);
    }

Usage Example

コード例 #1
0
 protected function _processShipping()
 {
     // Required Values
     $requiredValues = array('Length', 'Width', 'Height', 'Weight', 'Packer', 'NumTrees', 'ShipName', 'ShipAddress', 'ShipCity', 'ShipState', 'ShipZip', 'Phone');
     // All variables passed
     $request = Request::all();
     // Array of missing fields
     $return['errorFields'] = array();
     foreach ($requiredValues as $val) {
         if (empty($request[$val])) {
             $return['errorFields'][] = $val;
         }
     }
     // IF fields are missing
     if (!empty($return['errorFields'])) {
         return $return;
     }
     // Connect to API
     \EasyPost\EasyPost::setApiKey(config('app.easyPostAPIKey'));
     $toData = array("name" => $request['ShipName'], "street1" => $request['ShipAddress'], "street2" => $request['ShipAddress2'], "city" => $request['ShipCity'], "state" => $request['ShipState'], "zip" => $request['ShipZip'], "phone" => $request['Phone']);
     $toAddress = \EasyPost\Address::create($toData);
     // Build from address object
     $fromData = array("company" => config('app.fromCompany'), "street1" => config('app.fromStreet1'), "city" => config('app.fromCity'), "state" => config('app.fromState'), "zip" => config('app.fromZip'));
     $fromAddress = \EasyPost\Address::create($fromData);
     // Build parcel object
     $parcelData = array("length" => $request['Length'], "width" => $request['Width'], "height" => $request['Height'], "weight" => $request['Weight']);
     $parcel = \EasyPost\Parcel::create($parcelData);
     // Create shipment object
     $shipment = \EasyPost\Shipment::create(array("to_address" => $toAddress, "from_address" => $fromAddress, "parcel" => $parcel));
     return $shipment->lowest_rate();
 }
All Usage Examples Of EasyPost\Shipment::create