Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatthefork/e657cab8dc192c20df2b to your computer and use it in GitHub Desktop.
Save whatthefork/e657cab8dc192c20df2b to your computer and use it in GitHub Desktop.
UPS Freight API dummy class
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class FreightRatesAndService {
protected $username = '';
protected $password = '';
protected $accessKey = '';
protected $sandbox = '';
protected $endpointUrl = '';
protected static $endpointUrls = array(
'sandbox' => 'https://wwwcie.ups.com/webservices/FreightRate',
'production' => 'https://onlinetools.ups.com/webservices/FreightRate'
);
public $response = null;
public $errors = array();
public $exception = null;
public $lastRequestParams = array();
public function __construct($username, $password, $accessKey, $sandbox = null) {
$this->username = $username;
$this->password = $password;
$this->accessKey = $accessKey;
$this->sandbox = $sandbox;
if ($this->sandbox) {
$this->endpointUrl = self::$endpointUrls['sandbox'];
}
else {
$this->endpointUrl = self::$endpointUrls['production'];
}
$this->response = new stdClass();
}
static public function isOversizedOrOverweightForShipping($length, $width, $height, $weight) {
$ci =& get_instance();
$ci->config->load('shipping',true);
if ($length > $ci->config->item('shipping_max_length','shipping')) {
return true;
}
else if ($weight > $ci->config->item('shipping_max_weight','shipping')) {
return true;
}
else if (($length + $width * 2 + $height * 2) > $ci->config->item('shipping_max_length_and_grith','shipping')) {
return true;
}
else {
return false;
}
}
public function getFreightRate() {
$request['Request'] = array(
'RequestOption' => 'Ground'
);
$request['ShipFrom'] = array(
'Name' => 'Good Incorporation',
'Address' => array(
'AddressLine' => '',
'City' => '',
'StateProvinceCode' => 'NY',
'PostalCode' => '10009',
'CountryCode' => 'US',
)
);
$request['ShipTo'] = array(
'Name' => 'Sony Company Incorporation',
'Address' => array(
'AddressLine' => 'Knickerbocker Ave',
'City' => 'Brooklyn',
'StateProvinceCode' => 'NY',
'PostalCode' => '11237',
'CountryCode' => 'US',
)
);
$request['PaymentInformation'] = array(
'ShipmentBillingOption' => array(
'Code' => '10',
'Description' => 'PREPAID'
),
'Payer' => array(
'Name' => 'Sony Company Incorporation',
'Address' => array(
'AddressLine' => 'Knickerbocker Ave',
'City' => 'Brooklyn',
'StateProvinceCode' => 'NY',
'PostalCode' => '11237',
'CountryCode' => 'US',
)
)
);
$request['Service'] = array(
'Code' => '308',
'Description' => 'UPS Freight LTL'
);
$request['HandlingUnitOne'] = array(
'Quantity' => '20',
'Type' => array(
'Code' => 'PLT',
)
);
$request['Commodity'] = array(
'CommodityID' => '',
'Description' => 'No Description',
'Weight' => array(
'UnitOfMeasurement' => array
(
'Code' => 'LBS',
'Description' => 'Pounds'
),
'Value' => '10'
),
/*'Dimensions' => array(
'UnitOfMeasurement' => array(
'Code' => 'IN',
'Description' => 'Inches'
),
'Length' => '23',
'Width' => '17',
'Height' => '45'
),*/
'NumberOfPieces' => '1',
'PackagingType' => array(
'Code' => 'BAG',
'Description' => 'BAG'
),
//'DangerousGoodsIndicator' => '',
/*'CommodityValue' => array(
'CurrencyCode' => 'USD',
'MonetaryValue' => '100'
),*/
'FreightClass' => '60',
'NMFCCommodityCode' => ''
);
/*
$shipmentserviceoptions['PickupOptions'] = array
(
'HolidayPickupIndicator' => '',
'InsidePickupIndicator' => '',
'ResidentialPickupIndicator' => '',
'WeekendPickupIndicator' => '',
'LiftGateRequiredIndicator' => ''
);
$shipmentserviceoptions['OverSeasLeg'] = array
(
'Dimensions' => array
(
'Volume' => '20',
'UnitOfMeasurement' => array
(
'Code' => 'CF',
'Description' => 'String'
)
),
'Value' => array
(
'Cube' => array
(
'CurrencyCode' => 'USD',
'MonetaryValue' => '5670'
)
),
'COD' => array
(
'CODValue' => array
(
'CurrencyCode' => 'USD',
'MonetaryValue' => '363'
),
'CODPaymentMethod' => array
(
'Code' => 'M',
'Description' => 'For Company Check'
),
'CODBillingOption' => array
(
'Code' => '01',
'Description' => 'Prepaid'
),
'RemitTo' => array
(
'Name' => 'RemitToSomebody',
'Address' => array
(
'AddressLine' => '640 WINTERS AVE',
'City' => 'PARAMUS',
'StateProvinceCode' => 'NJ',
'PostalCode' => '07652',
'CountryCode' => 'US'
),
'AttentionName' => 'C J Parker'
)
),
'DangerousGoods' => array
(
'Name' => 'Very Safe',
'Phone' => array
(
'Number' => '453563321',
'Extension' => '1111'
),
'TransportationMode' => array
(
'Code' => 'CARGO',
'Description' => 'Cargo Mode'
)
),
'SortingAndSegregating' => array
(
'Quantity' => '23452'
),
'CustomsValue' => array
(
'CurrencyCode' => 'USD',
'MonetaryValue' => '23457923'
),
'HandlingCharge' => array
(
'Amount' => array
(
'CurrencyCode' => 'USD',
'MonetaryValue' => '450'
)
)
);
$request['ShipmentServiceOptions'] = $shipmentserviceoptions;
*/
$this->lastRequestParams = $request;
return $this->request($request);
}
protected function request($request) {
try {
// initialize soap client
$client = new SoapClient(dirname(__FILE__).'/wsdl/FreightRate.wsdl', array(
'soap_version' => 'SOAP_1_1', // use soap 1.1 client
'trace' => 1
));
//set endpoint url
$client->__setLocation($this->endpointUrl);
//create soap header
$UPSSecurity = array(
'UsernameToken' => array(
'Username' => $this->username,
'Password' => $this->password
),
'ServiceAccessToken' => array(
'AccessLicenseNumber' => $this->accessKey
)
);
$header = new SoapHeader('http://www.ups.com/XMLSchema/XOLTWS/UPSS/v1.0','UPSSecurity',$UPSSecurity);
$client->__setSoapHeaders($header);
//get response
$this->response = $client->__soapCall('ProcessFreightRate' ,array($request));
//print_r($client->__getLastResponse());
return true;
}
catch(Exception $e) {
$this->exception = $e;
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment