Skip to content

Commit

Permalink
Address check
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisatabix committed Oct 13, 2020
1 parent 49e5819 commit dd8cc69
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Soneritics/PostNL/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
5 changes: 5 additions & 0 deletions Soneritics/PostNL/Endpoints/Endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ abstract class Endpoints
*/
public $ShippingStatus;

/**
* @var string
*/
public $Address;

/**
* Endpoints constructor.
* Check if all endpoints are implemented.
Expand Down
1 change: 1 addition & 0 deletions Soneritics/PostNL/Endpoints/Production.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
1 change: 1 addition & 0 deletions Soneritics/PostNL/Endpoints/Sandbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
72 changes: 72 additions & 0 deletions Soneritics/PostNL/Service/AddressService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/*
* The MIT License
*
* Copyright 2015 Soneritics Webdevelopment.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
namespace PostNL\Service;

/**
* Address Service
*/
class AddressService extends AbstractService
{
/**
* Check the address (Dutch)
*
* @throws \Exception
*/
public function check(string $postalCode, string $city, string $street, string $houseNumber, string $addition): array
{
return $this->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
]
);
}
}

0 comments on commit dd8cc69

Please sign in to comment.