File manager - Edit - /home/opticamezl/www/newok/pop-shipping.tar
Back
composer.json 0000604 00000001625 15173165744 0007303 0 ustar 00 { "name": "popphp/pop-shipping", "description": "Pop Shipping Component for Pop PHP Framework", "keywords": [ "shipping", "shipping rates", "calculate shipping rates", "php", "pop", "pop php" ], "homepage": "http://www.popphp.org/", "license": "New BSD", "authors": [ { "name": "Nick Sagona", "email": "dev@nolainteractive.com", "homepage": "http://www.nolainteractive.com/" } ], "require": { "php": ">=5.4.0" }, "require-dev": { "phpunit/phpunit": "4.6.*" }, "autoload": { "psr-4": { "Pop\\Shipping\\": "src/" } }, "autoload-dev": { "psr-4": { "Pop\\Shipping\\Test\\": "tests/" } }, "extra": { "branch-alias": { "dev-master": "2.1.x-dev" } } } LICENSE.TXT 0000604 00000002765 15173165744 0006252 0 ustar 00 New BSD License Copyright (c) 2009-2016, NOLA Interactive, LLC. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of NOLA Interactive, LLC, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY NOLA INTERACTIVE, LLC, ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NOLA INTERACTIVE, LLC BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. src/Exception.php 0000604 00000001356 15173165744 0010020 0 ustar 00 <?php /** * Pop PHP Framework (http://www.popphp.org/) * * @link https://github.com/popphp/popphp-framework * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License */ /** * @namespace */ namespace Pop\Shipping; /** * Shipping exception class * * @category Pop * @package Pop_Shipping * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License * @version 2.1.0 */ class Exception extends \Exception {} src/Shipping.php 0000604 00000006602 15173165744 0007642 0 ustar 00 <?php /** * Pop PHP Framework (http://www.popphp.org/) * * @link https://github.com/popphp/popphp-framework * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License */ /** * @namespace */ namespace Pop\Shipping; /** * Shipping class * * @category Pop * @package Pop_Shipping * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License * @version 2.1.0 */ class Shipping { /** * Shipping adapter * @var mixed */ protected $adapter = null; /** * Constructor * * Instantiate the shipping object * * @param Adapter\AbstractAdapter $adapter * @return Shipping */ public function __construct(Adapter\AbstractAdapter $adapter) { $this->adapter = $adapter; } /** * Access the adapter * * @return Adapter\AbstractAdapter */ public function adapter() { return $this->adapter; } /** * Set ship to * * @param array $shipTo * @return self */ public function shipTo(array $shipTo) { $this->adapter->shipTo($shipTo); return $this; } /** * Set ship from * * @param array $shipFrom * @return self */ public function shipFrom(array $shipFrom) { $this->adapter->shipFrom($shipFrom); return $this; } /** * Set dimensions * * @param array $dimensions * @param string $unit * @return self */ public function setDimensions(array $dimensions, $unit = null) { $this->adapter->setDimensions($dimensions, $unit); return $this; } /** * Set dimensions * * @param string $weight * @param string $unit * @return self */ public function setWeight($weight, $unit = null) { $this->adapter->setWeight($weight, $unit); return $this; } /** * Send transaction * * @param boolean $verifyPeer * @return void */ public function send($verifyPeer = true) { $this->adapter->send($verifyPeer); } /** * Return whether the transaction is success * * @return boolean */ public function isSuccess() { return $this->adapter->isSuccess(); } /** * Return whether the transaction is an error * * @return boolean */ public function isError() { return $this->adapter->isError(); } /** * Get response * * @return object */ public function getResponse() { return $this->adapter->getResponse(); } /** * Get response code * * @return int */ public function getResponseCode() { return $this->adapter->getResponseCode(); } /** * Get response message * * @return string */ public function getResponseMessage() { return $this->adapter->getResponseMessage(); } /** * Get service rates * * @return array */ public function getRates() { return $this->adapter->getRates(); } } src/Adapter/AdapterInterface.php 0000604 00000004315 15173165744 0012641 0 ustar 00 <?php /** * Pop PHP Framework (http://www.popphp.org/) * * @link https://github.com/popphp/popphp-framework * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License */ /** * @namespace */ namespace Pop\Shipping\Adapter; /** * Shipping adapter interface * * @category Pop * @package Pop_Shipping * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License * @version 2.1.0 */ interface AdapterInterface { /** * Set ship to * * @param array $shipTo * @return mixed */ public function shipTo(array $shipTo); /** * Set ship from * * @param array $shipFrom * @return mixed */ public function shipFrom(array $shipFrom); /** * Set dimensions * * @param array $dimensions * @param string $unit * @return mixed */ public function setDimensions(array $dimensions, $unit = null); /** * Set dimensions * * @param string $weight * @param string $unit * @return mixed */ public function setWeight($weight, $unit = null); /** * Send transaction * * @param boolean $verifyPeer * @return void */ public function send($verifyPeer = true); /** * Return whether the transaction is a success * * @return boolean */ public function isSuccess(); /** * Return whether the transaction is an error * * @return boolean */ public function isError(); /** * Get response object * * @return object */ public function getResponse(); /** * Get response code * * @return int */ public function getResponseCode(); /** * Get response message * * @return string */ public function getResponseMessage(); /** * Get service rates * * @return array */ public function getRates(); } src/Adapter/Fedex.php 0000604 00000023656 15173165744 0010504 0 ustar 00 <?php /** * Pop PHP Framework (http://www.popphp.org/) * * @link https://github.com/popphp/popphp-framework * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License */ /** * @namespace */ namespace Pop\Shipping\Adapter; /** * FedEx shipping adapter class * * @category Pop * @package Pop_Shipping * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License * @version 2.1.0 */ class Fedex extends AbstractAdapter { /** * SOAP Client * @var \SoapClient */ protected $client = null; /** * FedEx WSDL File * @var string */ protected $wsdl = null; /** * Request array * @var array */ protected $request = null; /** * Ship to fields * @var array */ protected $shipTo = [ 'Contact' => [ 'PersonName' => '', 'CompanyName' => '', 'PhoneNumber' => '' ], 'Address' => [ 'StreetLines' => [], 'City' => '', 'StateOrProvinceCode' => '', 'PostalCode' => '', 'CountryCode' => '', 'Residential' => false ] ]; /** * Ship from fields * @var array */ protected $shipFrom = [ 'Contact' => [ 'PersonName' => '', 'CompanyName' => '', 'PhoneNumber' => '' ], 'Address' => [ 'StreetLines' => [], 'City' => '', 'StateOrProvinceCode' => '', 'PostalCode' => '', 'CountryCode' => '' ] ]; /** * Package dimensions * @var array */ protected $dimensions = [ 'Length' => null, 'Width' => null, 'Height' => null, 'Units' => 'IN' ]; /** * Package weight * @var array */ protected $weight = [ 'Value' => null, 'Units' => 'LB' ]; /** * Services * @var array */ protected static $services = [ 'FIRST_OVERNIGHT' => '1st Overnight', 'PRIORITY_OVERNIGHT' => 'Priority Overnight', 'STANDARD_OVERNIGHT' => 'Standard Overnight', 'FEDEX_2_DAY_AM' => 'FedEx 2 Day AM', 'FEDEX_2_DAY' => 'FedEx 2 Day', 'FEDEX_EXPRESS_SAVER' => 'FedEx Express Saver', 'FEDEX_GROUND' => 'FedEx Ground' ]; /** * Constructor * * Method to instantiate an FedEx shipping adapter object * * @param string $key * @param string $password * @param string $account * @param string $meter * @param string $wsdl * @return Fedex */ public function __construct($key, $password, $account, $meter, $wsdl) { $this->wsdl = $wsdl; ini_set('soap.wsdl_cache_enabled', '0'); $this->client = new \SoapClient($this->wsdl, ['trace' => 1]); $this->request['WebAuthenticationDetail'] = [ 'UserCredential' =>[ 'Key' => $key, 'Password' => $password ] ]; $this->request['ClientDetail'] = [ 'AccountNumber' => $account, 'MeterNumber' => $meter ]; $this->request['TransactionDetail'] = [ 'CustomerTransactionId' => ' *** Rate Request v14 using PHP ***' ]; $this->request['Version'] = [ 'ServiceId' => 'crs', 'Major' => '14', 'Intermediate' => '0', 'Minor' => '0' ]; $this->request['RequestedShipment']['RateRequestTypes'] = 'ACCOUNT'; $this->request['RequestedShipment']['RateRequestTypes'] = 'LIST'; $this->request['RequestedShipment']['PackageCount'] = '1'; } /** * Static method to get the services * * @return array */ public static function getServices() { return self::$services; } /** * Set ship to * * @param array $shipTo * @return mixed */ public function shipTo(array $shipTo) { foreach ($shipTo as $key => $value) { if (stripos($key, 'person') !== false) { $this->shipTo['Contact']['PersonName'] = $value; } else if (stripos($key, 'company') !== false) { $this->shipTo['Contact']['CompanyName'] = $value; } else if (stripos($key, 'phone') !== false) { $this->shipTo['Contact']['PhoneNumber'] = $value; } else if (stripos($key, 'address') !== false) { $this->shipTo['Address']['StreetLines'][] = $value; } else if (strtolower($key) == 'city') { $this->shipTo['Address']['City'] = $value; } else if ((stripos($key, 'state') !== false) || (stripos($key, 'province') !== false)) { $this->shipTo['Address']['StateOrProvinceCode'] = $value; } else if ((strtolower($key) == 'postalcode') || (strtolower($key) == 'zipcode') || (strtolower($key) == 'zip')) { $this->shipTo['Address']['PostalCode'] = $value; } else if ((strtolower($key) == 'countrycode') || (strtolower($key) == 'country')) { $this->shipTo['Address']['CountryCode'] = $value; } else if (strtolower($key) == 'residential') { $this->shipTo['Address']['Residential'] = $value; } } $this->request['RequestedShipment']['Recipient'] = $this->shipTo; } /** * Set ship from * * @param array $shipFrom * @return mixed */ public function shipFrom(array $shipFrom) { foreach ($shipFrom as $key => $value) { if (stripos($key, 'person') !== false) { $this->shipFrom['Contact']['PersonName'] = $value; } else if (stripos($key, 'company') !== false) { $this->shipFrom['Contact']['CompanyName'] = $value; } else if (stripos($key, 'phone') !== false) { $this->shipFrom['Contact']['PhoneNumber'] = $value; } else if (stripos($key, 'address') !== false) { $this->shipFrom['Address']['StreetLines'][] = $value; } else if (strtolower($key) == 'city') { $this->shipFrom['Address']['City'] = $value; } else if ((stripos($key, 'state') !== false) || (stripos($key, 'province') !== false)) { $this->shipFrom['Address']['StateOrProvinceCode'] = $value; } else if ((strtolower($key) == 'postalcode') || (strtolower($key) == 'zipcode') || (strtolower($key) == 'zip')) { $this->shipFrom['Address']['PostalCode'] = $value; } else if ((strtolower($key) == 'countrycode') || (strtolower($key) == 'country')) { $this->shipFrom['Address']['CountryCode'] = $value; } else if (strtolower($key) == 'residential') { $this->shipFrom['Address']['Residential'] = $value; } } $this->request['RequestedShipment']['Shipper'] = $this->shipFrom; } /** * Set dimensions * * @param array $dimensions * @param string $unit * @return mixed */ public function setDimensions(array $dimensions, $unit = null) { if ((null !== $unit) && (($unit == 'IN') || ($unit == 'CM'))) { $this->dimensions['Units'] = $unit; } foreach ($dimensions as $key => $value) { if (strtolower($key) == 'length') { $this->dimensions['Length'] = $value; } else if (strtolower($key) == 'width') { $this->dimensions['Width'] = $value; } else if (strtolower($key) == 'height') { $this->dimensions['Height'] = $value; } } } /** * Set dimensions * * @param string $weight * @param string $unit * @return mixed */ public function setWeight($weight, $unit = null) { if ((null !== $unit) && (($unit == 'LB') || ($unit == 'KG'))) { $this->weight['Units'] = $unit; } $this->weight['Value'] = $weight; } /** * Send transaction * * @return void */ public function send() { $this->request['RequestedShipment']['RequestedPackageLineItems'] = [ 'SequenceNumber' => 1, 'GroupPackageCount' => 1, 'Weight' => $this->weight ]; if ((null !== $this->dimensions['Length']) && (null !== $this->dimensions['Width']) && (null !== $this->dimensions['Height'])) { $this->request['RequestedShipment']['RequestedPackageLineItems']['Dimensions'] = $this->dimensions; } $this->response = $this->client->getRates($this->request); $this->responseCode = (int)$this->response->Notifications->Code; $this->responseMessage = (string)$this->response->Notifications->Message; if ($this->responseCode == 0) { foreach ($this->response->RateReplyDetails as $rate) { $this->rates[self::$services[(string)$rate->ServiceType]] = number_format((string)$rate->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2); } $this->rates = array_reverse($this->rates, true); } } /** * Return whether the transaction is a success * * @return boolean */ public function isSuccess() { return ($this->responseCode == 0); } /** * Return whether the transaction is an error * * @return boolean */ public function isError() { return ($this->responseCode != 0); } } src/Adapter/Ups.php 0000604 00000042622 15173165744 0010212 0 ustar 00 <?php /** * Pop PHP Framework (http://www.popphp.org/) * * @link https://github.com/popphp/popphp-framework * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License */ /** * @namespace */ namespace Pop\Shipping\Adapter; /** * UPS shipping adapter class * * @category Pop * @package Pop_Shipping * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License * @version 2.1.0 */ class Ups extends AbstractAdapter { /** * API URL * @var string */ protected $url = 'https://wwwcie.ups.com/ups.app/xml/Rate'; /** * User ID * @var string */ protected $userId = null; /** * Access Request XML * @var string */ protected $accessRequest = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<AccessRequest xml:lang=\"en-US\">"; /** * Rate Request XML * @var string */ protected $rateRequest = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<RatingServiceSelectionRequest>"; /** * Pickup Types * @var array */ protected static $pickupTypes = [ '01' => 'Daily Pickup', '03' => 'Customer Counter', '06' => 'One Time Pickup', '07' => 'On Call Air', '19' => 'Letter Center', '20' => 'Air Service Center' ]; /** * Pickup Types * @var array */ protected static $packagingTypes = [ '00' => 'UNKNOWN', '01' => 'UPS Letter', '02' => 'Package', '03' => 'Tube', '04' => 'Pak', '21' => 'Express Box', '24' => '25KG Box', '25' => '10KG Box', '30' => 'Pallet', '2a' => 'Small Express Box', '2b' => 'Medium Express Box', '2c' => 'Large Express Box' ]; /** * Services * @var array */ protected static $services = [ '14' => 'Next Day Air Early AM', '01' => 'Next Day Air', '13' => 'Next Day Air Saver', '59' => '2nd Day Air AM', '02' => '2nd Day Air', '12' => '3 Day Select', '03' => 'Ground', '11' => 'Standard', '07' => 'Worldwide Express', '54' => 'Worldwide Express Plus', '08' => 'Worldwide Expedited', '65' => 'Saver' ]; /** * Ship to fields * @var array */ protected $shipTo = [ 'CompanyName' => null, 'AddressLine1' => null, 'AddressLine2' => null, 'AddressLine3' => null, 'City' => null, 'PostalCode' => null, 'CountryCode' => null ]; /** * Ship from fields * @var array */ protected $shipFrom = [ 'CompanyName' => null, 'AddressLine1' => null, 'AddressLine2' => null, 'AddressLine3' => null, 'City' => null, 'PostalCode' => null, 'CountryCode' => null ]; /** * Pickup type * @var string */ protected $pickupType = '01'; /** * Package type * @var string */ protected $packageType = '02'; /** * Service * @var string */ protected $service = '03'; /** * Package dimensions * @var array */ protected $dimensions = [ 'UnitOfMeasurement' => 'IN', 'Length' => null, 'Width' => null, 'Height' => null ]; /** * Package weight * @var array */ protected $weight = [ 'UnitOfMeasurement' => 'LBS', 'Weight' => null ]; /** * Constructor * * Method to instantiate an UPS shipping adapter object * * @param string $accessKey * @param string $userId * @param string $password * @return Ups */ public function __construct($accessKey, $userId, $password) { $this->userId = $userId; $this->accessRequest .= PHP_EOL . ' <AccessLicenseNumber>' . $accessKey . '</AccessLicenseNumber>'; $this->accessRequest .= PHP_EOL . ' <UserId>' . $userId . '</UserId>'; $this->accessRequest .= PHP_EOL . ' <Password>' . $password . '</Password>'; $this->accessRequest .= PHP_EOL . '</AccessRequest>' . PHP_EOL; } /** * Static method to get the pickup types * * @return array */ public static function getPickupTypes() { return self::$pickupTypes; } /** * Static method to get the packaging types * * @return array */ public static function getPackagingTypes() { return self::$packagingTypes; } /** * Static method to get the services * * @return array */ public static function getServices() { return self::$services; } /** * Set pickup type * * @param string $code * @throws Exception * @return void */ public function setPickup($code) { if (!array_key_exists($code, self::$pickupTypes)) { throw new Exception('Error: That pickup code does not exist.'); } $this->pickupType = $code; } /** * Set package type * * @param string $code * @throws Exception * @return void */ public function setPackage($code) { if (!array_key_exists($code, self::$packagingTypes)) { throw new Exception('Error: That package code does not exist.'); } $this->packageType = $code; } /** * Set service * * @param string $code * @throws Exception * @return void */ public function setService($code) { if (!array_key_exists($code, self::$services)) { throw new Exception('Error: That service code does not exist.'); } $this->service = $code; } /** * Set ship to * * @param array $shipTo * @return void */ public function shipTo(array $shipTo) { foreach ($shipTo as $key => $value) { if (stripos($key, 'company') !== false) { $this->shipTo['CompanyName'] = $value; } else if ((strtolower($key) == 'addressline1') || (strtolower($key) == 'address1') || (strtolower($key) == 'address')) { $this->shipTo['AddressLine1'] = $value; } else if ((strtolower($key) == 'addressline2') || (strtolower($key) == 'address2')) { $this->shipTo['AddressLine2'] = $value; } else if ((strtolower($key) == 'addressline3') || (strtolower($key) == 'address3')) { $this->shipTo['AddressLine3'] = $value; } else if (strtolower($key) == 'city') { $this->shipTo['City'] = $value; } else if ((strtolower($key) == 'postalcode') || (strtolower($key) == 'zipcode') || (strtolower($key) == 'zip')) { $this->shipTo['PostalCode'] = $value; } else if ((strtolower($key) == 'countrycode') || (strtolower($key) == 'country')) { $this->shipTo['CountryCode'] = $value; } } } /** * Set ship from * * @param array $shipFrom * @return void */ public function shipFrom(array $shipFrom) { foreach ($shipFrom as $key => $value) { if (stripos($key, 'company') !== false) { $this->shipFrom['CompanyName'] = $value; } else if ((strtolower($key) == 'addressline1') || (strtolower($key) == 'address1') || (strtolower($key) == 'address')) { $this->shipFrom['AddressLine1'] = $value; } else if ((strtolower($key) == 'addressline2') || (strtolower($key) == 'address2')) { $this->shipFrom['AddressLine2'] = $value; } else if ((strtolower($key) == 'addressline3') || (strtolower($key) == 'address3')) { $this->shipFrom['AddressLine3'] = $value; } else if (strtolower($key) == 'city') { $this->shipFrom['City'] = $value; } else if ((strtolower($key) == 'postalcode') || (strtolower($key) == 'zipcode') || (strtolower($key) == 'zip')) { $this->shipFrom['PostalCode'] = $value; } else if ((strtolower($key) == 'countrycode') || (strtolower($key) == 'country')) { $this->shipFrom['CountryCode'] = $value; } } } /** * Set dimensions * * @param array $dimensions * @param string $unit * @return void */ public function setDimensions(array $dimensions, $unit = null) { if ((null !== $unit) && (($unit == 'IN') || ($unit == 'CM'))) { $this->dimensions['UnitOfMeasurement'] = $unit; } foreach ($dimensions as $key => $value) { if (strtolower($key) == 'length') { $this->dimensions['Length'] = $value; } else if (strtolower($key) == 'width') { $this->dimensions['Width'] = $value; } else if (strtolower($key) == 'height') { $this->dimensions['Height'] = $value; } } } /** * Set dimensions * * @param string $weight * @param string $unit * @return void */ public function setWeight($weight, $unit = null) { if ((null !== $unit) && (($unit == 'LBS') || ($unit == 'KGS'))) { $this->weight['UnitOfMeasurement'] = $unit; } $this->weight['Weight'] = $weight; } /** * Send transaction * * @param boolean $verifyPeer * @return void */ public function send($verifyPeer = true) { $this->buildRateRequest(); $options = [ CURLOPT_HEADER => false, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $this->accessRequest . $this->rateRequest, CURLOPT_URL => $this->url, CURLOPT_RETURNTRANSFER => true ]; if (!$verifyPeer) { $options[CURLOPT_SSL_VERIFYPEER] = false; } $curl = curl_init(); curl_setopt_array($curl, $options); $this->response = simplexml_load_string($this->parseResponse($curl)); $this->responseCode = (int)$this->response->Response->ResponseStatusCode; if ($this->responseCode == 1) { $this->responseMessage = (string)$this->response->Response->ResponseStatusDescription; foreach ($this->response->RatedShipment as $rate) { $this->rates[self::$services[(string)$rate->Service->Code]] = (string)$rate->TotalCharges->MonetaryValue; } } else { $this->responseCode = (string)$this->response->Response->Error->ErrorCode; $this->responseMessage = (string)$this->response->Response->Error->ErrorDescription; } } /** * Return whether the transaction is a success * * @return boolean */ public function isSuccess() { return ($this->responseCode == 1); } /** * Return whether the transaction is an error * * @return boolean */ public function isError() { return ($this->responseCode != 1); } /** * Build rate request * * @return void */ protected function buildRateRequest() { $this->rateRequest .= PHP_EOL . ' <Request>'; $this->rateRequest .= PHP_EOL . ' <TransactionReference>'; $this->rateRequest .= PHP_EOL . ' <CustomerContext>Rating and Service</CustomerContext>'; $this->rateRequest .= PHP_EOL . ' <XpciVersion>1.0</XpciVersion>'; $this->rateRequest .= PHP_EOL . ' </TransactionReference>'; $this->rateRequest .= PHP_EOL . ' <RequestAction>Rate</RequestAction>'; $this->rateRequest .= PHP_EOL . ' <RequestOption>Shop</RequestOption>'; $this->rateRequest .= PHP_EOL . ' </Request>'; $this->rateRequest .= PHP_EOL . ' <PickupType>'; $this->rateRequest .= PHP_EOL . ' <Code>' . $this->pickupType . '</Code>'; $this->rateRequest .= PHP_EOL . ' <Description>' . self::$pickupTypes[$this->pickupType] . '</Description>'; $this->rateRequest .= PHP_EOL . ' </PickupType>'; $this->rateRequest .= PHP_EOL . ' <Shipment>'; $this->rateRequest .= PHP_EOL . ' <Description>Rate</Description>'; $this->rateRequest .= PHP_EOL . ' <Shipper>'; $this->rateRequest .= PHP_EOL . ' <ShipperNumber>' . $this->userId . '</ShipperNumber>'; $this->rateRequest .= PHP_EOL . ' <Address>'; foreach ($this->shipFrom as $key => $value) { if ($key !== 'CompanyName') { if (null !== $value) { $this->rateRequest .= PHP_EOL . ' <' . $key . '>' . $value . '</' . $key . '>'; } else { $this->rateRequest .= PHP_EOL . ' <' . $key . ' />'; } } } $this->rateRequest .= PHP_EOL . ' </Address>'; $this->rateRequest .= PHP_EOL . ' </Shipper>'; $this->rateRequest .= PHP_EOL . ' <ShipTo>'; if (null !== $this->shipTo['CompanyName']) { $this->rateRequest .= PHP_EOL . ' <CompanyName>' . $this->shipTo['CompanyName'] . '</CompanyName>'; } $this->rateRequest .= PHP_EOL . ' <Address>'; foreach ($this->shipTo as $key => $value) { if ($key !== 'CompanyName') { if (null !== $value) { $this->rateRequest .= PHP_EOL . ' <' . $key . '>' . $value . '</' . $key . '>'; } else { $this->rateRequest .= PHP_EOL . ' <' . $key . ' />'; } } } $this->rateRequest .= PHP_EOL . ' </Address>'; $this->rateRequest .= PHP_EOL . ' </ShipTo>'; $this->rateRequest .= PHP_EOL . ' <ShipFrom>'; if (null !== $this->shipFrom['CompanyName']) { $this->rateRequest .= PHP_EOL . ' <CompanyName>' . $this->shipFrom['CompanyName'] . '</CompanyName>'; } $this->rateRequest .= PHP_EOL . ' <Address>'; foreach ($this->shipFrom as $key => $value) { if ($key !== 'CompanyName') { if (null !== $value) { $this->rateRequest .= PHP_EOL . ' <' . $key . '>' . $value . '</' . $key . '>'; } else { $this->rateRequest .= PHP_EOL . ' <' . $key . ' />'; } } } $this->rateRequest .= PHP_EOL . ' </Address>'; $this->rateRequest .= PHP_EOL . ' </ShipFrom>'; $this->rateRequest .= PHP_EOL . ' <Service>'; $this->rateRequest .= PHP_EOL . ' <Code>' . $this->service . '</Code>'; $this->rateRequest .= PHP_EOL . ' <Description>' . self::$services[$this->service] . '</Description>'; $this->rateRequest .= PHP_EOL . ' </Service>'; $this->rateRequest .= PHP_EOL . ' <Package>'; $this->rateRequest .= PHP_EOL . ' <PackagingType>'; $this->rateRequest .= PHP_EOL . ' <Code>' . $this->packageType . '</Code>'; $this->rateRequest .= PHP_EOL . ' <Description>' . self::$packagingTypes[$this->packageType] . '</Description>'; $this->rateRequest .= PHP_EOL . ' </PackagingType>'; $this->rateRequest .= PHP_EOL . ' <Description>Rate</Description>'; if ((null !== $this->dimensions['Length']) && (null !== $this->dimensions['Width']) && (null !== $this->dimensions['Height'])) { $this->rateRequest .= PHP_EOL . ' <Dimensions>'; $this->rateRequest .= PHP_EOL . ' <UnitOfMeasurement>'; $this->rateRequest .= PHP_EOL . ' <Code>' . $this->dimensions['UnitOfMeasurement'] . '</Code>'; $this->rateRequest .= PHP_EOL . ' </UnitOfMeasurement>'; $this->rateRequest .= PHP_EOL . ' <Length>' . $this->dimensions['Length'] . '</Length>'; $this->rateRequest .= PHP_EOL . ' <Width>' . $this->dimensions['Width'] . '</Width>'; $this->rateRequest .= PHP_EOL . ' <Height>' . $this->dimensions['Height'] . '</Height>'; $this->rateRequest .= PHP_EOL . ' </Dimensions>'; } $this->rateRequest .= PHP_EOL . ' <PackageWeight>'; $this->rateRequest .= PHP_EOL . ' <UnitOfMeasurement>'; $this->rateRequest .= PHP_EOL . ' <Code>' . $this->weight['UnitOfMeasurement'] . '</Code>'; $this->rateRequest .= PHP_EOL . ' </UnitOfMeasurement>'; $this->rateRequest .= PHP_EOL . ' <Weight>' . $this->weight['Weight'] . '</Weight>'; $this->rateRequest .= PHP_EOL . ' </PackageWeight>'; $this->rateRequest .= PHP_EOL . ' </Package>'; $this->rateRequest .= PHP_EOL . ' </Shipment>'; $this->rateRequest .= PHP_EOL . '</RatingServiceSelectionRequest>' . PHP_EOL; } } src/Adapter/Usps.php 0000604 00000021663 15173165744 0010377 0 ustar 00 <?php /** * Pop PHP Framework (http://www.popphp.org/) * * @link https://github.com/popphp/popphp-framework * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License */ /** * @namespace */ namespace Pop\Shipping\Adapter; /** * USPS shipping adapter class * * @category Pop * @package Pop_Shipping * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License * @version 2.1.0 */ class Usps extends AbstractAdapter { /** * Live API URL * @var string */ protected $liveUrl = 'http://production.shippingapis.com/ShippingAPI.dll?API=RateV4&XML='; /** * Test API URL * @var string */ protected $testUrl = 'http://production.shippingapis.com/ShippingAPITest.dll?API=RateV4&XML='; /** * Test mode flag * @var boolean */ protected $testMode = false; /** * Request XML * @var string */ protected $request = '<RateV4Request USERID="[{username}]" PASSWORD="[{password}]">'; /** * Ship to fields * @var array */ protected $shipTo = [ 'ZipDestination' => null ]; /** * Ship from fields * @var string */ protected $shipFrom = [ 'ZipOrigination' => null ]; /** * Container type * @var string */ protected $container = 'RECTANGULAR'; /** * Container size * @var string */ protected $containerSize = 'REGULAR'; /** * Machinable flag * @var string */ protected $machinable = 'false'; /** * Package dimensions * @var array */ protected $dimensions = [ 'Width' => null, 'Length' => null, 'Height' => null, 'Girth' => null ]; /** * Package weight * @var array */ protected $weight = [ 'Pounds' => 0, 'Ounces' => 0 ]; /** * Constructor * * Method to instantiate an USPS shipping adapter object * * @param string $username * @param string $password * @param boolean $test * @return Usps */ public function __construct($username, $password, $test = false) { $this->testMode = (bool)$test; $this->request = str_replace(['[{username}]', '[{password}]'], [$username, $password], $this->request); } /** * Set ship to * * @param array $shipTo * @return void */ public function shipTo(array $shipTo) { foreach ($shipTo as $key => $value) { if ((strtolower($key) == 'postalcode') || (strtolower($key) == 'zipcode') || (strtolower($key) == 'zip')) { $this->shipTo['ZipDestination'] = $value; } } } /** * Set ship from * * @param array $shipFrom * @return void */ public function shipFrom(array $shipFrom) { foreach ($shipFrom as $key => $value) { if ((strtolower($key) == 'postalcode') || (strtolower($key) == 'zipcode') || (strtolower($key) == 'zip')) { $this->shipFrom['ZipOrigination'] = $value; } } } /** * Set container * * @param string $container * @throws Exception * @return void */ public function setContainer($container = 'RECTANGULAR') { if (($container == 'RECTANGULAR') || ($container == 'NONRECTANGULAR')) { $this->container = $container; } else { throw new Exception('Error: The container type must be RECTANGULAR or NONRECTANGULAR.'); } } /** * Set machinable flag * * @param boolean $machinable * @return void */ public function setMachinable($machinable = false) { $this->machinable = ($machinable) ? 'true' : 'false'; } /** * Set dimensions * * @param array $dimensions * @param string $unit * @return void */ public function setDimensions(array $dimensions, $unit = null) { foreach ($dimensions as $key => $value) { if (strtolower($key) == 'length') { $this->dimensions['Length'] = $value; } else if (strtolower($key) == 'width') { $this->dimensions['Width'] = $value; } else if (strtolower($key) == 'height') { $this->dimensions['Height'] = $value; } else if (strtolower($key) == 'girth') { $this->dimensions['Girth'] = $value; } } if (max($this->dimensions) >= 12) { $this->containerSize = 'LARGE'; } } /** * Set dimensions * * @param string $weight * @param string $unit * @return void */ public function setWeight($weight, $unit = null) { if (is_float($weight)) { $lbs = (floor($weight)); $ozs = round(16 * ($weight - floor($weight)), 2); } else { $lbs = $weight; $ozs = 0; } $this->weight['Pounds'] = $lbs; $this->weight['Ounces'] = $ozs; } /** * Send transaction * * @param boolean $verifyPeer * @return void */ public function send($verifyPeer = true) { $this->buildRequest(); $options = [ CURLOPT_HEADER => false, CURLOPT_URL => ((($this->testMode) ? $this->testUrl : $this->liveUrl) . rawurlencode($this->request)), CURLOPT_RETURNTRANSFER => true ]; if (!$verifyPeer) { $options[CURLOPT_SSL_VERIFYPEER] = false; } $curl = curl_init(); curl_setopt_array($curl, $options); $this->response = simplexml_load_string($this->parseResponse($curl)); if (isset($this->response->Package)) { $this->responseCode = 1; foreach ($this->response->Package->Postage as $rate) { $this->rates[str_replace(['<', '>'], ['<', '>'], (string)$rate->MailService)] = (string)$rate->Rate; } $this->rates = array_reverse($this->rates, true); } else { if (isset($this->response->Number)) { $this->responseCode = (string)$this->response->Number; $this->responseMessage = (string)$this->response->Description; } else { $this->responseCode = 0; } } } /** * Return whether the transaction is a success * * @return boolean */ public function isSuccess() { return ($this->responseCode == 1); } /** * Return whether the transaction is an error * * @return boolean */ public function isError() { return ($this->responseCode != 1); } /** * Build rate request * * @return void */ protected function buildRequest() { $this->request .= PHP_EOL . ' <Package ID="1ST">'; $this->request .= PHP_EOL . ' <Service>ALL</Service>'; $this->request .= PHP_EOL . ' <ZipOrigination>' . $this->shipFrom['ZipOrigination'] . '</ZipOrigination>'; $this->request .= PHP_EOL . ' <ZipDestination>' . $this->shipTo['ZipDestination'] . '</ZipDestination>'; $this->request .= PHP_EOL . ' <Pounds>' . $this->weight['Pounds'] . '</Pounds>'; $this->request .= PHP_EOL . ' <Ounces>' . $this->weight['Ounces'] . '</Ounces>'; $this->request .= PHP_EOL . ' <Container>' . $this->container . '</Container>'; $this->request .= PHP_EOL . ' <Size>' . $this->containerSize . '</Size>'; if ((null !== $this->dimensions['Length']) && (null !== $this->dimensions['Width']) && (null !== $this->dimensions['Height'])) { $this->request .= PHP_EOL . ' <Width>' . $this->dimensions['Width'] . '</Width>'; $this->request .= PHP_EOL . ' <Length>' . $this->dimensions['Length'] . '</Length>'; $this->request .= PHP_EOL . ' <Height>' . $this->dimensions['Height'] . '</Height>'; if (null == $this->dimensions['Girth']) { $this->dimensions['Girth'] = (2 * $this->dimensions['Width']) + (2 * $this->dimensions['Height']); } $this->request .= PHP_EOL . ' <Girth>' . $this->dimensions['Girth'] . '</Girth>'; } $this->request .= PHP_EOL . ' <Machinable>' . $this->machinable . '</Machinable>'; $this->request .= PHP_EOL . ' <DropOffTime>12:00</DropOffTime>'; $this->request .= PHP_EOL . ' <ShipDate>' . date('Y-m-d') . '</ShipDate>'; $this->request .= PHP_EOL . ' </Package>'; $this->request .= PHP_EOL . '</RateV4Request>'; } } src/Adapter/Gso.php 0000604 00000033321 15173165744 0010167 0 ustar 00 <?php /** * Pop PHP Framework (http://www.popphp.org/) * * @link https://github.com/popphp/popphp-framework * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License */ /** * @namespace */ namespace Pop\Shipping\Adapter; /** * Gso shipping adapter class * * @category Pop * @package Pop_Shipping * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License * @version 2.0.0 */ class Gso extends AbstractAdapter { /** * SOAP Client * * @var \SoapClient */ protected $client = null; /** * FedEx WSDL File * * @var string */ protected $wsdl = null; /** * Request array * * @var array */ protected $request = null; /** * Request header - common header to apply to all API requests * * @var SoapHeader */ protected $requestHeader; /** * Ship to fields * * @var array */ protected $shipTo = [ 'Contact' => [ 'PersonName' => '', 'CompanyName' => '', 'PhoneNumber' => '' ], 'Address' => [ 'StreetLines' => ['', ''], 'City' => '', 'StateOrProvinceCode' => '', 'PostalCode' => '', 'CountryCode' => '', 'Residential' => false ] ]; /** * Ship from fields * * @var array */ protected $shipFrom = [ 'Contact' => [ 'PersonName' => '', 'CompanyName' => '', 'PhoneNumber' => '' ], 'Address' => [ 'StreetLines' => [], 'City' => '', 'StateOrProvinceCode' => '', 'PostalCode' => '', 'CountryCode' => '' ] ]; /** * Drop of types * * @var array */ protected $dropOfTypes = [ 'REGULAR_PICKUP', 'REQUEST_COURIER', 'DROP_BOX', 'BUSINESS_SERVICE_CENTER', 'STATION' ]; protected $dropOfType = 'REGULAR_PICKUP'; /** * Package dimensions * * @var array */ protected $dimensions = [ 'Length' => null, 'Width' => null, 'Height' => null, 'Units' => 'IN' ]; /** * Package weight * * @var array */ protected $weight = [ 'Value' => null, 'Units' => 'LB' ]; /** * Services * * @var array */ protected static $services = [ 'GSO' => 'Golden State Overnight', 'CPS' => 'California Parcel Service', 'EPS' => 'Early Priority Service', 'ESS' => 'Early Saturday Service', 'NPS' => 'Noon Priority Service', 'PDS' => 'Priority Delivery Service', 'SDS' => 'Saturday Delivery Service' ]; protected $accountNumber; /** * Constructor * * Method to instantiate an FedEx shipping adapter object * * @param string $username * @param string $password * @param string $accountNumber * @param string $wsdl * * @return Gso */ public function __construct($username, $password, $accountNumber, $wsdl) { if (!is_array($wsdl)) { $wsdl = ['rates' => $wsdl, 'shipping' => $wsdl]; } $this->wsdl = $wsdl; $this->accountNumber = $accountNumber; ini_set('soap.wsdl_cache_enabled', '0'); $this->requestHeader = new \SoapHeader('http://gso.com/GsoShipWS', 'AuthenticationHeader', array( 'UserName' => $username, 'Password' => $password )); } /** * Static method to get the services * * @return array */ public static function getServices() { return self::$services; } /** * Set ship to * * @param array $shipTo * * @return mixed */ public function shipTo(array $shipTo) { foreach ($shipTo as $key => $value) { if (stripos($key, 'person') !== false) { $this->shipTo['Contact']['PersonName'] = $value; } else { if (stripos($key, 'company') !== false) { $this->shipTo['Contact']['CompanyName'] = $value; } else { if (stripos($key, 'phone') !== false) { $this->shipTo['Contact']['PhoneNumber'] = $value; } else { if (stripos($key, 'address') !== false) { $v = (array) $value; foreach ($v as $k => $s) { $this->shipTo['Address']['StreetLines'][$k] = $s; } } else { if (strtolower($key) == 'city') { $this->shipTo['Address']['City'] = $value; } else { if ((stripos($key, 'state') !== false) || (stripos($key, 'province') !== false)) { $this->shipTo['Address']['StateOrProvinceCode'] = $value; } else { if ((strtolower($key) == 'postalcode') || (strtolower($key) == 'zipcode') || (strtolower($key) == 'zip')) { $this->shipTo['Address']['PostalCode'] = $value; } else { if ((strtolower($key) == 'countrycode') || (strtolower($key) == 'country')) { $this->shipTo['Address']['CountryCode'] = $value; } else { if (strtolower($key) == 'residential') { $this->shipTo['Address']['Residential'] = $value; } } } } } } } } } } return $this->shipTo; } /** * Set ship from * * @param array $shipFrom * * @return mixed */ public function shipFrom(array $shipFrom) { foreach ($shipFrom as $key => $value) { if (stripos($key, 'person') !== false) { $this->shipFrom['Contact']['PersonName'] = $value; } else { if (stripos($key, 'company') !== false) { $this->shipFrom['Contact']['CompanyName'] = $value; } else { if (stripos($key, 'phone') !== false) { $this->shipFrom['Contact']['PhoneNumber'] = $value; } else { if (stripos($key, 'address') !== false) { $this->shipFrom['Address']['StreetLines'][] = $value; } else { if (strtolower($key) == 'city') { $this->shipFrom['Address']['City'] = $value; } else { if ((stripos($key, 'state') !== false) || (stripos($key, 'province') !== false)) { $this->shipFrom['Address']['StateOrProvinceCode'] = $value; } else { if ((strtolower($key) == 'postalcode') || (strtolower($key) == 'zipcode') || (strtolower($key) == 'zip')) { $this->shipFrom['Address']['PostalCode'] = $value; } else { if ((strtolower($key) == 'countrycode') || (strtolower($key) == 'country')) { $this->shipFrom['Address']['CountryCode'] = $value; } else { if (strtolower($key) == 'residential') { $this->shipFrom['Address']['Residential'] = $value; } } } } } } } } } } return $this->shipFrom; } /** * Add Info on who pays the shipping charges. * * @return array */ protected function addShippingChargesPayment() { $shippingChargesPayment = array('PaymentType' => 'SENDER', 'Payor' => array( 'ResponsibleParty' => array( 'AccountNumber' => $this->accountNumber, 'Contact' => null, 'Address' => array( 'CountryCode' => 'US' ) ) ) ); return $shippingChargesPayment; } /** * Add label specification to shipping. * * @return array */ protected function addLabelSpecification() { $labelSpecification = array( ); return $labelSpecification; } /** * Add a shipping package line item * * @param Pop\Shipping\PackageAdapter\AbstractAdapter * * @return array */ protected function addPackageLineItem($package) { // TODO unhardwire: $this->trackingNumber = '012312312'; $this->shipmentReference = 'aadfasdfasdf'; $this->CODValue = '0.00'; $this->signatureRequired = 'ADULT_SIG_REQD'; // >SIG_REQD or SIG_NOT_REQD or ADULT_SIG_REQD echo "shipoing info = ";print_r($this->shippingInfo); $serviceType = isset($this->shippingInfo->serviceType) ? $this->shippingInfo->serviceType : 'STANDARD_OVERNIGHT'; echo "serice type = $serviceType"; // TODO - not sure if $this->declaredValue should be per package or as total? return [ 'AccountNumber' => $this->accountNumber, 'TrackingNumber' => $this->trackingNumber, 'ShipperCompany' => $this->shipFrom['Contact']['CompanyName'], 'ShipperContact' => $this->shipFrom['Contact']['PersonName'], 'ShipperPhone' => $this->shipFrom['Contact']['PhoneNumber'], 'PickupAddress1' => $this->shipFrom['Address']['StreetLines'][0], 'PickupAddress2' => $this->shipFrom['Address']['StreetLines'][1], 'PickupCity' => $this->shipFrom['Address']['City'], 'PickupState' => $this->shipFrom['Address']['StateOrProvinceCode'], 'PickupZip' => $this->shipFrom['Address']['PostalCode'], 'ShipToCompany' => $this->shipTo['Contact']['CompanyName'], 'ShipToAttention' => $this->shipTo['Contact']['PersonName'], 'ShipToPhone' => $this->shipTo['Contact']['PhoneNumber'], 'DeliveryAddress1' => $this->shipTo['Address']['StreetLines'][0], 'DeliveryAddress2' => $this->shipTo['Address']['StreetLines'][1], 'DeliveryCity' => $this->shipTo['Address']['City'], 'DeliveryState' => $this->shipTo['Address']['StateOrProvinceCode'], 'DeliveryZip' => $this->shipTo['Address']['PostalCode'], 'ServiceCode' => $serviceType, 'ShipmentReference' => $this->shipmentReference, 'DeclaredValue' => $this->declaredValue, 'CODValue' => $this->CODValue, 'Weight' => $package->getWeight(), 'SignatureCode' => $this->signatureRequired ]; } /** * Set the drop off type * * @param $type */ protected function setDropOfType($type) { if (in_array($this->dropOfTypes, $type)) { $this->dropOfType = $type; } else { $this->dropOfType = 'REGULAR_PICKUP'; } } /** * Confirm a shipment * * @param bool $verifyPeer * * @throws \Exception * * @return array label file format, label image data */ public function ship($verifyPeer = true) { $request = [ ]; $request['Shipment']['Package'] = []; $request['Shipment'] = [ 'Notification' => [ 'ShipmentNotification' => '', 'ExceptionNotification' => '', 'DeliveryNotification' => '', 'ReceiptNotification' => '' ], 'ShipmentLabel' => [ 'Type' => 'PAPER_LABEL' ] ]; // TODO - we can only add in one package - ask G what to do here.... foreach ($this->packages as $package) { $request['Shipment']['Package'] = $this->addPackageLineItem($package); } $this->client = new \SoapClient($this->wsdl['shipping'], ['trace' => 1]); $this->client->__setSoapHeaders($this->requestHeader); $this->response = $this->client->SubmitShipment($request); if ($this->response->SubmitShipmentResult->Result->Code == '1') { throw new \Exception(implode("\n", $this->response->Result->Message)); } $label = $this->response->SubmitShipmentResult->Label->Paper; // @todo test this is the right format and label is not base64 enoded return ['gif', $label]; } /** * Get the SOAP client * @return \SoapClient */ private function getClient() { if (!isset($this->client)) { $this->client = new \SoapClient($this->wsdl['rates'], ['trace' => 1]); $this->client->__setSoapHeaders($this->requestHeader); } return $this->client; } /** * @return array|void */ private function getServiceTypes() { self::$services = array(); $client = $this->getClient(); $typeRequest = [ 'GetServiceTypesRequest' => [ 'AccountNumber' => $this->accountNumber ] ]; $serviceTypes = $client->GetServiceTypes($typeRequest); if ($serviceTypes->GetServiceTypesResult->Result->Code === 1) { $this->responseCode = 1; $this->responseMessage = 'Could not get service types'; return; } foreach ($serviceTypes->GetServiceTypesResult->Service->Service as $service) { self::$services[$service->Code] = $service->Description; } return self::$services; } /** * Send transaction * * @return void */ public function send() { $request['GetShippingRateRequest'] = [ 'AccountNumber' => $this->accountNumber, 'OriginZip' => $this->shipFrom['Address']['PostalCode'], 'DestinationZip' => $this->shipTo['Address']['PostalCode'], 'PackageWeight' => $this->totalWeight(), 'DeclaredValue' => floatval($this->declaredValue), 'CODValue' => $this->CODValue ]; $client = $this->getClient(); $this->getServiceTypes(); $responseCodes = []; $responseMessage = []; $this->ratesExtended = []; foreach (self::$services as $serviceCode => $serviceType) { $request['GetShippingRateRequest']['ServiceCode'] = $serviceCode; $this->response = $client->GetShippingRate($request); $responseCode = (int) $this->response->GetShippingRateResult->Result->Code; $responseCodes[] = $responseCode; $responseMessage[] = (string) $this->response->GetShippingRateResult->Result->Message; if ($responseCode == 0) { $total = number_format((string) $this->response->GetShippingRateResult->ShipmentCharges->TotalCharge, 2); $this->ratesExtended[$serviceCode] = (object) [ 'shipper' => 'gso', 'total' => $total, 'serviceType' =>$serviceCode, 'title' => $serviceType ]; $this->rates[$serviceCode] = $total; } } // Presume that response is OK if at least one API call returned true $this->responseCode = min($responseCodes); $this->responseMessage = $responseMessage[array_search($this->responseCode, $responseCodes)]; } /** * Return whether the transaction is a success * * @return boolean */ public function isSuccess() { return ($this->responseCode == 0); } /** * Return whether the transaction is an error * * @return boolean */ public function isError() { return ($this->responseCode != 0); } /** * Get Package * @return \Pop\Shipping\PackageAdapter\Gso */ public function getPackage() { return new \Pop\Shipping\PackageAdapter\Gso(); } } src/Adapter/Exception.php 0000604 00000001376 15173165744 0011402 0 ustar 00 <?php /** * Pop PHP Framework (http://www.popphp.org/) * * @link https://github.com/popphp/popphp-framework * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License */ /** * @namespace */ namespace Pop\Shipping\Adapter; /** * Shipping adapter exception class * * @category Pop * @package Pop_Shipping * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License * @version 2.1.0 */ class Exception extends \Exception {} src/Adapter/AbstractAdapter.php 0000604 00000005147 15173165744 0012510 0 ustar 00 <?php /** * Pop PHP Framework (http://www.popphp.org/) * * @link https://github.com/popphp/popphp-framework * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License */ /** * @namespace */ namespace Pop\Shipping\Adapter; /** * Shipping adapter abstract class * * @category Pop * @package Pop_Shipping * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License * @version 2.1.0 */ abstract class AbstractAdapter implements AdapterInterface { /** * Response object * @var object */ protected $response = null; /** * Response code * @var int */ protected $responseCode = null; /** * Response message * @var string */ protected $responseMessage = null; /** * Service rates * @var array */ protected $rates = []; /** * Send transaction * * @param boolean $verifyPeer * @return void */ abstract public function send($verifyPeer = true); /** * Return whether the transaction is a success * * @return boolean */ abstract public function isSuccess(); /** * Return whether the transaction is an error * * @return boolean */ abstract public function isError(); /** * Get response * * @return object */ public function getResponse() { return $this->response; } /** * Get response code * * @return int */ public function getResponseCode() { return $this->responseCode; } /** * Get response message * * @return string */ public function getResponseMessage() { return $this->responseMessage; } /** * Get service rates * * @return array */ public function getRates() { return $this->rates; } /** * Parse the curl response * * @param resource $curl * @return string */ protected function parseResponse($curl) { $response = curl_exec($curl); if (curl_getinfo($curl, CURLOPT_HEADER)) { $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE); $body = substr($response, $headerSize); } else { $body = $response; } return $body; } } src/PackageAdapter/Usps.php 0000604 00000007446 15173165744 0011656 0 ustar 00 <?php /** * Pop PHP Framework (http://www.popphp.org/) * * @link https://github.com/popphp/popphp-framework * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License */ /** * @namespace */ namespace Pop\Shipping\PackageAdapter; /** * Usps shipping adapter class * * @category Pop * @package Pop_Shipping * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License * @version 2.0.0 */ class Usps extends AbstractAdapter { /** * Container type * @var string */ protected $container = 'VARIABLE'; /** * Container size * @var string */ protected $containerSize = 'REGULAR'; /** * Package dimensions * * @var array */ protected $dimensions = [ 'Width' => null, 'Length' => null, 'Height' => null, 'Girth' => null ]; /** * Package weight * * @var array */ protected $weight = [ 'Pounds' => 0, 'Ounces' => 0 ]; /** * Set container * * @param string $container * @throws Exception * @return void */ public function setContainer($container = 'RECTANGULAR') { // Not sure that NONRECTANGULAR is still valid. if (in_array($container, ['RECTANGULAR', 'NONRECTANGULAR', 'VARIABLE'])) { $this->container = $container; } else { throw new Exception('Error: The container type must be RECTANGULAR or NONRECTANGULAR.'); } } /** * Set dimensions * * @param string $weight * @param string $unit * * @return void */ public function setWeight($weight, $unit = null) { if (is_float($weight)) { $lbs = floor($weight); $ozs = round(16 * ($weight - $lbs), 2); } else { $lbs = $weight; $ozs = 0; } $this->weight['Pounds'] = $lbs; $this->weight['Ounces'] = $ozs; } /** * Set dimensions * * @param array $dimensions * @param string $unit * * @return void */ public function setDimensions(array $dimensions, $unit = null) { parent::setDimensions($dimensions, $unit); foreach ($dimensions as $key => $value) { switch (strtolower($key)) { case 'girth': $this->dimensions['Girth'] = $value; break; } } } /** * @param bool $alcohol Package contains alcohol * * @return string */ public function rateRequest($alcohol = false) { //$request = PHP_EOL . ' <Package ID="' . $id . '">'; /* $request .= PHP_EOL . ' <Service>ALL</Service>'; $request .= PHP_EOL . ' <ZipOrigination>' . $shipFrom['ZipOrigination'] . '</ZipOrigination>'; $request .= PHP_EOL . ' <ZipDestination>' . $shipTo['ZipDestination'] . '</ZipDestination>';*/ $request = PHP_EOL . ' <Pounds>' . $this->weight['Pounds'] . '</Pounds>'; $request .= PHP_EOL . ' <Ounces>' . $this->weight['Ounces'] . '</Ounces>'; $request .= PHP_EOL . ' <Container>' . $this->container . '</Container>'; $request .= PHP_EOL . ' <Size>' . $this->containerSize . '</Size>'; if ((null !== $this->dimensions['Length']) && (null !== $this->dimensions['Width']) && (null !== $this->dimensions['Height']) ) { $request .= PHP_EOL . ' <Width>' . $this->dimensions['Width'] . '</Width>'; $request .= PHP_EOL . ' <Length>' . $this->dimensions['Length'] . '</Length>'; $request .= PHP_EOL . ' <Height>' . $this->dimensions['Height'] . '</Height>'; if (null == $this->dimensions['Girth']) { $this->dimensions['Girth'] = (2 * $this->dimensions['Width']) + (2 * $this->dimensions['Height']); } $request .= PHP_EOL . ' <Girth>' . $this->dimensions['Girth'] . '</Girth>'; } return $request; } } src/PackageAdapter/AbstractAdapter.php 0000604 00000004351 15173165744 0013760 0 ustar 00 <?php /** * Pop PHP Framework (http://www.popphp.org/) * * @link https://github.com/popphp/popphp-framework * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License */ /** * @namespace */ namespace Pop\Shipping\PackageAdapter; /** * Package adapter abstract class * * @category Pop * @package Pop_Shipping * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License * @version 2.0.0 */ abstract class AbstractAdapter implements AdapterInterface { protected $weight = []; protected $dimensions = []; /** * @param $weight * @param null $unit * * @return mixed */ public function setWeight($weight, $unit = null) { if ((null !== $unit) && (($unit == 'LB') || ($unit == 'KG'))) { $this->weight['Units'] = $unit; } $this->weight['Value'] = $weight; } /** * Get weight * @return number */ public function getWeight() { return $this->weight['Value']; } /** * @param array $dimensions * @param null $unit * * @return mixed */ public function setDimensions(array $dimensions, $unit = null) { if ((null !== $unit) && (($unit == 'IN') || ($unit == 'CM'))) { $this->dimensions['Units'] = $unit; } foreach ($dimensions as $key => $value) { switch (strtolower($key)) { case 'length': $this->dimensions['Length'] = $value; break; case 'width': $this->dimensions['Width'] = $value; break; case 'height': $this->dimensions['Height'] = $value; break; } } } /** * @param bool $alcohol Package contains alcohol * @return string */ public function rateRequest($alcohol = false) { $request = [ 'SequenceNumber' => 1, 'GroupPackageCount' => 1, 'Weight' => $this->weight ]; if ((null !== $this->dimensions['Length']) && (null !== $this->dimensions['Width']) && (null !== $this->dimensions['Height'])) { $request['Dimensions'] = $this->dimensions; } return $request; } } src/PackageAdapter/Fedex.php 0000604 00000001404 15173165744 0011743 0 ustar 00 <?php /** * Pop PHP Framework (http://www.popphp.org/) * * @link https://github.com/popphp/popphp-framework * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License */ /** * @namespace */ namespace Pop\Shipping\PackageAdapter; /** * FedEx shipping adapter class * * @category Pop * @package Pop_Shipping * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License * @version 2.0.0 */ class Fedex extends AbstractAdapter { } src/PackageAdapter/Gso.php 0000604 00000001400 15173165744 0011434 0 ustar 00 <?php /** * Pop PHP Framework (http://www.popphp.org/) * * @link https://github.com/popphp/popphp-framework * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License */ /** * @namespace */ namespace Pop\Shipping\PackageAdapter; /** * Gso shipping adapter class * * @category Pop * @package Pop_Shipping * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License * @version 2.0.0 */ class Gso extends AbstractAdapter { } src/PackageAdapter/Ups.php 0000604 00000010674 15173165744 0011470 0 ustar 00 <?php /** * Pop PHP Framework (http://www.popphp.org/) * * @link https://github.com/popphp/popphp-framework * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License */ /** * @namespace */ namespace Pop\Shipping\PackageAdapter; /** * Usps shipping adapter class * * @category Pop * @package Pop_Shipping * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License * @version 2.0.0 */ class Ups extends AbstractAdapter { /** * Package type * * @var string */ protected $packageType = '02'; /** * Pickup Types * * @var array */ protected static $packagingTypes = [ '00' => 'UNKNOWN', '01' => 'UPS Letter', '02' => 'Package', '03' => 'Tube', '04' => 'Pak', '21' => 'Express Box', '24' => '25KG Box', '25' => '10KG Box', '30' => 'Pallet', '2a' => 'Small Express Box', '2b' => 'Medium Express Box', '2c' => 'Large Express Box' ]; /** * Set dimensions * * @param array $dimensions * @param string $unit * * @return void */ public function setDimensions(array $dimensions, $unit = null) { parent::setDimensions($dimensions, $unit); if ((null !== $unit) && (($unit == 'IN') || ($unit == 'CM'))) { $this->dimensions['UnitOfMeasurement'] = $unit; } } /** * Set dimensions * * @param string $weight * @param string $unit * * @return void */ public function setWeight($weight, $unit = null) { if ((null !== $unit) && (($unit == 'LBS') || ($unit == 'KGS'))) { $this->weight['UnitOfMeasurement'] = $unit; } else { $this->weight['UnitOfMeasurement'] = 'LBS'; } $this->weight['Weight'] = $weight; } /** * Set package type * * @param string $code * * @throws Exception * @return void */ public function setPackage($code) { if (!array_key_exists($code, self::$packagingTypes)) { throw new Exception('Error: That package code does not exist.'); } $this->packageType = $code; } /** * @param bool $alcohol Package contains alcohol * @return string */ public function rateRequest($alcohol = false) { $request = ''; $request .= PHP_EOL . ' <Package>'; $request .= PHP_EOL . ' <PackagingType>'; $request .= PHP_EOL . ' <Code>' . $this->packageType . '</Code>'; $request .= PHP_EOL . ' <Description>' . self::$packagingTypes[$this->packageType] . '</Description>'; $request .= PHP_EOL . ' </PackagingType>'; $request .= PHP_EOL . ' <Description>Rate</Description>'; if ((null !== $this->dimensions['Length']) && (null !== $this->dimensions['Width']) && (null !== $this->dimensions['Height']) ) { $request .= PHP_EOL . ' <Dimensions>'; $request .= PHP_EOL . ' <UnitOfMeasurement>'; $request .= PHP_EOL . ' <Code>' . $this->dimensions['UnitOfMeasurement'] . '</Code>'; $request .= PHP_EOL . ' </UnitOfMeasurement>'; $request .= PHP_EOL . ' <Length>' . $this->dimensions['Length'] . '</Length>'; $request .= PHP_EOL . ' <Width>' . $this->dimensions['Width'] . '</Width>'; $request .= PHP_EOL . ' <Height>' . $this->dimensions['Height'] . '</Height>'; $request .= PHP_EOL . ' </Dimensions>'; } $request .= PHP_EOL . ' <PackageWeight>'; $request .= PHP_EOL . ' <UnitOfMeasurement>'; $request .= PHP_EOL . ' <Code>' . $this->weight['UnitOfMeasurement'] . '</Code>'; $request .= PHP_EOL . ' </UnitOfMeasurement>'; $request .= PHP_EOL . ' <Weight>' . $this->weight['Weight'] . '</Weight>'; $request .= PHP_EOL . ' </PackageWeight>'; if ($alcohol) { $request .= PHP_EOL . ' <PackageServiceOptions>'; $request .= PHP_EOL . ' <DeliveryConfirmation>'; // 3 = DeliveryConfirmation AdultSignature Required $request .= PHP_EOL . ' <DCISType>3</DCISType>'; $request .= PHP_EOL . ' </DeliveryConfirmation>'; $request .= PHP_EOL . ' </PackageServiceOptions>'; } $request .= PHP_EOL . ' </Package>'; return $request; } } src/PackageAdapter/AdapterInterface.php 0000604 00000002223 15173165744 0014111 0 ustar 00 <?php /** * Pop PHP Framework (http://www.popphp.org/) * * @link https://github.com/popphp/popphp-framework * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License */ /** * @namespace */ namespace Pop\Shipping\PackageAdapter; /** * Shipping adapter interface * * @category Pop * @package Pop_Shipping * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License * @version 2.0.0 */ interface AdapterInterface { /** * @param $weight * @param null $unit * * @return mixed */ public function setWeight($weight, $unit = null); /** * @param array $dimensions * @param null $unit * * @return mixed */ public function setDimensions(array $dimensions, $unit = null); /** * Get weight * @return number */ public function getWeight(); } src/Package.php 0000604 00000002353 15173165744 0007413 0 ustar 00 <?php /** * Pop PHP Framework (http://www.popphp.org/) * * @link https://github.com/popphp/popphp-framework * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License */ /** * @namespace */ namespace Pop\Shipping; /** * Shipping class * * @category Pop * @package Pop_Shipping * @author Nick Sagona, III <dev@nolainteractive.com> * @copyright Copyright (c) 2009-2016 NOLA Interactive, LLC. (http://www.nolainteractive.com) * @license http://www.popphp.org/license New BSD License * @version 2.0.0 */ class Package { /** * Package adapter * @var mixed */ protected $adapter = null; /** * Constructor * * Instantiate the package object * * @param PackageAdapter\AbstractAdapter $adapter * @return Package */ public function __construct(PackageAdapter\AbstractAdapter $adapter) { $this->adapter = $adapter; } /** * Access the adapter * * @return Adapter\AbstractAdapter */ public function adapter() { return $this->adapter; } } .gitattributes 0000604 00000000111 15173165744 0007441 0 ustar 00 tests/ export-ignore phpunit.xml export-ignore .travis.yml export-ignore README.md 0000604 00000005462 15173165744 0006043 0 ustar 00 pop-shipping ============ END OF LIFE ----------- The `pop-shipping` component v2.1.0 is now end-of-life and will no longer be maintained. [](https://travis-ci.org/popphp/pop-shipping) [](http://cc.popphp.org/pop-shipping/) OVERVIEW -------- `pop-shipping` is a component for calculating shipping rates with some of the known standard shipping vendors like UPS, FedEx and the US Post Office. It can also be extended to support other shipping vendors and their available APIs. `pop-shipping` is a component of the [Pop PHP Framework](http://www.popphp.org/). INSTALL ------- Install `pop-shipping` using Composer. composer require popphp/pop-shipping BASIC USAGE ----------- ### Creating a shipping object Of course, using any of the shipping adapters will require you to have a registered account with the shipping vendor: ##### FedEx The FedEx API utilizes SOAP, so you'll have to obtain a copy of the WSDL file and point to its location on your sever: ```php use Pop\Shipping\Shipping; use Pop\Shipping\Adapter\Fedex; $shipping = new Shipping( new Fedex('USER_KEY', 'PASSWORD', 'ACCOUNT_NUM', 'METER_NUM', 'WSDL_FILE') ); ``` ##### UPS The UPS API utilizes basic XML under the hood: ```php use Pop\Shipping\Shipping; use Pop\Shipping\Adapter\Ups; $shipping = new Shipping( new Ups('ACCESS_KEY', 'USER_ID', 'PASSWORD') ); ``` ##### US Post Office The US Post Office API utilizes basic XML under the hood as well: ```php use Pop\Shipping\Shipping; use Pop\Shipping\Adapter\Usps; $shipping = new Shipping( new Usps('USERNAME', 'PASSWORD') ); ``` ### Using the shipping object to get the rates ```php use Pop\Shipping\Shipping; use Pop\Shipping\Adapter\Ups; $shipping = new Shipping( new Ups('ACCESS_KEY', 'USER_ID', 'PASSWORD') ); // Set the 'ship to' address $shipping->shipTo([ 'address' => '123 Main St.', 'city' => 'Some Town', 'state' => 'LA', 'zip' => '12345', 'country' => 'US' ]); // Set the 'ship from' address $shipping->shipFrom([ 'company' => 'Widgets Inc', 'address1' => '456 Some St.', 'address2' => 'Suite 100', 'city' => 'Some Town', 'zip' => '12345', 'country' => 'US' ]); // Set the package dimensions $shipping->setDimensions([ 'length' => 12, 'height' => 10, 'width' => 8 ], 'IN'); // Set the package weight $shipping->setWeight(5.4, 'LBS'); // Go get the rates $shipping->send(); if ($shipping->isSuccess()) { foreach ($shipping->getRates() as $service => $rate) { echo $service . ': ' . $rate . PHP_EOL; } } ``` The above example will output something like: Next Day Air: $36.70 2nd Day Air: $28.84 3 Day Select: $22.25 Ground: $17.48 .gitignore 0000604 00000000035 15173165744 0006543 0 ustar 00 composer.lock public vendor
| ver. 1.4 |
Github
|
.
| PHP 8.3.23 | Generation time: 0 |
proxy
|
phpinfo
|
Settings