Skip to content

Commit cb633b8

Browse files
authored
Implement Ratetimeintransit and Shoptimeintransit requests
RateTimeInTransit (replaces PR #145)
2 parents 17c5f77 + 409b858 commit cb633b8

15 files changed

+980
-51
lines changed

README.md

Lines changed: 85 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,23 @@ Tracking API, Shipping API, Rating API and Time in Transit API. Feel free to con
3333
7. [Rate Class](#rate-class)
3434
* [Example](#rate-class-example)
3535
* [Parameters](#rate-class-parameters)
36-
8. [TimeInTransit Class](#timeintransit-class)
36+
8. [RateTimeInTransit Class](#ratetimeintransit-class)
37+
* [Example](#ratetimeintransit-class-example)
38+
* [Parameters](#ratetimeintransit-class-parameters)
39+
9. [TimeInTransit Class](#timeintransit-class)
3740
* [Example](#timeintransit-class-example)
3841
* [Parameters](#timeintransit-class-parameters)
39-
9. [Locator Class](#locator-class)
42+
10. [Locator Class](#locator-class)
4043
* [Example](#locator-class-example)
4144
* [Parameters](#locator-class-parameters)
42-
10. [Tradeability Class](#tradeability-class)
45+
11. [Tradeability Class](#tradeability-class)
4346
* [Example](#tradeability-class-example)
4447
* [Parameters](#tradeability-class-parameters)
45-
11. [Shipping Class](#shipping-class)
48+
12. [Shipping Class](#shipping-class)
4649
* [Example](#shipping-class-example)
4750
* [Parameters](#shipping-class-parameters)
48-
12. [Logging](#logging)
49-
13. [License](#license-section)
51+
13. [Logging](#logging)
52+
14. [License](#license-section)
5053

5154
<a name="requirements"></a>
5255
## Requirements
@@ -365,6 +368,82 @@ try {
365368

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

371+
<a name="ratetimeinstransit-class"></a>
372+
## RateTimeInTransit Class
373+
374+
The RateTimeInTransit Class allow you to get shipment rates like the Rate Class, but the response will also include
375+
TimeInTransit data.
376+
377+
<a name="ratetimeintransit-class-example"></a>
378+
### Example
379+
380+
```php
381+
$rate = new Ups\RateTimeInTransit(
382+
$accessKey,
383+
$userId,
384+
$password
385+
);
386+
387+
try {
388+
$shipment = new \Ups\Entity\Shipment();
389+
390+
$shipperAddress = $shipment->getShipper()->getAddress();
391+
$shipperAddress->setPostalCode('99205');
392+
393+
$address = new \Ups\Entity\Address();
394+
$address->setPostalCode('99205');
395+
$shipFrom = new \Ups\Entity\ShipFrom();
396+
$shipFrom->setAddress($address);
397+
398+
$shipment->setShipFrom($shipFrom);
399+
400+
$shipTo = $shipment->getShipTo();
401+
$shipTo->setCompanyName('Test Ship To');
402+
$shipToAddress = $shipTo->getAddress();
403+
$shipToAddress->setPostalCode('99205');
404+
405+
$package = new \Ups\Entity\Package();
406+
$package->getPackagingType()->setCode(\Ups\Entity\PackagingType::PT_PACKAGE);
407+
$package->getPackageWeight()->setWeight(10);
408+
409+
// if you need this (depends of the shipper country)
410+
$weightUnit = new \Ups\Entity\UnitOfMeasurement;
411+
$weightUnit->setCode(\Ups\Entity\UnitOfMeasurement::UOM_KGS);
412+
$package->getPackageWeight()->setUnitOfMeasurement($weightUnit);
413+
414+
$dimensions = new \Ups\Entity\Dimensions();
415+
$dimensions->setHeight(10);
416+
$dimensions->setWidth(10);
417+
$dimensions->setLength(10);
418+
419+
$unit = new \Ups\Entity\UnitOfMeasurement;
420+
$unit->setCode(\Ups\Entity\UnitOfMeasurement::UOM_IN);
421+
422+
$dimensions->setUnitOfMeasurement($unit);
423+
$package->setDimensions($dimensions);
424+
425+
$shipment->addPackage($package);
426+
427+
$deliveryTimeInformation = new \Ups\Entity\DeliveryTimeInformation();
428+
$deliveryTimeInformation->setPackageBillType(\Ups\Entity\DeliveryTimeInformation::PBT_NON_DOCUMENT);
429+
430+
$pickup = new \Ups\Entity\Pickup();
431+
$pickup->setDate("20170520");
432+
$pickup->setTime("160000");
433+
$shipment->setDeliveryTimeInformation($deliveryTimeInformation);
434+
435+
var_dump($rate->shopRatesTimeInTransit($shipment));
436+
} catch (Exception $e) {
437+
var_dump($e);
438+
}
439+
```
440+
<a name="ratetimeintransit-class-parameters"></a>
441+
### Parameters
442+
443+
* `rateRequest` Mandatory. rateRequest Object with shipment details
444+
445+
This RateTimeInTransit extends the Rate class which is not finished yet! Parameter should be added when it will be finished.
446+
368447
<a name="timeintransit-class"></a>
369448
## TimeInTransit Class
370449

src/Entity/Arrival.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
namespace Ups\Entity;
4+
5+
use DOMDocument;
6+
use DOMElement;
7+
use Ups\NodeInterface;
8+
9+
/**
10+
* @author mazzarito
11+
*/
12+
class Arrival
13+
{
14+
/**
15+
* @var string
16+
*/
17+
private $date;
18+
19+
/**
20+
* @var string
21+
*/
22+
private $time;
23+
24+
/**
25+
* @param \stdClass|null $response
26+
*/
27+
public function __construct(\stdClass $response = null)
28+
{
29+
if (null !== $response) {
30+
if (isset($response->Date)) {
31+
$this->date = $response->Date;
32+
}
33+
if (isset($response->Time)) {
34+
$this->time = $response->Time;
35+
}
36+
}
37+
}
38+
39+
/**
40+
* @return string
41+
*/
42+
public function getDate()
43+
{
44+
return $this->date;
45+
}
46+
47+
/**
48+
* @param string $date
49+
*/
50+
public function setDate($date)
51+
{
52+
$this->date = $date;
53+
}
54+
55+
/**
56+
* @return string
57+
*/
58+
public function getTime()
59+
{
60+
return $this->time;
61+
}
62+
63+
/**
64+
* @param string $time
65+
*/
66+
public function setTime($time)
67+
{
68+
$this->time = $time;
69+
}
70+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
namespace Ups\Entity;
4+
5+
use DOMDocument;
6+
use DOMElement;
7+
use Ups\NodeInterface;
8+
9+
/**
10+
* @author mazzarito
11+
*/
12+
class DeliveryTimeInformation implements NodeInterface
13+
{
14+
const PBT_DOCUMENT_ONLY = '02';
15+
const PBT_NON_DOCUMENT = '03';
16+
const PBT_PALLET = '04';
17+
18+
/*
19+
* @var string
20+
*/
21+
private $packageBillType;
22+
23+
/*
24+
* @var Pickup
25+
*/
26+
private $pickup;
27+
28+
/**
29+
* @param null|DOMDocument $document
30+
*
31+
* @return DOMElement
32+
*/
33+
public function toNode(DOMDocument $document = null)
34+
{
35+
if (null === $document) {
36+
$document = new DOMDocument();
37+
}
38+
39+
$node = $document->createElement('DeliveryTimeInformation');
40+
$node->appendChild($document->createElement('PackageBillType', $this->getPackageBillType()));
41+
42+
if ($this->getPickup() !== null) {
43+
$node->appendChild($this->getPickup()->toNode($document));
44+
}
45+
46+
return $node;
47+
}
48+
49+
/**
50+
* @return string
51+
*/
52+
public function getPackageBillType()
53+
{
54+
return $this->packageBillType;
55+
}
56+
57+
/**
58+
* @param string $packageBillType
59+
*/
60+
public function setPackageBillType($packageBillType)
61+
{
62+
$this->packageBillType = $packageBillType;
63+
}
64+
65+
/**
66+
* @return Pickup
67+
*/
68+
public function getPickup()
69+
{
70+
return $this->pickup;
71+
}
72+
73+
/**
74+
* @param Pickup $pickup
75+
*/
76+
public function setPickup($pickup)
77+
{
78+
$this->pickup = $pickup;
79+
}
80+
}

0 commit comments

Comments
 (0)