diff --git a/Soneritics/PostNL/API.php b/Soneritics/PostNL/API.php index 3333803..b0a7da2 100644 --- a/Soneritics/PostNL/API.php +++ b/Soneritics/PostNL/API.php @@ -26,6 +26,7 @@ use PostNL\Endpoints\Endpoints; use PostNL\Model\Customer; +use PostNL\Service\AddressService; use PostNL\Service\BarcodeService; use PostNL\Service\ConfirmService; use PostNL\Service\LabellingService; @@ -137,4 +138,14 @@ public function getShippingStatusService(): ShippingStatusService { return new ShippingStatusService($this->apiKey, $this->customer, $this->endpoints->ShippingStatus); } + + /** + * Get the address service + * + * @return AddressService + */ + public function getAddressService(): AddressService + { + return new AddressService($this->apiKey, $this->customer, $this->endpoints->Address); + } } diff --git a/Soneritics/PostNL/Endpoints/Endpoints.php b/Soneritics/PostNL/Endpoints/Endpoints.php index 4de3b10..27df056 100644 --- a/Soneritics/PostNL/Endpoints/Endpoints.php +++ b/Soneritics/PostNL/Endpoints/Endpoints.php @@ -73,6 +73,11 @@ abstract class Endpoints */ public $ShippingStatus; + /** + * @var string + */ + public $Address; + /** * Endpoints constructor. * Check if all endpoints are implemented. diff --git a/Soneritics/PostNL/Endpoints/Production.php b/Soneritics/PostNL/Endpoints/Production.php index 368bbba..c716702 100644 --- a/Soneritics/PostNL/Endpoints/Production.php +++ b/Soneritics/PostNL/Endpoints/Production.php @@ -39,4 +39,5 @@ class Production extends Endpoints public $Locations = 'https://api.postnl.nl/shipment/v2_1/locations'; public $PostalCode = 'https://api.postnl.nl/shipment/checkout/v1'; public $ShippingStatus = 'https://api.postnl.nl/shipment/v2/status'; + public $Address = 'https://api.postnl.nl/address'; } diff --git a/Soneritics/PostNL/Endpoints/Sandbox.php b/Soneritics/PostNL/Endpoints/Sandbox.php index a572cfe..0416280 100644 --- a/Soneritics/PostNL/Endpoints/Sandbox.php +++ b/Soneritics/PostNL/Endpoints/Sandbox.php @@ -41,4 +41,5 @@ class Sandbox extends Endpoints public $Locations = 'https://api-sandbox.postnl.nl/shipment/v2_1/locations'; public $PostalCode = 'https://api-sandbox.postnl.nl/shipment/checkout/v1'; public $ShippingStatus = 'https://api-sandbox.postnl.nl/shipment/v2/status'; + public $Address = 'https://api.postnl.nl/address'; // No sandbox available } diff --git a/Soneritics/PostNL/Service/AddressService.php b/Soneritics/PostNL/Service/AddressService.php new file mode 100644 index 0000000..f97daf1 --- /dev/null +++ b/Soneritics/PostNL/Service/AddressService.php @@ -0,0 +1,72 @@ +get( + '/national/v1/validate', + [ + 'PostalCode' => $postalCode, + 'Country' => 'NDL', + 'City' => $city, + 'Street' => $street, + 'HouseNumber' => $houseNumber, + 'Addition' => $addition + ] + ); + } + + /** + * Check the address for international addresses + * + * @throws \Exception + */ + public function checkInternational(string $country, string $postalCode, string $city, string $street, string $houseNumber, string $addition): array + { + return $this->post( + '/international/v1/validate', + [ + 'PostalCode' => $postalCode, + 'Country' => $country, + 'City' => $city, + 'Street' => $street, + 'HouseNumber' => $houseNumber, + 'Addition' => $addition + ] + ); + } +} +