Skip to content

Commit 9db5b30

Browse files
authored
Add shipping label functionality
1 parent ddec199 commit 9db5b30

24 files changed

+1630
-0
lines changed

src/Entity/Address.php

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
namespace RahulGodiyal\PhpUpsApiWrapper\Entity;
4+
5+
class Address
6+
{
7+
private ?string $addressLine1;
8+
private ?string $addressLine2;
9+
private ?string $city;
10+
private ?string $stateProvinceCode;
11+
private ?string $postalCode;
12+
private ?string $countryCode;
13+
14+
public function setAddressLine1(string $addressLine1): self
15+
{
16+
$this->addressLine1 = $addressLine1;
17+
return $this;
18+
}
19+
20+
public function getAddressLine1(): string | null
21+
{
22+
return $this->addressLine1;
23+
}
24+
25+
public function setAddressLine2(string $addressLine2): self
26+
{
27+
$this->addressLine2 = $addressLine2;
28+
return $this;
29+
}
30+
31+
public function getAddressLine2(): string | null
32+
{
33+
return $this->addressLine2;
34+
}
35+
36+
public function setCity(string $city): self
37+
{
38+
$this->city = $city;
39+
return $this;
40+
}
41+
42+
public function getCity(): string | null
43+
{
44+
return $this->city;
45+
}
46+
47+
public function setStateProvinceCode(string $state): self
48+
{
49+
$this->stateProvinceCode = $state;
50+
return $this;
51+
}
52+
53+
public function getStateProvinceCode(): string | null
54+
{
55+
return $this->stateProvinceCode;
56+
}
57+
58+
public function setPostalCode(string $postal_code): self
59+
{
60+
$this->postalCode = $postal_code;
61+
return $this;
62+
}
63+
64+
public function getPostalCode(): string | null
65+
{
66+
return $this->postalCode;
67+
}
68+
69+
public function setCountryCode(string $country_code): self
70+
{
71+
$this->countryCode = $country_code;
72+
return $this;
73+
}
74+
75+
public function getCountryCode(): string | null
76+
{
77+
return $this->countryCode;
78+
}
79+
80+
public function toArray(): array
81+
{
82+
$address_lines = [$this->addressLine1];
83+
84+
if ($this->addressLine2) {
85+
array_push($address_lines, $this->addressLine2);
86+
}
87+
88+
return [
89+
"AddressLine" => $address_lines,
90+
"City" => $this->city,
91+
"StateProvinceCode" => $this->stateProvinceCode,
92+
"PostalCode" => $this->postalCode,
93+
"CountryCode" => $this->countryCode
94+
];
95+
}
96+
}

src/Entity/BillShipper.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace RahulGodiyal\PhpUpsApiWrapper\Entity;
4+
5+
class BillShipper
6+
{
7+
private string $accountNumber = "";
8+
9+
public function exists()
10+
{
11+
if (!empty($this->accountNumber)) {
12+
return true;
13+
}
14+
15+
return false;
16+
}
17+
18+
public function setAccountNumber(string $accountNumber): self
19+
{
20+
$this->accountNumber = $accountNumber;
21+
return $this;
22+
}
23+
24+
public function getAccountNumber(): string
25+
{
26+
return $this->accountNumber;
27+
}
28+
29+
public function toArray(): array
30+
{
31+
return [
32+
"AccountNumber" => $this->accountNumber
33+
];
34+
}
35+
}

src/Entity/Dimensions.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
namespace RahulGodiyal\PhpUpsApiWrapper\Entity;
4+
5+
class Dimensions
6+
{
7+
private UnitOfMeasurement $unitOfMeasurement;
8+
private ?string $length;
9+
private ?string $width;
10+
private ?string $height;
11+
12+
public function setUnitOfMeasurement(UnitOfMeasurement $unitOfMeasurement): self
13+
{
14+
$this->unitOfMeasurement = $unitOfMeasurement;
15+
return $this;
16+
}
17+
18+
public function getUnitOfMeasurement(): UnitOfMeasurement
19+
{
20+
return $this->unitOfMeasurement;
21+
}
22+
23+
public function setLength(string $length): self
24+
{
25+
if ($this->unitOfMeasurement->getCode() == 'IN') {
26+
if ($length >= 0 && $length <= 108) {
27+
$this->length = $length;
28+
return $this;
29+
}
30+
}
31+
32+
if ($this->unitOfMeasurement->getCode() == 'CM') {
33+
if ($length >= 0 && $length <= 270) {
34+
$this->length = $length;
35+
return $this;
36+
}
37+
}
38+
39+
throw new \Exception("Length value is not valid.");
40+
}
41+
42+
public function getLength(): string
43+
{
44+
return $this->length;
45+
}
46+
47+
public function setWidth(string $width): self
48+
{
49+
$this->width = $width;
50+
return $this;
51+
}
52+
53+
public function getWidth(): string
54+
{
55+
return $this->width;
56+
}
57+
58+
public function setHeight(string $height): self
59+
{
60+
$this->height = $height;
61+
return $this;
62+
}
63+
64+
public function getHeight(): string
65+
{
66+
return $this->height;
67+
}
68+
69+
public function toArray(): array
70+
{
71+
return [
72+
"UnitOfMeasurement" => $this->unitOfMeasurement->toArray(),
73+
"Length" => $this->length,
74+
"Width" => $this->width,
75+
"Height" => $this->height
76+
];
77+
}
78+
}

