| 1 |
<?php declare(strict_types=1); |
| 2 |
/** |
| 3 |
* This object is embedded in the AbstractConsignment object for global shipments and is |
| 4 |
* |
| 5 |
* If you want to add improvements, please create a fork in our GitHub: |
| 6 |
* https://github.com/myparcelnl |
| 7 |
* |
| 8 |
* @author Reindert Vetter <[email protected]> |
| 9 |
* @copyright 2010-2020 MyParcel |
| 10 |
* @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US CC BY-NC-ND 3.0 NL |
| 11 |
* @link https://github.com/myparcelnl/sdk |
| 12 |
* @since File available since Release v0.1.0 |
| 13 |
*/ |
| 14 |
|
| 15 |
namespace MyParcelNL\Sdk\src\Model; |
| 16 |
|
| 17 |
use MyParcelNL\Sdk\src\Exception\MissingFieldException; |
| 18 |
use MyParcelNL\Sdk\src\Support\Str; |
| 19 |
|
| 20 |
/** |
| 21 |
* This object is embedded in the MyParcelConsignment object for global shipments and is |
| 22 |
* mandatory for non-EU shipments. |
| 23 |
* |
| 24 |
* Class MyParcelCustomsItem |
| 25 |
*/ |
| 26 |
class MyParcelCustomsItem |
| 27 |
{ |
| 28 |
const DESCRIPTION_MAX_LENGTH = 47; |
| 29 |
|
| 30 |
private $description; |
| 31 |
private $amount; |
| 32 |
private $weight; |
| 33 |
private $item_value; |
| 34 |
private $classification; |
| 35 |
private $country; |
| 36 |
|
| 37 |
/** |
| 38 |
* @return mixed |
| 39 |
*/ |
| 40 |
public function getDescription() |
| 41 |
{ |
| 42 |
return $this->description; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* The description of the item |
| 47 |
* |
| 48 |
* Required: Yes |
| 49 |
* |
| 50 |
* @param mixed $description |
| 51 |
* @return $this |
| 52 |
*/ |
| 53 |
public function setDescription($description) |
| 54 |
{ |
| 55 |
/** |
| 56 |
* Description cut after 47 chars |
| 57 |
*/ |
| 58 |
$this->description = Str::limit($description, self::DESCRIPTION_MAX_LENGTH); |
| 59 |
|
| 60 |
return $this; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* @return int|null |
| 65 |
*/ |
| 66 |
public function getAmount() |
| 67 |
{ |
| 68 |
return $this->amount; |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* The amount of this item in the package. The minimum amount is 1. |
| 73 |
* |
| 74 |
* Required: Yes |
| 75 |
* |
| 76 |
* @param int $amount |
| 77 |
* @return $this |
| 78 |
*/ |
| 79 |
public function setAmount($amount) |
| 80 |
{ |
| 81 |
$this->amount = (int) $amount; |
| 82 |
|
| 83 |
return $this; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* @return int|null |
| 88 |
*/ |
| 89 |
public function getWeight() |
| 90 |
{ |
| 91 |
return $this->weight; |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* The total weight for these items in whole grams. Between 0 and 20000 grams. |
| 96 |
* |
| 97 |
* Required: Yes |
| 98 |
* |
| 99 |
* @param int $weight |
| 100 |
* |
| 101 |
* @return $this |
| 102 |
* @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException |
| 103 |
*/ |
| 104 |
public function setWeight($weight) |
| 105 |
{ |
| 106 |
if ($weight == 0) { |
| 107 |
throw new MissingFieldException('Weight must be set for a MyParcel product'); |
| 108 |
} |
| 109 |
|
| 110 |
$this->weight = (int) $weight; |
| 111 |
|
| 112 |
return $this; |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Item value. |
| 117 |
* |
| 118 |
* @return int|null |
| 119 |
*/ |
| 120 |
public function getItemValue() |
| 121 |
{ |
| 122 |
return $this->item_value; |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Item value |
| 127 |
* |
| 128 |
* Composite type containing integer and currency. The amount is without decimal |
| 129 |
* separators (in cents). |
| 130 |
* Required: Yes |
| 131 |
* |
| 132 |
* @param int $item_value |
| 133 |
* |
| 134 |
* @return $this |
| 135 |
*/ |
| 136 |
public function setItemValue($item_value) |
| 137 |
{ |
| 138 |
$this->item_value = (int) $item_value; |
| 139 |
return $this; |
| 140 |
} |
| 141 |
|
| 142 |
/** |
| 143 |
* @return int|null |
| 144 |
*/ |
| 145 |
public function getClassification() |
| 146 |
{ |
| 147 |
return $this->classification; |
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* International Standard Industry Classification |
| 152 |
* |
| 153 |
* Pattern: [0-9]{1,4} |
| 154 |
* Example: 0111 (Growing of cereals (except rice), leguminous crops and oil seeds) |
| 155 |
* Required: Yes |
| 156 |
* |
| 157 |
* @link https://www.cbs.nl/nl-nl/deelnemers-enquetes/deelnemers-enquetes/bedrijven/onderzoek/internationale-handel-in-goederen/idep-codelijsten |
| 158 |
* |
| 159 |
* @param null|int $classification |
| 160 |
* |
| 161 |
* @return $this |
| 162 |
* @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException |
| 163 |
*/ |
| 164 |
public function setClassification(?int $classification): self |
| 165 |
{ |
| 166 |
if (! $classification) { |
| 167 |
throw new MissingFieldException('Classification must be set for a MyParcel product'); |
| 168 |
} |
| 169 |
|
| 170 |
$this->classification = substr("$classification", 0, 5); |
| 171 |
|
| 172 |
return $this; |
| 173 |
} |
| 174 |
|
| 175 |
/** |
| 176 |
* @return string|null |
| 177 |
*/ |
| 178 |
public function getCountry() |
| 179 |
{ |
| 180 |
return $this->country; |
| 181 |
} |
| 182 |
|
| 183 |
/** |
| 184 |
* The country of origin for this item |
| 185 |
* |
| 186 |
* ISO 3166-1 alpha-2 code |
| 187 |
* Pattern: [A-Z]{2,2} |
| 188 |
* Example: NL, BE, CW |
| 189 |
* Required: Yes |
| 190 |
* |
| 191 |
* @link https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements |
| 192 |
* |
| 193 |
* @param string $country |
| 194 |
* @return $this |
| 195 |
*/ |
| 196 |
public function setCountry($country) |
| 197 |
{ |
| 198 |
$this->country = $country; |
| 199 |
|
| 200 |
return $this; |
| 201 |
} |
| 202 |
|
| 203 |
/** |
| 204 |
* Check if object is fully filled |
| 205 |
* |
| 206 |
* @return void |
| 207 |
* @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException |
| 208 |
*/ |
| 209 |
public function ensureFilled() |
| 210 |
{ |
| 211 |
$required = [ |
| 212 |
'Description', |
| 213 |
'Amount', |
| 214 |
'Weight', |
| 215 |
'ItemValue', |
| 216 |
'Classification', |
| 217 |
'Country', |
| 218 |
]; |
| 219 |
foreach ($required as $methodAlias) { |
| 220 |
if ($this->{'get' . $methodAlias}() === null) { |
| 221 |
throw new MissingFieldException("set$methodAlias() must be set"); |
| 222 |
} |
| 223 |
} |
| 224 |
} |
| 225 |
} |
| 226 |
|