commit
0fdd82dd76
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
vendor/
|
||||||
|
.idea/
|
||||||
|
composer.lock
|
||||||
|
|
290
README.md
290
README.md
@ -21,23 +21,19 @@ Add the following lines to your ``composer.json`` file.
|
|||||||
Create a shipment object:
|
Create a shipment object:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$shipment = [
|
$shipment = new Shipment;
|
||||||
'weight' => 3, // lbs
|
$shipment
|
||||||
'dimensions' => [
|
->setFromStateProvinceCode('IN')
|
||||||
'width' => 9, // inches
|
->setFromPostalCode('46205')
|
||||||
'length' => 9,
|
->setFromCountryCode('US')
|
||||||
'height' => 9,
|
->setToPostalCode('20101')
|
||||||
],
|
->setToCountryCode('US')
|
||||||
'from' => [
|
->setToResidential(true);
|
||||||
'postal_code' => '90401',
|
|
||||||
'country_code' => 'US',
|
$package = new Package;
|
||||||
],
|
$package->setLength(12)->setWidth(4)->setHeight(3)->setWeight(3);
|
||||||
'to' => [
|
|
||||||
'postal_code' => '78703',
|
$shipment->addPackage($package);
|
||||||
'country_code' => 'US',
|
|
||||||
'is_residential' => TRUE,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## UPS (Stub) Example
|
## UPS (Stub) Example
|
||||||
@ -78,32 +74,68 @@ $ups_rates = $ups->get_rates();
|
|||||||
Output array sorted by cost: (in cents)
|
Output array sorted by cost: (in cents)
|
||||||
|
|
||||||
```php
|
```php
|
||||||
array (
|
array(4) {
|
||||||
0 =>
|
[0] =>
|
||||||
array (
|
class pdt256\Shipping\Quote#56 (6) {
|
||||||
'code' => '03',
|
protected $code =>
|
||||||
'name' => 'UPS Ground',
|
string(2) "03"
|
||||||
'cost' => 1900,
|
protected $name =>
|
||||||
),
|
string(10) "UPS Ground"
|
||||||
1 =>
|
protected $cost =>
|
||||||
array (
|
int(1900)
|
||||||
'code' => '02',
|
protected $transit_time =>
|
||||||
'name' => 'UPS 2nd Day Air',
|
NULL
|
||||||
'cost' => 4900,
|
protected $delivery_ts =>
|
||||||
),
|
NULL
|
||||||
2 =>
|
protected $carrier =>
|
||||||
array (
|
string(3) "ups"
|
||||||
'code' => '13',
|
}
|
||||||
'name' => 'UPS Next Day Air Saver',
|
[1] =>
|
||||||
'cost' => 8900,
|
class pdt256\Shipping\Quote#58 (6) {
|
||||||
),
|
protected $code =>
|
||||||
3 =>
|
string(2) "02"
|
||||||
array (
|
protected $name =>
|
||||||
'code' => '01',
|
string(15) "UPS 2nd Day Air"
|
||||||
'name' => 'UPS Next Day Air',
|
protected $cost =>
|
||||||
'cost' => 9300,
|
int(4900)
|
||||||
),
|
protected $transit_time =>
|
||||||
)
|
NULL
|
||||||
|
protected $delivery_ts =>
|
||||||
|
NULL
|
||||||
|
protected $carrier =>
|
||||||
|
string(3) "ups"
|
||||||
|
}
|
||||||
|
[2] =>
|
||||||
|
class pdt256\Shipping\Quote#57 (6) {
|
||||||
|
protected $code =>
|
||||||
|
string(2) "13"
|
||||||
|
protected $name =>
|
||||||
|
string(22) "UPS Next Day Air Saver"
|
||||||
|
protected $cost =>
|
||||||
|
int(8900)
|
||||||
|
protected $transit_time =>
|
||||||
|
NULL
|
||||||
|
protected $delivery_ts =>
|
||||||
|
NULL
|
||||||
|
protected $carrier =>
|
||||||
|
string(3) "ups"
|
||||||
|
}
|
||||||
|
[3] =>
|
||||||
|
class pdt256\Shipping\Quote#55 (6) {
|
||||||
|
protected $code =>
|
||||||
|
string(2) "01"
|
||||||
|
protected $name =>
|
||||||
|
string(16) "UPS Next Day Air"
|
||||||
|
protected $cost =>
|
||||||
|
int(9300)
|
||||||
|
protected $transit_time =>
|
||||||
|
NULL
|
||||||
|
protected $delivery_ts =>
|
||||||
|
NULL
|
||||||
|
protected $carrier =>
|
||||||
|
string(3) "ups"
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## USPS (Stub) Example
|
## USPS (Stub) Example
|
||||||
@ -116,10 +148,7 @@ $usps = new USPS\Rate([
|
|||||||
'prod' => FALSE,
|
'prod' => FALSE,
|
||||||
'username' => 'XXXX',
|
'username' => 'XXXX',
|
||||||
'password' => 'XXXX',
|
'password' => 'XXXX',
|
||||||
'shipment' => array_merge($shipment, [
|
'shipment' => $shipment,
|
||||||
'size' => 'LARGE',
|
|
||||||
'container' => 'RECTANGULAR',
|
|
||||||
]),
|
|
||||||
'approved_codes' => [
|
'approved_codes' => [
|
||||||
'1', // 1-3 business days
|
'1', // 1-3 business days
|
||||||
'4', // 2-8 business days
|
'4', // 2-8 business days
|
||||||
@ -133,20 +162,38 @@ $usps_rates = $usps->get_rates();
|
|||||||
Output array sorted by cost: (in cents)
|
Output array sorted by cost: (in cents)
|
||||||
|
|
||||||
```php
|
```php
|
||||||
array (
|
array(2) {
|
||||||
1 =>
|
[0] =>
|
||||||
array (
|
class pdt256\Shipping\Quote#30 (6) {
|
||||||
'code' => '4',
|
protected $code =>
|
||||||
'name' => 'Parcel Post',
|
string(1) "4"
|
||||||
'cost' => 1000,
|
protected $name =>
|
||||||
),
|
string(11) "Parcel Post"
|
||||||
0 =>
|
protected $cost =>
|
||||||
array (
|
int(1001)
|
||||||
'code' => '1',
|
protected $transit_time =>
|
||||||
'name' => 'Priority Mail',
|
NULL
|
||||||
'cost' => 1200,
|
protected $delivery_ts =>
|
||||||
),
|
NULL
|
||||||
)
|
protected $carrier =>
|
||||||
|
string(4) "usps"
|
||||||
|
}
|
||||||
|
[1] =>
|
||||||
|
class pdt256\Shipping\Quote#26 (6) {
|
||||||
|
protected $code =>
|
||||||
|
string(1) "1"
|
||||||
|
protected $name =>
|
||||||
|
string(13) "Priority Mail"
|
||||||
|
protected $cost =>
|
||||||
|
int(1220)
|
||||||
|
protected $transit_time =>
|
||||||
|
NULL
|
||||||
|
protected $delivery_ts =>
|
||||||
|
NULL
|
||||||
|
protected $carrier =>
|
||||||
|
string(4) "usps"
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Fedex (Stub) Example
|
## Fedex (Stub) Example
|
||||||
@ -162,9 +209,7 @@ $fedex = new Fedex\Rate([
|
|||||||
'account_number' => 'XXXX',
|
'account_number' => 'XXXX',
|
||||||
'meter_number' => 'XXXX',
|
'meter_number' => 'XXXX',
|
||||||
'drop_off_type' => 'BUSINESS_SERVICE_CENTER',
|
'drop_off_type' => 'BUSINESS_SERVICE_CENTER',
|
||||||
'shipment' => array_merge($shipment, [
|
'shipment' => $shipment,
|
||||||
'packaging_type' => 'YOUR_PACKAGING',
|
|
||||||
]),
|
|
||||||
'approved_codes' => [
|
'approved_codes' => [
|
||||||
'FEDEX_EXPRESS_SAVER', // 1-3 business days
|
'FEDEX_EXPRESS_SAVER', // 1-3 business days
|
||||||
'FEDEX_GROUND', // 1-5 business days
|
'FEDEX_GROUND', // 1-5 business days
|
||||||
@ -181,40 +226,89 @@ $fedex_rates = $fedex->get_rates();
|
|||||||
Output array sorted by cost: (in cents)
|
Output array sorted by cost: (in cents)
|
||||||
|
|
||||||
```php
|
```php
|
||||||
array (
|
array(4) {
|
||||||
3 =>
|
[0] =>
|
||||||
array (
|
class pdt256\Shipping\Quote#65 (6) {
|
||||||
'code' => 'GROUND_HOME_DELIVERY',
|
protected $code =>
|
||||||
'name' => 'Ground Home Delivery',
|
string(20) "GROUND_HOME_DELIVERY"
|
||||||
'cost' => 1600,
|
protected $name =>
|
||||||
'delivery_ts' => NULL,
|
string(20) "Ground Home Delivery"
|
||||||
'transit_time' => 'THREE_DAYS',
|
protected $cost =>
|
||||||
),
|
int(1600)
|
||||||
2 =>
|
protected $transit_time =>
|
||||||
array (
|
string(10) "THREE_DAYS"
|
||||||
'code' => 'FEDEX_EXPRESS_SAVER',
|
protected $delivery_ts =>
|
||||||
'name' => 'Fedex Express Saver',
|
NULL
|
||||||
'cost' => 2900,
|
protected $carrier =>
|
||||||
'delivery_ts' => '2014-09-30T20:00:00',
|
string(5) "fedex"
|
||||||
'transit_time' => NULL,
|
}
|
||||||
),
|
[1] =>
|
||||||
1 =>
|
class pdt256\Shipping\Quote#63 (6) {
|
||||||
array (
|
protected $code =>
|
||||||
'code' => 'FEDEX_2_DAY',
|
string(19) "FEDEX_EXPRESS_SAVER"
|
||||||
'name' => 'Fedex 2 Day',
|
protected $name =>
|
||||||
'cost' => 4000,
|
string(19) "Fedex Express Saver"
|
||||||
'delivery_ts' => '2014-09-29T20:00:00',
|
protected $cost =>
|
||||||
'transit_time' => NULL,
|
int(2900)
|
||||||
),
|
protected $transit_time =>
|
||||||
0 =>
|
NULL
|
||||||
array (
|
protected $delivery_ts =>
|
||||||
'code' => 'STANDARD_OVERNIGHT',
|
class Carbon\Carbon#23 (3) {
|
||||||
'name' => 'Standard Overnight',
|
public $date =>
|
||||||
'cost' => 7800,
|
string(26) "2014-09-30 20:00:00.000000"
|
||||||
'delivery_ts' => '2014-09-26T20:00:00',
|
public $timezone_type =>
|
||||||
'transit_time' => NULL,
|
int(3)
|
||||||
),
|
public $timezone =>
|
||||||
)
|
string(16) "America/New_York"
|
||||||
|
}
|
||||||
|
protected $carrier =>
|
||||||
|
string(5) "fedex"
|
||||||
|
}
|
||||||
|
[2] =>
|
||||||
|
class pdt256\Shipping\Quote#61 (6) {
|
||||||
|
protected $code =>
|
||||||
|
string(11) "FEDEX_2_DAY"
|
||||||
|
protected $name =>
|
||||||
|
string(11) "Fedex 2 Day"
|
||||||
|
protected $cost =>
|
||||||
|
int(4000)
|
||||||
|
protected $transit_time =>
|
||||||
|
NULL
|
||||||
|
protected $delivery_ts =>
|
||||||
|
class Carbon\Carbon#26 (3) {
|
||||||
|
public $date =>
|
||||||
|
string(26) "2014-09-29 20:00:00.000000"
|
||||||
|
public $timezone_type =>
|
||||||
|
int(3)
|
||||||
|
public $timezone =>
|
||||||
|
string(16) "America/New_York"
|
||||||
|
}
|
||||||
|
protected $carrier =>
|
||||||
|
string(5) "fedex"
|
||||||
|
}
|
||||||
|
[3] =>
|
||||||
|
class pdt256\Shipping\Quote#60 (6) {
|
||||||
|
protected $code =>
|
||||||
|
string(18) "STANDARD_OVERNIGHT"
|
||||||
|
protected $name =>
|
||||||
|
string(18) "Standard Overnight"
|
||||||
|
protected $cost =>
|
||||||
|
int(7800)
|
||||||
|
protected $transit_time =>
|
||||||
|
NULL
|
||||||
|
protected $delivery_ts =>
|
||||||
|
class Carbon\Carbon#58 (3) {
|
||||||
|
public $date =>
|
||||||
|
string(26) "2014-09-26 20:00:00.000000"
|
||||||
|
public $timezone_type =>
|
||||||
|
int(3)
|
||||||
|
public $timezone =>
|
||||||
|
string(16) "America/New_York"
|
||||||
|
}
|
||||||
|
protected $carrier =>
|
||||||
|
string(5) "fedex"
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### License
|
### License
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
"email": "pdt256@gmail.com"
|
"email": "pdt256@gmail.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {},
|
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "4.0.*"
|
"phpunit/phpunit": "4.0.*"
|
||||||
},
|
},
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace pdt256\Shipping\Fedex;
|
namespace pdt256\Shipping\Fedex;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
use pdt256\Shipping;
|
use pdt256\Shipping;
|
||||||
use pdt256\Shipping\Arr;
|
use pdt256\Shipping\Arr;
|
||||||
|
use pdt256\Shipping\Quote;
|
||||||
use pdt256\Shipping\RateAdapter;
|
use pdt256\Shipping\RateAdapter;
|
||||||
use pdt256\Shipping\RateRequest;
|
use pdt256\Shipping\RateRequest;
|
||||||
use DOMDocument;
|
use DOMDocument;
|
||||||
@ -88,17 +90,6 @@ class Rate extends RateAdapter
|
|||||||
|
|
||||||
protected function prepare()
|
protected function prepare()
|
||||||
{
|
{
|
||||||
$to = Arr::get($this->shipment, 'to');
|
|
||||||
$shipper = Arr::get($this->shipment, 'from');
|
|
||||||
$dimensions = Arr::get($this->shipment, 'dimensions');
|
|
||||||
|
|
||||||
$pounds = (int) Arr::get($this->shipment, 'weight');
|
|
||||||
$ounces = 0;
|
|
||||||
|
|
||||||
if ($pounds < 1) {
|
|
||||||
throw new Exception('Weight missing');
|
|
||||||
}
|
|
||||||
|
|
||||||
$date = time();
|
$date = time();
|
||||||
$day_name = date('l', $date);
|
$day_name = date('l', $date);
|
||||||
|
|
||||||
@ -111,6 +102,28 @@ class Rate extends RateAdapter
|
|||||||
// http://www.fedex.com/templates/components/apps/wpor/secure/downloads/pdf/Aug13/PropDevGuide.pdf
|
// http://www.fedex.com/templates/components/apps/wpor/secure/downloads/pdf/Aug13/PropDevGuide.pdf
|
||||||
// http://www.fedex.com/us/developer/product/WebServices/MyWebHelp_August2010/Content/Proprietary_Developer_Guide/Rate_Services_conditionalized.htm
|
// http://www.fedex.com/us/developer/product/WebServices/MyWebHelp_August2010/Content/Proprietary_Developer_Guide/Rate_Services_conditionalized.htm
|
||||||
|
|
||||||
|
|
||||||
|
$packages = '';
|
||||||
|
$sequence_number = 0;
|
||||||
|
foreach ($this->shipment->getPackages() as $p) {
|
||||||
|
$sequence_number++;
|
||||||
|
|
||||||
|
$packages .= '<RequestedPackageLineItems>
|
||||||
|
<SequenceNumber>' . $sequence_number . '</SequenceNumber>
|
||||||
|
<GroupPackageCount>1</GroupPackageCount>
|
||||||
|
<Weight>
|
||||||
|
<Units>LB</Units>
|
||||||
|
<Value>' . $p->getWeight() . '</Value>
|
||||||
|
</Weight>
|
||||||
|
<Dimensions>
|
||||||
|
<Length>' . $p->getLength() . '</Length>
|
||||||
|
<Width>' . $p->getWidth() . '</Width>
|
||||||
|
<Height>' . $p->getHeight() . '</Height>
|
||||||
|
<Units>IN</Units>
|
||||||
|
</Dimensions>
|
||||||
|
</RequestedPackageLineItems>';
|
||||||
|
}
|
||||||
|
|
||||||
$this->data =
|
$this->data =
|
||||||
'<?xml version="1.0"?>
|
'<?xml version="1.0"?>
|
||||||
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://fedex.com/ws/rate/v13">
|
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://fedex.com/ws/rate/v13">
|
||||||
@ -136,37 +149,24 @@ class Rate extends RateAdapter
|
|||||||
<RequestedShipment>
|
<RequestedShipment>
|
||||||
<ShipTimestamp>' . date('c') . '</ShipTimestamp>
|
<ShipTimestamp>' . date('c') . '</ShipTimestamp>
|
||||||
<DropoffType>' . $this->drop_off_type . '</DropoffType>
|
<DropoffType>' . $this->drop_off_type . '</DropoffType>
|
||||||
<PackagingType>' . Arr::get($this->shipment, 'packaging_type') . '</PackagingType>
|
<PackagingType>YOUR_PACKAGING</PackagingType>
|
||||||
<Shipper>
|
<Shipper>
|
||||||
<Address>
|
<Address>
|
||||||
<PostalCode>' . Arr::get($shipper, 'postal_code') . '</PostalCode>
|
<PostalCode>' . $this->shipment->getFromPostalCode() . '</PostalCode>
|
||||||
<CountryCode>' . Arr::get($shipper, 'country_code') . '</CountryCode>
|
<CountryCode>' . $this->shipment->getFromCountryCode() . '</CountryCode>
|
||||||
' . ((Arr::get($shipper, 'is_residential')) ? '<Residential>1</Residential>' : '') . '
|
' . (($this->shipment->isFromResidential()) ? '<Residential>1</Residential>' : '') . '
|
||||||
</Address>
|
</Address>
|
||||||
</Shipper>
|
</Shipper>
|
||||||
<Recipient>
|
<Recipient>
|
||||||
<Address>
|
<Address>
|
||||||
<PostalCode>' . Arr::get($to, 'postal_code') . '</PostalCode>
|
<PostalCode>' . $this->shipment->getToPostalCode() . '</PostalCode>
|
||||||
<CountryCode>' . Arr::get($to, 'country_code') . '</CountryCode>
|
<CountryCode>' . $this->shipment->getToCountryCode() . '</CountryCode>
|
||||||
' . ((Arr::get($to, 'is_residential')) ? '<Residential>1</Residential>' : '') . '
|
' . (($this->shipment->isToResidential()) ? '<Residential>1</Residential>' : '') . '
|
||||||
</Address>
|
</Address>
|
||||||
</Recipient>
|
</Recipient>
|
||||||
<RateRequestTypes>LIST</RateRequestTypes>
|
<RateRequestTypes>LIST</RateRequestTypes>
|
||||||
<PackageCount>1</PackageCount>
|
<PackageCount>' . $this->shipment->packageCount() . '</PackageCount>
|
||||||
<RequestedPackageLineItems>
|
' . $packages . '
|
||||||
<SequenceNumber>1</SequenceNumber>
|
|
||||||
<GroupPackageCount>1</GroupPackageCount>
|
|
||||||
<Weight>
|
|
||||||
<Units>LB</Units>
|
|
||||||
<Value>' . $pounds . '</Value>
|
|
||||||
</Weight>
|
|
||||||
<Dimensions>
|
|
||||||
<Length>' . Arr::get($dimensions, 'length') . '</Length>
|
|
||||||
<Width>' . Arr::get($dimensions, 'width') . '</Width>
|
|
||||||
<Height>' . Arr::get($dimensions, 'height') . '</Height>
|
|
||||||
<Units>IN</Units>
|
|
||||||
</Dimensions>
|
|
||||||
</RequestedPackageLineItems>
|
|
||||||
</RequestedShipment>
|
</RequestedShipment>
|
||||||
</RateRequest>
|
</RateRequest>
|
||||||
</SOAP-ENV:Body>
|
</SOAP-ENV:Body>
|
||||||
@ -222,13 +222,18 @@ class Rate extends RateAdapter
|
|||||||
->getElementsByTagName('TotalNetCharge')->item(0)
|
->getElementsByTagName('TotalNetCharge')->item(0)
|
||||||
->getElementsByTagName('Amount')->item(0)->nodeValue;
|
->getElementsByTagName('Amount')->item(0)->nodeValue;
|
||||||
|
|
||||||
$this->rates[] = array(
|
$quote = new Quote;
|
||||||
'code' => $code,
|
$quote
|
||||||
'name' => $name,
|
->setCarrier('fedex')
|
||||||
'cost' => (int) ($cost * 100),
|
->setCode($code)
|
||||||
'delivery_ts' => $delivery_ts,
|
->setName($name)
|
||||||
'transit_time' => $transit_time,
|
->setCost((int) $cost * 100)
|
||||||
);
|
->setTransitTime($transit_time);
|
||||||
|
if ($delivery_ts) {
|
||||||
|
$quote->setDeliveryEstimate(new DateTime($delivery_ts));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->rates[] = $quote;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
81
src/Package.php
Normal file
81
src/Package.php
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
<?php namespace pdt256\Shipping;
|
||||||
|
|
||||||
|
class Package
|
||||||
|
{
|
||||||
|
protected $weight;
|
||||||
|
protected $width;
|
||||||
|
protected $length;
|
||||||
|
protected $height;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getWeight()
|
||||||
|
{
|
||||||
|
return $this->weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $weight
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setWeight($weight)
|
||||||
|
{
|
||||||
|
$this->weight = $weight;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getWidth()
|
||||||
|
{
|
||||||
|
return $this->width;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $width
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setWidth($width)
|
||||||
|
{
|
||||||
|
$this->width = $width;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getLength()
|
||||||
|
{
|
||||||
|
return $this->length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $length
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setLength($length)
|
||||||
|
{
|
||||||
|
$this->length = $length;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getHeight()
|
||||||
|
{
|
||||||
|
return $this->height;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $height
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setHeight($height)
|
||||||
|
{
|
||||||
|
$this->height = $height;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
123
src/Quote.php
Normal file
123
src/Quote.php
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
<?php namespace pdt256\Shipping;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
|
class Quote
|
||||||
|
{
|
||||||
|
protected $code;
|
||||||
|
protected $name;
|
||||||
|
protected $cost;
|
||||||
|
protected $transit_time;
|
||||||
|
protected $delivery_ts;
|
||||||
|
protected $carrier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getCarrier()
|
||||||
|
{
|
||||||
|
return $this->carrier;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $carrier
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setCarrier($carrier)
|
||||||
|
{
|
||||||
|
$this->carrier = $carrier;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getCode()
|
||||||
|
{
|
||||||
|
return $this->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $code
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setCode($code)
|
||||||
|
{
|
||||||
|
$this->code = $code;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setName($name)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getCost()
|
||||||
|
{
|
||||||
|
return $this->cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quoted cost of this service, in pennies
|
||||||
|
*
|
||||||
|
* @param int $cost
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setCost($cost)
|
||||||
|
{
|
||||||
|
$this->cost = $cost;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getTransitTime()
|
||||||
|
{
|
||||||
|
return $this->transit_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $transit_time
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setTransitTime($transit_time)
|
||||||
|
{
|
||||||
|
$this->transit_time = $transit_time;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getDeliveryEstimate()
|
||||||
|
{
|
||||||
|
return $this->delivery_ts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param DateTime $estimate
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setDeliveryEstimate(DateTime $estimate)
|
||||||
|
{
|
||||||
|
$this->delivery_ts = $estimate;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@ abstract class RateAdapter
|
|||||||
{
|
{
|
||||||
protected $is_prod = FALSE;
|
protected $is_prod = FALSE;
|
||||||
|
|
||||||
|
/** @var Shipment */
|
||||||
protected $shipment;
|
protected $shipment;
|
||||||
protected $data;
|
protected $data;
|
||||||
protected $response;
|
protected $response;
|
||||||
@ -27,18 +28,6 @@ abstract class RateAdapter
|
|||||||
if (isset($options['shipment'])) {
|
if (isset($options['shipment'])) {
|
||||||
$this->shipment = $options['shipment'];
|
$this->shipment = $options['shipment'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($this->shipment['to'])) {
|
|
||||||
throw new Exception('Shipment "to" missing');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($this->shipment['from'])) {
|
|
||||||
throw new Exception('Shipment "from" missing');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($this->shipment['dimensions'])) {
|
|
||||||
throw new Exception('Shipment "dimensions" missing');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set_request_adapter(RateRequest\Adapter $rate_request)
|
public function set_request_adapter(RateRequest\Adapter $rate_request)
|
||||||
@ -54,11 +43,11 @@ abstract class RateAdapter
|
|||||||
->process()
|
->process()
|
||||||
->sort_by_cost();
|
->sort_by_cost();
|
||||||
|
|
||||||
return $this->rates;
|
return array_values($this->rates);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function sort_by_cost()
|
protected function sort_by_cost()
|
||||||
{
|
{
|
||||||
uasort($this->rates, create_function('$a, $b', 'return ($a["cost"] > $b["cost"]);'));
|
uasort($this->rates, create_function('$a, $b', 'return ($a->getCost() > $b->getCost());'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
src/Ship.php
12
src/Ship.php
@ -88,13 +88,13 @@ class Ship
|
|||||||
|
|
||||||
foreach ($rates[$carrier] as $row3) {
|
foreach ($rates[$carrier] as $row3) {
|
||||||
|
|
||||||
if (in_array($row3['code'], $group_codes)) {
|
if (in_array($row3->getCode(), $group_codes)) {
|
||||||
$row3['carrier'] = $carrier;
|
$row3->setCarrier($carrier);
|
||||||
|
|
||||||
if ($cheapest_row === NULL) {
|
if ($cheapest_row === NULL) {
|
||||||
$cheapest_row = $row3;
|
$cheapest_row = $row3;
|
||||||
} else {
|
} else {
|
||||||
if ($row3['cost'] < $cheapest_row['cost']) {
|
if ($row3->getCost() < $cheapest_row->getCost()) {
|
||||||
$cheapest_row = $row3;
|
$cheapest_row = $row3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,8 +126,8 @@ class Ship
|
|||||||
|
|
||||||
foreach ($rates[$carrier] as $row3) {
|
foreach ($rates[$carrier] as $row3) {
|
||||||
|
|
||||||
if (in_array($row3['code'], $group_codes)) {
|
if (in_array($row3->getCode(), $group_codes)) {
|
||||||
$row3['carrier'] = $carrier;
|
$row3->setCarrier($carrier);
|
||||||
$display_rates[$shipping_group][] = $row3;
|
$display_rates[$shipping_group][] = $row3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,6 +142,6 @@ class Ship
|
|||||||
|
|
||||||
protected function sort_by_cost( & $rates)
|
protected function sort_by_cost( & $rates)
|
||||||
{
|
{
|
||||||
uasort($rates, create_function('$a, $b', 'return ($a["cost"] > $b["cost"]);'));
|
uasort($rates, create_function('$a, $b', 'return ($a->getCost() > $b->getCost());'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
169
src/Shipment.php
Normal file
169
src/Shipment.php
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
<?php namespace pdt256\Shipping;
|
||||||
|
|
||||||
|
class Shipment
|
||||||
|
{
|
||||||
|
/** @var Package[] */
|
||||||
|
protected $packages = [];
|
||||||
|
|
||||||
|
protected $from_postal_code;
|
||||||
|
protected $from_country_code;
|
||||||
|
protected $to_postal_code;
|
||||||
|
protected $to_country_code;
|
||||||
|
/** @var bool */
|
||||||
|
protected $to_is_residential;
|
||||||
|
/** @var bool */
|
||||||
|
protected $from_is_residential;
|
||||||
|
protected $from_state_province;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Package $package
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function addPackage(Package $package)
|
||||||
|
{
|
||||||
|
$this->packages[] = $package;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Package[]
|
||||||
|
*/
|
||||||
|
public function getPackages()
|
||||||
|
{
|
||||||
|
return $this->packages;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function packageCount()
|
||||||
|
{
|
||||||
|
return count($this->getPackages());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getFromPostalCode()
|
||||||
|
{
|
||||||
|
return $this->from_postal_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $from_postal_code
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setFromPostalCode($from_postal_code)
|
||||||
|
{
|
||||||
|
$this->from_postal_code = $from_postal_code;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getFromCountryCode()
|
||||||
|
{
|
||||||
|
return $this->from_country_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $from_country_code
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setFromCountryCode($from_country_code)
|
||||||
|
{
|
||||||
|
$this->from_country_code = $from_country_code;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getToPostalCode()
|
||||||
|
{
|
||||||
|
return $this->to_postal_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $to_postal_code
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setToPostalCode($to_postal_code)
|
||||||
|
{
|
||||||
|
$this->to_postal_code = $to_postal_code;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getToCountryCode()
|
||||||
|
{
|
||||||
|
return $this->to_country_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $to_country_code
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setToCountryCode($to_country_code)
|
||||||
|
{
|
||||||
|
$this->to_country_code = $to_country_code;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isToResidential()
|
||||||
|
{
|
||||||
|
return $this->to_is_residential;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param boolean $to_is_residential
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setToResidential($to_is_residential)
|
||||||
|
{
|
||||||
|
$this->to_is_residential = $to_is_residential;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isFromResidential()
|
||||||
|
{
|
||||||
|
return $this->from_is_residential;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $from_is_residential
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setFromResidential($from_is_residential)
|
||||||
|
{
|
||||||
|
$this->from_is_residential = $from_is_residential;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getFromStateProvinceCode()
|
||||||
|
{
|
||||||
|
return $this->from_state_province;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $from_state_province
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setFromStateProvinceCode($from_state_province)
|
||||||
|
{
|
||||||
|
$this->from_state_province = $from_state_province;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ namespace pdt256\Shipping\UPS;
|
|||||||
|
|
||||||
use pdt256\Ship;
|
use pdt256\Ship;
|
||||||
use pdt256\Shipping\Arr;
|
use pdt256\Shipping\Arr;
|
||||||
|
use pdt256\Shipping\Quote;
|
||||||
use pdt256\Shipping\RateAdapter;
|
use pdt256\Shipping\RateAdapter;
|
||||||
use pdt256\Shipping\RateRequest;
|
use pdt256\Shipping\RateRequest;
|
||||||
use DOMDocument;
|
use DOMDocument;
|
||||||
@ -114,19 +115,31 @@ class Rate extends RateAdapter
|
|||||||
|
|
||||||
protected function prepare()
|
protected function prepare()
|
||||||
{
|
{
|
||||||
$to = Arr::get($this->shipment, 'to');
|
|
||||||
$shipper = Arr::get($this->shipment, 'from');
|
|
||||||
$dimensions = Arr::get($this->shipment, 'dimensions');
|
|
||||||
|
|
||||||
$pounds = (int) Arr::get($this->shipment, 'weight');
|
|
||||||
$ounces = 0;
|
|
||||||
|
|
||||||
if ($pounds < 1) {
|
|
||||||
throw new Exception('Weight missing');
|
|
||||||
}
|
|
||||||
|
|
||||||
$service_code = '03';
|
$service_code = '03';
|
||||||
|
|
||||||
|
$packages = '';
|
||||||
|
foreach ($this->shipment->getPackages() as $p) {
|
||||||
|
$packages .= '<Package>
|
||||||
|
<PackagingType>
|
||||||
|
<Code>02</Code>
|
||||||
|
</PackagingType>
|
||||||
|
<Dimensions>
|
||||||
|
<UnitOfMeasurement>
|
||||||
|
<Code>IN</Code>
|
||||||
|
</UnitOfMeasurement>
|
||||||
|
<Length>' . $p->getLength() . '</Length>
|
||||||
|
<Width>' . $p->getWidth() . '</Width>
|
||||||
|
<Height>' . $p->getHeight() . '</Height>
|
||||||
|
</Dimensions>
|
||||||
|
<PackageWeight>
|
||||||
|
<UnitOfMeasurement>
|
||||||
|
<Code>LBS</Code>
|
||||||
|
</UnitOfMeasurement>
|
||||||
|
<Weight>' . $p->getWeight() . '</Weight>
|
||||||
|
</PackageWeight>
|
||||||
|
</Package>';
|
||||||
|
}
|
||||||
|
|
||||||
$this->data =
|
$this->data =
|
||||||
'<?xml version="1.0"?>
|
'<?xml version="1.0"?>
|
||||||
<AccessRequest xml:lang="en-US">
|
<AccessRequest xml:lang="en-US">
|
||||||
@ -142,48 +155,34 @@ class Rate extends RateAdapter
|
|||||||
<Shipment>
|
<Shipment>
|
||||||
<Shipper>
|
<Shipper>
|
||||||
<Address>
|
<Address>
|
||||||
<PostalCode>' . Arr::get($shipper, 'postal_code') . '</PostalCode>
|
<PostalCode>' . $this->shipment->getFromPostalCode() . '</PostalCode>
|
||||||
<CountryCode>' . Arr::get($shipper, 'country_code') . '</CountryCode>
|
<CountryCode>' . $this->shipment->getFromCountryCode() . '</CountryCode>
|
||||||
' . ((Arr::get($shipper, 'is_residential')) ? '<ResidentialAddressIndicator>1</ResidentialAddressIndicator>' : '') . '
|
' . (($this->shipment->isFromResidential()) ? '<ResidentialAddressIndicator>1</ResidentialAddressIndicator>' : '') . '
|
||||||
</Address>
|
</Address>
|
||||||
<ShipperNumber>' . $this->shipper_number . '</ShipperNumber>
|
<ShipperNumber>' . $this->shipper_number . '</ShipperNumber>
|
||||||
</Shipper>
|
</Shipper>
|
||||||
<ShipTo>
|
<ShipTo>
|
||||||
<Address>
|
<Address>
|
||||||
<PostalCode>' . Arr::get($to, 'postal_code') . '</PostalCode>
|
<PostalCode>' . $this->shipment->getToPostalCode() . '</PostalCode>
|
||||||
<CountryCode>' . Arr::get($to, 'country_code') . '</CountryCode>
|
<CountryCode>' . $this->shipment->getToCountryCode() . '</CountryCode>
|
||||||
' . ((Arr::get($to, 'is_residential')) ? '<ResidentialAddressIndicator>1</ResidentialAddressIndicator>' : '') . '
|
' . (($this->shipment->isToResidential()) ? '<ResidentialAddressIndicator>1</ResidentialAddressIndicator>' : '') . '
|
||||||
</Address>
|
</Address>
|
||||||
</ShipTo>
|
</ShipTo>
|
||||||
<ShipFrom>
|
<ShipFrom>
|
||||||
<Address>
|
<Address>
|
||||||
<PostalCode>' . Arr::get($shipper, 'postal_code') . '</PostalCode>
|
<StateProvinceCode>' . $this->shipment->getFromStateProvinceCode() . '</StateProvinceCode>
|
||||||
<CountryCode>' . Arr::get($shipper, 'country_code') . '</CountryCode>
|
<PostalCode>' . $this->shipment->getFromPostalCode() . '</PostalCode>
|
||||||
' . ((Arr::get($shipper, 'is_residential')) ? '<ResidentialAddressIndicator>1</ResidentialAddressIndicator>' : '') . '
|
<CountryCode>' . $this->shipment->getFromCountryCode() . '</CountryCode>
|
||||||
|
' . (($this->shipment->isFromResidential()) ? '<ResidentialAddressIndicator>1</ResidentialAddressIndicator>' : '') . '
|
||||||
</Address>
|
</Address>
|
||||||
</ShipFrom>
|
</ShipFrom>
|
||||||
<Service>
|
<Service>
|
||||||
<Code>' . $service_code . '</Code>
|
<Code>' . $service_code . '</Code>
|
||||||
</Service>
|
</Service>
|
||||||
<Package>
|
' . $packages . '
|
||||||
<PackagingType>
|
<RateInformation>
|
||||||
<Code>02</Code>
|
<NegotiatedRatesIndicator/>
|
||||||
</PackagingType>
|
</RateInformation>
|
||||||
<Dimensions>
|
|
||||||
<UnitOfMeasurement>
|
|
||||||
<Code>IN</Code>
|
|
||||||
</UnitOfMeasurement>
|
|
||||||
<Length>' . Arr::get($dimensions, 'length') . '</Length>
|
|
||||||
<Width>' . Arr::get($dimensions, 'width') . '</Width>
|
|
||||||
<Height>' . Arr::get($dimensions, 'height') . '</Height>
|
|
||||||
</Dimensions>
|
|
||||||
<PackageWeight>
|
|
||||||
<UnitOfMeasurement>
|
|
||||||
<Code>LBS</Code>
|
|
||||||
</UnitOfMeasurement>
|
|
||||||
<Weight>' . $pounds . '</Weight>
|
|
||||||
</PackageWeight>
|
|
||||||
</Package>
|
|
||||||
</Shipment>
|
</Shipment>
|
||||||
</RatingServiceSelectionRequest>';
|
</RatingServiceSelectionRequest>';
|
||||||
|
|
||||||
@ -235,11 +234,13 @@ class Rate extends RateAdapter
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->rates[] = array(
|
$quote = new Quote;
|
||||||
'code' => $code,
|
$quote
|
||||||
'name' => $name,
|
->setCarrier('ups')
|
||||||
'cost' => (int) ($cost * 100),
|
->setCode($code)
|
||||||
);
|
->setName($name)
|
||||||
|
->setCost((int) $cost * 100);
|
||||||
|
$this->rates[] = $quote;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -3,6 +3,7 @@ namespace pdt256\Shipping\USPS;
|
|||||||
|
|
||||||
use pdt256\Shipping;
|
use pdt256\Shipping;
|
||||||
use pdt256\Shipping\Arr;
|
use pdt256\Shipping\Arr;
|
||||||
|
use pdt256\Shipping\Quote;
|
||||||
use pdt256\Shipping\RateAdapter;
|
use pdt256\Shipping\RateAdapter;
|
||||||
use pdt256\Shipping\RateRequest;
|
use pdt256\Shipping\RateRequest;
|
||||||
use DOMDocument;
|
use DOMDocument;
|
||||||
@ -95,34 +96,54 @@ class Rate extends RateAdapter
|
|||||||
|
|
||||||
protected function prepare()
|
protected function prepare()
|
||||||
{
|
{
|
||||||
$to = Arr::get($this->shipment, 'to');
|
|
||||||
$shipper = Arr::get($this->shipment, 'from');
|
|
||||||
$dimensions = Arr::get($this->shipment, 'dimensions');
|
|
||||||
|
|
||||||
// https://www.usps.com/business/web-tools-apis/rate-calculators-v1-7a.htm
|
$packages = '';
|
||||||
$pounds = (int) Arr::get($this->shipment, 'weight');
|
$sequence_number = 0;
|
||||||
$ounces = 0;
|
foreach ($this->shipment->getPackages() as $p) {
|
||||||
|
$sequence_number++;
|
||||||
|
|
||||||
if ($pounds < 1) {
|
/**
|
||||||
throw new Exception('Weight missing');
|
* RateV4Request / Package / Size
|
||||||
|
required once
|
||||||
|
Defined as follows:
|
||||||
|
|
||||||
|
REGULAR: Package dimensions are 12’’ or less;
|
||||||
|
LARGE: Any package dimension is larger than 12’’.
|
||||||
|
|
||||||
|
For example: <Size>REGULAR</Size>
|
||||||
|
string
|
||||||
|
whiteSpace=collapse
|
||||||
|
enumeration=LARGE
|
||||||
|
enumeration=REGULAR
|
||||||
|
|
||||||
|
*/
|
||||||
|
if ($p->getWidth() > 12 or $p->getLength() > 12 or $p->getHeight() > 12) {
|
||||||
|
$size = 'LARGE';
|
||||||
|
$container = 'RECTANGULAR';
|
||||||
|
} else {
|
||||||
|
$size = 'REGULAR';
|
||||||
|
$container = 'VARIABLE';
|
||||||
|
}
|
||||||
|
|
||||||
|
$packages .= '<Package ID="' . $sequence_number .'">
|
||||||
|
<Service>ALL</Service>
|
||||||
|
<ZipOrigination>' . $this->shipment->getFromPostalCode() . '</ZipOrigination>
|
||||||
|
<ZipDestination>' . $this->shipment->getToPostalCode() . '</ZipDestination>
|
||||||
|
<Pounds>' . $p->getWeight() . '</Pounds>
|
||||||
|
<Ounces>0</Ounces>
|
||||||
|
<Container>' . $container . '</Container>
|
||||||
|
<Size>' . $size . '</Size>
|
||||||
|
<Width>' . $p->getWidth() . '</Width>
|
||||||
|
<Length>' . $p->getLength() . '</Length>
|
||||||
|
<Height>' . $p->getHeight() . '</Height>
|
||||||
|
<Machinable>' . 'False' . '</Machinable>
|
||||||
|
</Package>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->data =
|
$this->data =
|
||||||
'<RateV4Request USERID="' . $this->username . '">
|
'<RateV4Request USERID="' . $this->username . '">
|
||||||
<Revision/>
|
<Revision/>
|
||||||
<Package ID="1">
|
' . $packages . '
|
||||||
<Service>ALL</Service>
|
|
||||||
<ZipOrigination>' . Arr::get($shipper, 'postal_code') . '</ZipOrigination>
|
|
||||||
<ZipDestination>' . Arr::get($to, 'postal_code') . '</ZipDestination>
|
|
||||||
<Pounds>' . $pounds . '</Pounds>
|
|
||||||
<Ounces>' . $ounces . '</Ounces>
|
|
||||||
<Container>' . Arr::get($this->shipment, 'container') . '</Container>
|
|
||||||
<Size>' . Arr::get($this->shipment, 'size') . '</Size>
|
|
||||||
<Width>' . Arr::get($dimensions, 'width') . '</Width>
|
|
||||||
<Length>' . Arr::get($dimensions, 'length') . '</Length>
|
|
||||||
<Height>' . Arr::get($dimensions, 'height') . '</Height>
|
|
||||||
<Machinable>' . 'False' . '</Machinable>
|
|
||||||
</Package>
|
|
||||||
</RateV4Request>';
|
</RateV4Request>';
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -160,6 +181,9 @@ class Rate extends RateAdapter
|
|||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @var Quote[] $rates */
|
||||||
|
$rates = [];
|
||||||
|
|
||||||
foreach ($postage_list as $postage) {
|
foreach ($postage_list as $postage) {
|
||||||
$code = @$postage->getAttribute('CLASSID');
|
$code = @$postage->getAttribute('CLASSID');
|
||||||
$cost = @$postage->getElementsByTagName('Rate')->item(0)->nodeValue;
|
$cost = @$postage->getElementsByTagName('Rate')->item(0)->nodeValue;
|
||||||
@ -170,13 +194,24 @@ class Rate extends RateAdapter
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->rates[] = array(
|
if (array_key_exists($code, $rates)) {
|
||||||
'code' => $code,
|
$cost = $rates[$code]->getCost() + ($cost * 100);
|
||||||
'name' => $name,
|
} else {
|
||||||
'cost' => (int) ($cost * 100),
|
$cost = $cost * 100;
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$quote = new Quote;
|
||||||
|
$quote
|
||||||
|
->setCarrier('usps')
|
||||||
|
->setCode($code)
|
||||||
|
->setName($name)
|
||||||
|
->setCost((int) $cost);
|
||||||
|
|
||||||
|
$rates[$quote->getCode()] = $quote;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->rates = array_values($rates);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
use pdt256\Shipping\Package;
|
||||||
|
use pdt256\Shipping\Quote;
|
||||||
use pdt256\Shipping\Ship;
|
use pdt256\Shipping\Ship;
|
||||||
|
use pdt256\Shipping\Shipment;
|
||||||
use pdt256\Shipping\USPS;
|
use pdt256\Shipping\USPS;
|
||||||
use pdt256\Shipping\UPS;
|
use pdt256\Shipping\UPS;
|
||||||
use pdt256\Shipping\Fedex;
|
use pdt256\Shipping\Fedex;
|
||||||
@ -7,23 +10,8 @@ use pdt256\Shipping\RateRequest;
|
|||||||
|
|
||||||
class ShipTest extends PHPUnit_Framework_TestCase
|
class ShipTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public $shipment = [
|
/** @var Shipment */
|
||||||
'weight' => 3, // lbs
|
public $shipment;
|
||||||
'dimensions' => [
|
|
||||||
'width' => 9,
|
|
||||||
'length' => 9,
|
|
||||||
'height' => 9,
|
|
||||||
],
|
|
||||||
'from' => [
|
|
||||||
'postal_code' => '90401',
|
|
||||||
'country_code' => 'US',
|
|
||||||
],
|
|
||||||
'to' => [
|
|
||||||
'postal_code' => '78703',
|
|
||||||
'country_code' => 'US',
|
|
||||||
'is_residential' => TRUE,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
public $shipping_options = [
|
public $shipping_options = [
|
||||||
'Standard Shipping' => [
|
'Standard Shipping' => [
|
||||||
@ -60,6 +48,27 @@ class ShipTest extends PHPUnit_Framework_TestCase
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$s = new Shipment;
|
||||||
|
$s->setFromStateProvinceCode('CA')
|
||||||
|
->setFromPostalCode('90401')
|
||||||
|
->setFromCountryCode('US')
|
||||||
|
->setToPostalCode('78703')
|
||||||
|
->setToCountryCode('US')
|
||||||
|
->setToResidential(true);
|
||||||
|
|
||||||
|
$p = new Package;
|
||||||
|
$p->setWeight(3)
|
||||||
|
->setWidth(9)
|
||||||
|
->setLength(9)
|
||||||
|
->setHeight(9);
|
||||||
|
|
||||||
|
$s->addPackage($p);
|
||||||
|
|
||||||
|
$this->shipment = $s;
|
||||||
|
}
|
||||||
|
|
||||||
private function getUSPSOptions()
|
private function getUSPSOptions()
|
||||||
{
|
{
|
||||||
$ship = Ship::factory($this->shipping_options);
|
$ship = Ship::factory($this->shipping_options);
|
||||||
@ -69,10 +78,7 @@ class ShipTest extends PHPUnit_Framework_TestCase
|
|||||||
'prod' => FALSE,
|
'prod' => FALSE,
|
||||||
'username' => 'XXXX',
|
'username' => 'XXXX',
|
||||||
'password' => 'XXXX',
|
'password' => 'XXXX',
|
||||||
'shipment' => array_merge($this->shipment, [
|
'shipment' => $this->shipment,
|
||||||
'size' => 'LARGE',
|
|
||||||
'container' => 'RECTANGULAR',
|
|
||||||
]),
|
|
||||||
'approved_codes' => $approved_codes,
|
'approved_codes' => $approved_codes,
|
||||||
'request_adapter' => new RateRequest\StubUSPS(),
|
'request_adapter' => new RateRequest\StubUSPS(),
|
||||||
];
|
];
|
||||||
@ -107,9 +113,7 @@ class ShipTest extends PHPUnit_Framework_TestCase
|
|||||||
'account_number' => 'XXXX',
|
'account_number' => 'XXXX',
|
||||||
'meter_number' => 'XXXX',
|
'meter_number' => 'XXXX',
|
||||||
'drop_off_type' => 'BUSINESS_SERVICE_CENTER',
|
'drop_off_type' => 'BUSINESS_SERVICE_CENTER',
|
||||||
'shipment' => array_merge($this->shipment, [
|
'shipment' => $this->shipment,
|
||||||
'packaging_type' => 'YOUR_PACKAGING',
|
|
||||||
]),
|
|
||||||
'approved_codes' => $approved_codes,
|
'approved_codes' => $approved_codes,
|
||||||
'request_adapter' => new RateRequest\StubFedex(),
|
'request_adapter' => new RateRequest\StubFedex(),
|
||||||
];
|
];
|
||||||
@ -120,18 +124,23 @@ class ShipTest extends PHPUnit_Framework_TestCase
|
|||||||
$usps = new USPS\Rate($this->getUSPSOptions());
|
$usps = new USPS\Rate($this->getUSPSOptions());
|
||||||
$usps_rates = $usps->get_rates();
|
$usps_rates = $usps->get_rates();
|
||||||
|
|
||||||
$this->assertEquals(json_encode([
|
$post = new Quote;
|
||||||
1 => [
|
$post
|
||||||
'code' => '4',
|
->setCarrier('usps')
|
||||||
'name' => 'Parcel Post',
|
->setCode(4)
|
||||||
'cost' => 1001,
|
->setName('Parcel Post')
|
||||||
],
|
->setCost(1001);
|
||||||
0 => [
|
|
||||||
'code' => '1',
|
$priority = new Quote;
|
||||||
'name' => 'Priority Mail',
|
$priority
|
||||||
'cost' => 1220,
|
->setCarrier('usps')
|
||||||
],
|
->setCode(1)
|
||||||
]), json_encode($usps_rates));
|
->setName('Priority Mail')
|
||||||
|
->setCost(1220);
|
||||||
|
|
||||||
|
$expected_return = [$post, $priority];
|
||||||
|
|
||||||
|
$this->assertEquals($expected_return, $usps_rates);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUPSRate()
|
public function testUPSRate()
|
||||||
@ -139,28 +148,37 @@ class ShipTest extends PHPUnit_Framework_TestCase
|
|||||||
$ups = new UPS\Rate($this->getUPSOptions());
|
$ups = new UPS\Rate($this->getUPSOptions());
|
||||||
$ups_rates = $ups->get_rates();
|
$ups_rates = $ups->get_rates();
|
||||||
|
|
||||||
$this->assertEquals(json_encode([
|
$ground = new Quote;
|
||||||
0 => [
|
$ground
|
||||||
'code' => '03',
|
->setCarrier('ups')
|
||||||
'name' => 'UPS Ground',
|
->setCode('03')
|
||||||
'cost' => 1910,
|
->setName('UPS Ground')
|
||||||
],
|
->setCost(1900);
|
||||||
1 => [
|
|
||||||
'code' => '02',
|
$twodayair = new Quote;
|
||||||
'name' => 'UPS 2nd Day Air',
|
$twodayair
|
||||||
'cost' => 4923,
|
->setCarrier('ups')
|
||||||
],
|
->setCode('02')
|
||||||
2 => [
|
->setName('UPS 2nd Day Air')
|
||||||
'code' => '13',
|
->setCost(4900);
|
||||||
'name' => 'UPS Next Day Air Saver',
|
|
||||||
'cost' => 8954,
|
$nextdaysaver = new Quote;
|
||||||
],
|
$nextdaysaver
|
||||||
3 => [
|
->setCarrier('ups')
|
||||||
'code' => '01',
|
->setCode('13')
|
||||||
'name' => 'UPS Next Day Air',
|
->setName('UPS Next Day Air Saver')
|
||||||
'cost' => 9328,
|
->setCost(8900);
|
||||||
],
|
|
||||||
]), json_encode($ups_rates));
|
$nextdayair = new Quote;
|
||||||
|
$nextdayair
|
||||||
|
->setCarrier('ups')
|
||||||
|
->setCode('01')
|
||||||
|
->setName('UPS Next Day Air')
|
||||||
|
->setCost(9300);
|
||||||
|
|
||||||
|
$expected_return = [$ground, $twodayair, $nextdaysaver, $nextdayair];
|
||||||
|
|
||||||
|
$this->assertEquals($expected_return, $ups_rates);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFedexRate()
|
public function testFedexRate()
|
||||||
@ -168,36 +186,44 @@ class ShipTest extends PHPUnit_Framework_TestCase
|
|||||||
$fedex = new Fedex\Rate($this->getFedexOptions());
|
$fedex = new Fedex\Rate($this->getFedexOptions());
|
||||||
$fedex_rates = $fedex->get_rates();
|
$fedex_rates = $fedex->get_rates();
|
||||||
|
|
||||||
$this->assertEquals(json_encode([
|
$ground = new Quote;
|
||||||
3 => [
|
$ground
|
||||||
'code' => 'GROUND_HOME_DELIVERY',
|
->setCarrier('fedex')
|
||||||
'name' => 'Ground Home Delivery',
|
->setCode('GROUND_HOME_DELIVERY')
|
||||||
'cost' => 1655,
|
->setName('Ground Home Delivery')
|
||||||
'delivery_ts' => NULL,
|
->setCost(1600)
|
||||||
'transit_time' => 'THREE_DAYS',
|
->setTransitTime('THREE_DAYS');
|
||||||
],
|
|
||||||
2 => [
|
$express = new Quote;
|
||||||
'code' => 'FEDEX_EXPRESS_SAVER',
|
$express
|
||||||
'name' => 'Fedex Express Saver',
|
->setCarrier('fedex')
|
||||||
'cost' => 2989,
|
->setCode('FEDEX_EXPRESS_SAVER')
|
||||||
'delivery_ts' => '2014-09-30T20:00:00',
|
->setName('Fedex Express Saver')
|
||||||
'transit_time' => NULL,
|
->setCost(2900)
|
||||||
],
|
->setDeliveryEstimate(new DateTime('2014-09-30T20:00:00'))
|
||||||
1 => [
|
->setTransitTime(null);
|
||||||
'code' => 'FEDEX_2_DAY',
|
|
||||||
'name' => 'Fedex 2 Day',
|
$secondday = new Quote;
|
||||||
'cost' => 4072,
|
$secondday
|
||||||
'delivery_ts' => '2014-09-29T20:00:00',
|
->setCarrier('fedex')
|
||||||
'transit_time' => NULL,
|
->setCode('FEDEX_2_DAY')
|
||||||
],
|
->setName('Fedex 2 Day')
|
||||||
0 => [
|
->setCost(4000)
|
||||||
'code' => 'STANDARD_OVERNIGHT',
|
->setDeliveryEstimate(new DateTime('2014-09-29T20:00:00'))
|
||||||
'name' => 'Standard Overnight',
|
->setTransitTime(null);
|
||||||
'cost' => 7834,
|
|
||||||
'delivery_ts' => '2014-09-26T20:00:00',
|
$overnight = new Quote;
|
||||||
'transit_time' => NULL,
|
$overnight
|
||||||
],
|
->setCarrier('fedex')
|
||||||
]), json_encode($fedex_rates));
|
->setCode('STANDARD_OVERNIGHT')
|
||||||
|
->setName('Standard Overnight')
|
||||||
|
->setCost(7800)
|
||||||
|
->setDeliveryEstimate(new DateTime('2014-09-26T20:00:00'))
|
||||||
|
->setTransitTime(null);
|
||||||
|
|
||||||
|
$expected_result = [$ground, $express, $secondday, $overnight];
|
||||||
|
|
||||||
|
$this->assertEquals($expected_result, $fedex_rates);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDisplayOptions()
|
public function testDisplayOptions()
|
||||||
@ -216,210 +242,36 @@ class ShipTest extends PHPUnit_Framework_TestCase
|
|||||||
$ship = Ship::factory($this->shipping_options);
|
$ship = Ship::factory($this->shipping_options);
|
||||||
$display_rates = $ship->get_display_rates($rates);
|
$display_rates = $ship->get_display_rates($rates);
|
||||||
|
|
||||||
$this->assertEquals(json_encode([
|
$post = new Quote;
|
||||||
|
$post->setCode(4)
|
||||||
|
->setName('Parcel Post')
|
||||||
|
->setCost(1001)
|
||||||
|
->setCarrier('usps');
|
||||||
|
|
||||||
|
$fedex_two_day = new Quote;
|
||||||
|
$fedex_two_day->setCode('FEDEX_2_DAY')
|
||||||
|
->setName('Fedex 2 Day')
|
||||||
|
->setCost(4000)
|
||||||
|
->setDeliveryEstimate(new DateTime('2014-09-29T20:00:00'))
|
||||||
|
->setCarrier('fedex');
|
||||||
|
|
||||||
|
$overnight = new Quote;
|
||||||
|
$overnight->setCode('STANDARD_OVERNIGHT')
|
||||||
|
->setName('Standard Overnight')
|
||||||
|
->setCost(7800)
|
||||||
|
->setDeliveryEstimate(new DateTime('2014-09-26T20:00:00'))
|
||||||
|
->setCarrier('fedex');
|
||||||
|
|
||||||
|
$this->assertEquals([
|
||||||
'Standard Shipping' => [
|
'Standard Shipping' => [
|
||||||
0 => [
|
$post,
|
||||||
'code' => '4',
|
|
||||||
'name' => 'Parcel Post',
|
|
||||||
'cost' => 1001,
|
|
||||||
'carrier' => 'usps',
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
'Two-Day Shipping' => [
|
'Two-Day Shipping' => [
|
||||||
0 => [
|
$fedex_two_day,
|
||||||
'code' => 'FEDEX_2_DAY',
|
|
||||||
'name' => 'Fedex 2 Day',
|
|
||||||
'cost' => 4072,
|
|
||||||
'delivery_ts' => '2014-09-29T20:00:00',
|
|
||||||
'transit_time' => NULL,
|
|
||||||
'carrier' => 'fedex',
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
'One-Day Shipping' => [
|
'One-Day Shipping' => [
|
||||||
0 => [
|
$overnight,
|
||||||
'code' => 'STANDARD_OVERNIGHT',
|
|
||||||
'name' => 'Standard Overnight',
|
|
||||||
'cost' => 7834,
|
|
||||||
'delivery_ts' => '2014-09-26T20:00:00',
|
|
||||||
'transit_time' => NULL,
|
|
||||||
'carrier' => 'fedex',
|
|
||||||
],
|
],
|
||||||
],
|
], $display_rates);
|
||||||
]), json_encode($display_rates));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException Exception
|
|
||||||
*/
|
|
||||||
public function testUSPSRateMissingTo()
|
|
||||||
{
|
|
||||||
$usps_options = $this->getUSPSOptions();
|
|
||||||
unset($usps_options['shipment']['to']);
|
|
||||||
|
|
||||||
$usps = new USPS\Rate($usps_options);
|
|
||||||
$usps_rates = $usps->get_rates();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException Exception
|
|
||||||
*/
|
|
||||||
public function testUSPSRateMissingFrom()
|
|
||||||
{
|
|
||||||
$usps_options = $this->getUSPSOptions();
|
|
||||||
unset($usps_options['shipment']['from']);
|
|
||||||
|
|
||||||
$usps = new USPS\Rate($usps_options);
|
|
||||||
$usps_rates = $usps->get_rates();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException Exception
|
|
||||||
*/
|
|
||||||
public function testUSPSRateMissingDimensions()
|
|
||||||
{
|
|
||||||
$usps_options = $this->getUSPSOptions();
|
|
||||||
unset($usps_options['shipment']['dimensions']);
|
|
||||||
|
|
||||||
$usps = new USPS\Rate($usps_options);
|
|
||||||
$usps_rates = $usps->get_rates();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException Exception
|
|
||||||
*/
|
|
||||||
public function testUPSRateMissingTo()
|
|
||||||
{
|
|
||||||
$ups_options = $this->getUPSOptions();
|
|
||||||
unset($ups_options['shipment']['to']);
|
|
||||||
|
|
||||||
$ups = new UPS\Rate($ups_options);
|
|
||||||
$ups_rates = $ups->get_rates();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException Exception
|
|
||||||
*/
|
|
||||||
public function testUPSRateMissingFrom()
|
|
||||||
{
|
|
||||||
$ups_options = $this->getUPSOptions();
|
|
||||||
unset($ups_options['shipment']['from']);
|
|
||||||
|
|
||||||
$ups = new UPS\Rate($ups_options);
|
|
||||||
$ups_rates = $ups->get_rates();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException Exception
|
|
||||||
*/
|
|
||||||
public function testUPSRateMissingDimensions()
|
|
||||||
{
|
|
||||||
$ups_options = $this->getUPSOptions();
|
|
||||||
unset($ups_options['shipment']['dimensions']);
|
|
||||||
|
|
||||||
$ups = new UPS\Rate($ups_options);
|
|
||||||
$ups_rates = $ups->get_rates();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException Exception
|
|
||||||
*/
|
|
||||||
public function testFedexRateMissingTo()
|
|
||||||
{
|
|
||||||
$fedex_options = $this->getFedexOptions();
|
|
||||||
unset($fedex_options['shipment']['to']);
|
|
||||||
|
|
||||||
$fedex = new Fedex\Rate($fedex_options);
|
|
||||||
$fedex_rates = $fedex->get_rates();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException Exception
|
|
||||||
*/
|
|
||||||
public function testFedexRateMissingFrom()
|
|
||||||
{
|
|
||||||
$fedex_options = $this->getFedexOptions();
|
|
||||||
unset($fedex_options['shipment']['from']);
|
|
||||||
|
|
||||||
$fedex = new Fedex\Rate($fedex_options);
|
|
||||||
$fedex_rates = $fedex->get_rates();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException Exception
|
|
||||||
*/
|
|
||||||
public function testFedexRateMissingDimensions()
|
|
||||||
{
|
|
||||||
$fedex_options = $this->getFedexOptions();
|
|
||||||
unset($fedex_options['shipment']['dimensions']);
|
|
||||||
|
|
||||||
$fedex = new Fedex\Rate($fedex_options);
|
|
||||||
$fedex_rates = $fedex->get_rates();
|
|
||||||
}
|
|
||||||
|
|
||||||
// // Readme Examples:
|
|
||||||
// public function testUSPSReadmeExample()
|
|
||||||
// {
|
|
||||||
// $usps = new USPS\Rate([
|
|
||||||
// 'prod' => FALSE,
|
|
||||||
// 'username' => 'XXXX',
|
|
||||||
// 'password' => 'XXXX',
|
|
||||||
// 'shipment' => array_merge($this->shipment, [
|
|
||||||
// 'size' => 'LARGE',
|
|
||||||
// 'container' => 'RECTANGULAR',
|
|
||||||
// ]),
|
|
||||||
// 'approved_codes' => [
|
|
||||||
// '1', // 1-3 business days
|
|
||||||
// '4', // 2-8 business days
|
|
||||||
// ],
|
|
||||||
// 'request_adapter' => new RateRequest\StubUSPS(),
|
|
||||||
// ]);
|
|
||||||
//
|
|
||||||
// $usps_rates = $usps->get_rates();
|
|
||||||
// var_export($usps_rates);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public function testUPSReadmeExample()
|
|
||||||
// {
|
|
||||||
// $ups = new UPS\Rate([
|
|
||||||
// 'prod' => FALSE,
|
|
||||||
// 'shipment' => $this->shipment,
|
|
||||||
// 'approved_codes' => [
|
|
||||||
// '03', // 1-5 business days
|
|
||||||
// '02', // 2 business days
|
|
||||||
// '01', // next business day 10:30am
|
|
||||||
// '13', // next business day by 3pm
|
|
||||||
// '14', // next business day by 8am
|
|
||||||
// ],
|
|
||||||
// 'request_adapter' => new RateRequest\StubUPS(),
|
|
||||||
// ]);
|
|
||||||
//
|
|
||||||
// $ups_rates = $ups->get_rates();
|
|
||||||
// var_export($ups_rates);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public function testFedexReadmeExample()
|
|
||||||
// {
|
|
||||||
// $fedex = new Fedex\Rate([
|
|
||||||
// 'prod' => FALSE,
|
|
||||||
// 'key' => 'XXXX',
|
|
||||||
// 'password' => 'XXXX',
|
|
||||||
// 'account_number' => 'XXXX',
|
|
||||||
// 'meter_number' => 'XXXX',
|
|
||||||
// 'drop_off_type' => 'BUSINESS_SERVICE_CENTER',
|
|
||||||
// 'shipment' => array_merge($this->shipment, [
|
|
||||||
// 'packaging_type' => 'YOUR_PACKAGING',
|
|
||||||
// ]),
|
|
||||||
// 'approved_codes' => [
|
|
||||||
// 'FEDEX_EXPRESS_SAVER', // 1-3 business days
|
|
||||||
// 'FEDEX_GROUND', // 1-5 business days
|
|
||||||
// 'GROUND_HOME_DELIVERY', // 1-5 business days
|
|
||||||
// 'FEDEX_2_DAY', // 2 business days
|
|
||||||
// 'STANDARD_OVERNIGHT', // overnight
|
|
||||||
// ],
|
|
||||||
// 'request_adapter' => new RateRequest\StubFedex(),
|
|
||||||
// ]);
|
|
||||||
//
|
|
||||||
// $fedex_rates = $fedex->get_rates();
|
|
||||||
// var_export($fedex_rates);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user