|
|
@ -1,4 +1,5 @@
|
|
|
|
<?php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace pdt256\Shipping\USPS;
|
|
|
|
namespace pdt256\Shipping\USPS;
|
|
|
|
|
|
|
|
|
|
|
|
use pdt256\Shipping;
|
|
|
|
use pdt256\Shipping;
|
|
|
@ -10,18 +11,17 @@ use pdt256\Shipping\Validator;
|
|
|
|
use DOMDocument;
|
|
|
|
use DOMDocument;
|
|
|
|
use Exception;
|
|
|
|
use Exception;
|
|
|
|
|
|
|
|
|
|
|
|
class Rate extends RateAdapter
|
|
|
|
class Rate extends RateAdapter {
|
|
|
|
{
|
|
|
|
|
|
|
|
private $urlDev = 'http://production.shippingapis.com/ShippingAPI.dll';
|
|
|
|
private $urlDev = 'http://production.shippingapis.com/ShippingAPI.dll';
|
|
|
|
private $urlProd = 'http://production.shippingapis.com/ShippingAPI.dll';
|
|
|
|
private $urlProd = 'http://production.shippingapis.com/ShippingAPI.dll';
|
|
|
|
|
|
|
|
|
|
|
|
private $username;
|
|
|
|
private $username;
|
|
|
|
private $password;
|
|
|
|
private $password;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Codes of appropriate shipping types. Default value is specified in __construct.
|
|
|
|
* Codes of appropriate shipping types. Default value is specified in __construct.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public $approvedCodes;
|
|
|
|
public $approvedCodes;
|
|
|
|
|
|
|
|
|
|
|
|
private $shipping_codes = [
|
|
|
|
private $shipping_codes = [
|
|
|
|
'domestic' => [
|
|
|
|
'domestic' => [
|
|
|
|
'00' => 'First-Class Mail Parcel',
|
|
|
|
'00' => 'First-Class Mail Parcel',
|
|
|
@ -67,20 +67,19 @@ class Rate extends RateAdapter
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct($options = [])
|
|
|
|
public function __construct($options = []) {
|
|
|
|
{
|
|
|
|
|
|
|
|
parent::__construct($options);
|
|
|
|
parent::__construct($options);
|
|
|
|
|
|
|
|
|
|
|
|
$this->username = Arr::get($options, 'username');
|
|
|
|
$this->username = Arr::get($options, 'username');
|
|
|
|
$this->password = Arr::get($options, 'password');
|
|
|
|
$this->password = Arr::get($options, 'password');
|
|
|
|
$this->approvedCodes = Arr::get($options, 'approvedCodes', [
|
|
|
|
$this->approvedCodes = Arr::get($options, 'approvedCodes', [
|
|
|
|
'1',
|
|
|
|
'1',
|
|
|
|
'4',
|
|
|
|
'4',
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
$this->setRequestAdapter(Arr::get($options, 'requestAdapter', new RateRequest\Get()));
|
|
|
|
$this->setRequestAdapter(Arr::get($options, 'requestAdapter', new RateRequest\Get()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
protected function validate()
|
|
|
|
|
|
|
|
{
|
|
|
|
protected function validate() {
|
|
|
|
$this->validatePackages();
|
|
|
|
$this->validatePackages();
|
|
|
|
Validator::checkIfNull($this->username, 'username');
|
|
|
|
Validator::checkIfNull($this->username, 'username');
|
|
|
|
Validator::checkIfNull($this->password, 'password');
|
|
|
|
Validator::checkIfNull($this->password, 'password');
|
|
|
@ -89,8 +88,8 @@ class Rate extends RateAdapter
|
|
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
protected function prepare()
|
|
|
|
|
|
|
|
{
|
|
|
|
protected function prepare() {
|
|
|
|
$packages = '';
|
|
|
|
$packages = '';
|
|
|
|
$sequence_number = 0;
|
|
|
|
$sequence_number = 0;
|
|
|
|
foreach ($this->shipment->getPackages() as $p) {
|
|
|
|
foreach ($this->shipment->getPackages() as $p) {
|
|
|
@ -119,33 +118,30 @@ class Rate extends RateAdapter
|
|
|
|
$container = 'VARIABLE';
|
|
|
|
$container = 'VARIABLE';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$packages .=
|
|
|
|
$packages .= '<Package ID="' . $sequence_number . '">' .
|
|
|
|
'<Package ID="' . $sequence_number . '">' .
|
|
|
|
|
|
|
|
'<Service>ALL</Service>' .
|
|
|
|
'<Service>ALL</Service>' .
|
|
|
|
'<ZipOrigination>' . $this->shipment->getFromPostalCode() . '</ZipOrigination>' .
|
|
|
|
'<ZipOrigination>' . $this->shipment->getFromPostalCode() . '</ZipOrigination>' .
|
|
|
|
'<ZipDestination>' . $this->shipment->getToPostalCode() . '</ZipDestination>' .
|
|
|
|
'<ZipDestination>' . $this->shipment->getToPostalCode() . '</ZipDestination>' .
|
|
|
|
'<Pounds>' . $p->getWeight() . '</Pounds>' .
|
|
|
|
'<Pounds>' . $p->getPounds() . '</Pounds>' .
|
|
|
|
'<Ounces>0</Ounces>' .
|
|
|
|
'<Ounces>' . $p->getOunces() . '</Ounces>' .
|
|
|
|
'<Container>' . $container . '</Container>' .
|
|
|
|
'<Container>' . $container . '</Container>' .
|
|
|
|
'<Size>' . $size . '</Size>' .
|
|
|
|
'<Size>' . $size . '</Size>' .
|
|
|
|
'<Width>' . $p->getWidth() . '</Width>' .
|
|
|
|
'<Width>' . $p->getWidth() . '</Width>' .
|
|
|
|
'<Length>' . $p->getLength() . '</Length>' .
|
|
|
|
'<Length>' . $p->getLength() . '</Length>' .
|
|
|
|
'<Height>' . $p->getHeight() . '</Height>' .
|
|
|
|
'<Height>' . $p->getHeight() . '</Height>' .
|
|
|
|
'<Machinable>' . 'False' . '</Machinable>' .
|
|
|
|
'<Machinable>' . 'False' . '</Machinable>' .
|
|
|
|
'</Package>';
|
|
|
|
'</Package>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->data =
|
|
|
|
$this->data = '<RateV4Request USERID="' . $this->username . '">' .
|
|
|
|
'<RateV4Request USERID="' . $this->username . '">' .
|
|
|
|
|
|
|
|
'<Revision/>' .
|
|
|
|
'<Revision/>' .
|
|
|
|
$packages .
|
|
|
|
$packages .
|
|
|
|
'</RateV4Request>';
|
|
|
|
'</RateV4Request>';
|
|
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function execute()
|
|
|
|
protected function execute() {
|
|
|
|
{
|
|
|
|
|
|
|
|
if ($this->isProduction) {
|
|
|
|
if ($this->isProduction) {
|
|
|
|
$url = $this->urlProd;
|
|
|
|
$url = $this->urlProd;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -159,8 +155,7 @@ class Rate extends RateAdapter
|
|
|
|
return $this;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function process()
|
|
|
|
protected function process() {
|
|
|
|
{
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
$dom = new DOMDocument('1.0', 'UTF-8');
|
|
|
|
$dom = new DOMDocument('1.0', 'UTF-8');
|
|
|
|
$dom->loadXml($this->response);
|
|
|
|
$dom->loadXml($this->response);
|
|
|
@ -195,10 +190,10 @@ class Rate extends RateAdapter
|
|
|
|
|
|
|
|
|
|
|
|
$quote = new Quote;
|
|
|
|
$quote = new Quote;
|
|
|
|
$quote
|
|
|
|
$quote
|
|
|
|
->setCarrier('usps')
|
|
|
|
->setCarrier('usps')
|
|
|
|
->setCode($code)
|
|
|
|
->setCode($code)
|
|
|
|
->setName($name)
|
|
|
|
->setName($name)
|
|
|
|
->setCost((int) $cost);
|
|
|
|
->setCost((int) $cost);
|
|
|
|
|
|
|
|
|
|
|
|
$rates[$quote->getCode()] = $quote;
|
|
|
|
$rates[$quote->getCode()] = $quote;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -207,4 +202,5 @@ class Rate extends RateAdapter
|
|
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|