Skip to content

Commit

Permalink
Implement Ratetimeintransit and Shoptimeintransit requests
Browse files Browse the repository at this point in the history
RateTimeInTransit (replaces PR #145)
  • Loading branch information
stefandoorn authored Nov 11, 2017
2 parents 17c5f77 + 409b858 commit cb633b8
Show file tree
Hide file tree
Showing 15 changed files with 980 additions and 51 deletions.
91 changes: 85 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,23 @@ Tracking API, Shipping API, Rating API and Time in Transit API. Feel free to con
7. [Rate Class](#rate-class)
* [Example](#rate-class-example)
* [Parameters](#rate-class-parameters)
8. [TimeInTransit Class](#timeintransit-class)
8. [RateTimeInTransit Class](#ratetimeintransit-class)
* [Example](#ratetimeintransit-class-example)
* [Parameters](#ratetimeintransit-class-parameters)
9. [TimeInTransit Class](#timeintransit-class)
* [Example](#timeintransit-class-example)
* [Parameters](#timeintransit-class-parameters)
9. [Locator Class](#locator-class)
10. [Locator Class](#locator-class)
* [Example](#locator-class-example)
* [Parameters](#locator-class-parameters)
10. [Tradeability Class](#tradeability-class)
11. [Tradeability Class](#tradeability-class)
* [Example](#tradeability-class-example)
* [Parameters](#tradeability-class-parameters)
11. [Shipping Class](#shipping-class)
12. [Shipping Class](#shipping-class)
* [Example](#shipping-class-example)
* [Parameters](#shipping-class-parameters)
12. [Logging](#logging)
13. [License](#license-section)
13. [Logging](#logging)
14. [License](#license-section)

<a name="requirements"></a>
## Requirements
Expand Down Expand Up @@ -365,6 +368,82 @@ try {

This Rate class is not finished yet! Parameter should be added when it will be finished.

<a name="ratetimeinstransit-class"></a>
## RateTimeInTransit Class

The RateTimeInTransit Class allow you to get shipment rates like the Rate Class, but the response will also include
TimeInTransit data.

<a name="ratetimeintransit-class-example"></a>
### Example

```php
$rate = new Ups\RateTimeInTransit(
$accessKey,
$userId,
$password
);

try {
$shipment = new \Ups\Entity\Shipment();

$shipperAddress = $shipment->getShipper()->getAddress();
$shipperAddress->setPostalCode('99205');

$address = new \Ups\Entity\Address();
$address->setPostalCode('99205');
$shipFrom = new \Ups\Entity\ShipFrom();
$shipFrom->setAddress($address);

$shipment->setShipFrom($shipFrom);

$shipTo = $shipment->getShipTo();
$shipTo->setCompanyName('Test Ship To');
$shipToAddress = $shipTo->getAddress();
$shipToAddress->setPostalCode('99205');

$package = new \Ups\Entity\Package();
$package->getPackagingType()->setCode(\Ups\Entity\PackagingType::PT_PACKAGE);
$package->getPackageWeight()->setWeight(10);

// if you need this (depends of the shipper country)
$weightUnit = new \Ups\Entity\UnitOfMeasurement;
$weightUnit->setCode(\Ups\Entity\UnitOfMeasurement::UOM_KGS);
$package->getPackageWeight()->setUnitOfMeasurement($weightUnit);

$dimensions = new \Ups\Entity\Dimensions();
$dimensions->setHeight(10);
$dimensions->setWidth(10);
$dimensions->setLength(10);

$unit = new \Ups\Entity\UnitOfMeasurement;
$unit->setCode(\Ups\Entity\UnitOfMeasurement::UOM_IN);

$dimensions->setUnitOfMeasurement($unit);
$package->setDimensions($dimensions);

$shipment->addPackage($package);

$deliveryTimeInformation = new \Ups\Entity\DeliveryTimeInformation();
$deliveryTimeInformation->setPackageBillType(\Ups\Entity\DeliveryTimeInformation::PBT_NON_DOCUMENT);

$pickup = new \Ups\Entity\Pickup();
$pickup->setDate("20170520");
$pickup->setTime("160000");
$shipment->setDeliveryTimeInformation($deliveryTimeInformation);

var_dump($rate->shopRatesTimeInTransit($shipment));
} catch (Exception $e) {
var_dump($e);
}
```
<a name="ratetimeintransit-class-parameters"></a>
### Parameters

* `rateRequest` Mandatory. rateRequest Object with shipment details

This RateTimeInTransit extends the Rate class which is not finished yet! Parameter should be added when it will be finished.

<a name="timeintransit-class"></a>
## TimeInTransit Class

Expand Down
70 changes: 70 additions & 0 deletions src/Entity/Arrival.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace Ups\Entity;

use DOMDocument;
use DOMElement;
use Ups\NodeInterface;

/**
* @author mazzarito
*/
class Arrival
{
/**
* @var string
*/
private $date;

/**
* @var string
*/
private $time;

/**
* @param \stdClass|null $response
*/
public function __construct(\stdClass $response = null)
{
if (null !== $response) {
if (isset($response->Date)) {
$this->date = $response->Date;
}
if (isset($response->Time)) {
$this->time = $response->Time;
}
}
}

/**
* @return string
*/
public function getDate()
{
return $this->date;
}

/**
* @param string $date
*/
public function setDate($date)
{
$this->date = $date;
}

/**
* @return string
*/
public function getTime()
{
return $this->time;
}

/**
* @param string $time
*/
public function setTime($time)
{
$this->time = $time;
}
}
80 changes: 80 additions & 0 deletions src/Entity/DeliveryTimeInformation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace Ups\Entity;

use DOMDocument;
use DOMElement;
use Ups\NodeInterface;

/**
* @author mazzarito
*/
class DeliveryTimeInformation implements NodeInterface
{
const PBT_DOCUMENT_ONLY = '02';
const PBT_NON_DOCUMENT = '03';
const PBT_PALLET = '04';

/*
* @var string
*/
private $packageBillType;

/*
* @var Pickup
*/
private $pickup;

/**
* @param null|DOMDocument $document
*
* @return DOMElement
*/
public function toNode(DOMDocument $document = null)
{
if (null === $document) {
$document = new DOMDocument();
}

$node = $document->createElement('DeliveryTimeInformation');
$node->appendChild($document->createElement('PackageBillType', $this->getPackageBillType()));

if ($this->getPickup() !== null) {
$node->appendChild($this->getPickup()->toNode($document));
}

return $node;
}

/**
* @return string
*/
public function getPackageBillType()
{
return $this->packageBillType;
}

/**
* @param string $packageBillType
*/
public function setPackageBillType($packageBillType)
{
$this->packageBillType = $packageBillType;
}

/**
* @return Pickup
*/
public function getPickup()
{
return $this->pickup;
}

/**
* @param Pickup $pickup
*/
public function setPickup($pickup)
{
$this->pickup = $pickup;
}
}
Loading

0 comments on commit cb633b8

Please sign in to comment.