src/Entity/LabelImageFormat.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace RahulGodiyal\PhpUpsApiWrapper\Entity;
4+
5+
class LabelImageFormat
6+
{
7+
public const GIF = "GIF";
8+
public const ZPL = "ZPL";
9+
public const EPL = "EPL";
10+
public const SPL = "SPL";
11+
12+
private ?string $code;
13+
private ?string $description;
14+
15+
public function setCode(string $code): self
16+
{
17+
if (in_array($code, [self::GIF, self::ZPL, self::EPL, self::SPL])) {
18+
$this->code = $code;
19+
return $this;
20+
}
21+
22+
throw new \Exception("LabelImageFormat code doesn't exists.");
23+
}
24+
25+
public function getCode(): string
26+
{
27+
return $this->code;
28+
}
29+
30+
public function setDescription(string $description): self
31+
{
32+
$this->description = $description;
33+
return $this;
34+
}
35+
36+
public function getDescription(): string
37+
{
38+
return $this->description;
39+
}
40+
41+
public function toArray(): array
42+
{
43+
$labelImageFormat = [
44+
"Code" => $this->code
45+
];
46+
47+
if ($this->description) {
48+
$labelImageFormat["Description"] = $this->description;
49+
}
50+
51+
return $labelImageFormat;
52+
}
53+
}

src/Entity/LabelSpecification.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace RahulGodiyal\PhpUpsApiWrapper\Entity;
4+
5+
class LabelSpecification
6+
{
7+
private LabelImageFormat $labelImageFormat;
8+
private LabelStockSize $labelStockSize;
9+
private ?string $httpUserAgent;
10+
11+
public function setLabelImageFormat(LabelImageFormat $labelImageFormat): self
12+
{
13+
$this->labelImageFormat = $labelImageFormat;
14+
return $this;
15+
}
16+
17+
public function getLabelImageFormat(): LabelImageFormat
18+
{
19+
return $this->labelImageFormat;
20+
}
21+
22+
public function setLabelStockSize(LabelStockSize $labelStockSize): self
23+
{
24+
$this->labelStockSize = $labelStockSize;
25+
return $this;
26+
}
27+
28+
public function getLabelStockSize(): LabelStockSize
29+
{
30+
return $this->labelStockSize;
31+
}
32+
33+
public function setHttpUserAgent(string $httpUserAgent): self
34+
{
35+
$this->httpUserAgent = $httpUserAgent;
36+
return $this;
37+
}
38+
39+
public function getHttpUserAgent(): string
40+
{
41+
return $this->httpUserAgent;
42+
}
43+
44+
public function toArray(): array
45+
{
46+
$labelSpecification = [
47+
"LabelImageFormat" => $this->labelImageFormat->toArray(),
48+
"LabelStockSize" => $this->labelStockSize->toArray()
49+
];
50+
51+
if ($this->httpUserAgent) {
52+
$labelSpecification["HTTPUserAgent"] = $this->httpUserAgent;
53+
}
54+
55+
return $labelSpecification;
56+
}
57+
}

src/Entity/LabelStockSize.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace RahulGodiyal\PhpUpsApiWrapper\Entity;
4+
5+
class LabelStockSize
6+
{
7+
public const H_6 = "6";
8+
public const H_8 = "8";
9+
public const W_4 = "4";
10+
11+
private ?string $height;
12+
private ?string $width;
13+
14+
public function setHeight(string $height): self
15+
{
16+
if (in_array($height, [self::H_6, self::H_8])) {
17+
$this->height = $height;
18+
return $this;
19+
}
20+
21+
throw new \Exception("LabelStockSize height can be only 6 or 8");
22+
}
23+
24+
public function getHeight(): string
25+
{
26+
return $this->height;
27+
}
28+
29+
public function setWidth(string $width): self
30+
{
31+
if ($width == self::W_4) {
32+
$this->width = $width;
33+
return $this;
34+
}
35+
36+
throw new \Exception("LabelStockSize width can be only 4");
37+
}
38+
39+
public function getWidth(): string
40+
{
41+
return $this->width;
42+
}
43+
44+
public function toArray(): array
45+
{
46+
return [
47+
"Height" => $this->height,
48+
"Width" => $this->width
49+
];
50+
}
51+
}

0 commit comments

Comments
 (0)