https://github.com/spatie/bpost-address-webservice
An API wrapper for bpost's address webservice
https://github.com/spatie/bpost-address-webservice
belgium geo php validator
Last synced: about 1 year ago
JSON representation
An API wrapper for bpost's address webservice
- Host: GitHub
- URL: https://github.com/spatie/bpost-address-webservice
- Owner: spatie
- License: mit
- Created: 2018-12-27T14:41:31.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-01-11T08:46:07.000Z (over 2 years ago)
- Last Synced: 2025-04-02T03:43:21.165Z (about 1 year ago)
- Topics: belgium, geo, php, validator
- Language: PHP
- Homepage: https://spatie.be/open-source
- Size: 54.7 KB
- Stars: 16
- Watchers: 4
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# An API wrapper for bpost's address webservice
[](https://packagist.org/packages/spatie/bpost-address-webservice)
[](https://travis-ci.org/spatie/bpost-address-webservice)
[](https://scrutinizer-ci.com/g/spatie/bpost-address-webservice)
[](https://github.styleci.io/repos/163304747)
[](https://packagist.org/packages/spatie/bpost-address-webservice)
The Belgian mail service, Bpost, has an API to
Create an `\Spatie\BpostAddressWebservice\Address`, and validate it.
```php
$addressValidator = AddressValidator::create();
$address = Address::create([
'streetName' => 'Samberstraat',
'streetNumber' => '69',
'boxNumber' => 'D',
'postalCode' => '2060',
'municipalityName' => 'Antwaarpe',
'country' => 'BELGIE',
]);
$validatedAddress = $addressValidator->validate($address);
```
The validated address can contain *errors* and *warnings*. If it has any *error* or *warning*, we say that it has *issues*.
```php
$validatedAddress->hasErrors(); // false
$validatedAddress->hasWarnings(); // true
$validatedAddress->hasIssues(); // true
```
An array of errors, warnings, or issues can be retrieved from the validated address.
```php
$validatedAddress->errors(); // []
$validatedAddress->warnings()[0]->attribute(); // 'municipalityName'
$validatedAddress->warnings()[0]->message(); // 'anomaly_in_field'
$validatedAddress->issues()[0]->attribute(); // 'municipalityName'
$validatedAddress->issues()[0]->message(); // 'anomaly_in_field'
```
A validated addresses' attributes can be retrieved.
```php
$validatedAddress->streetName; // 'Samberstraat'
$validatedAddress->streetNumber; // '69'
$validatedAddress->boxNumber; // ''
$validatedAddress->postalCode; // '2060'
$validatedAddress->municipalityName; // 'Antwaarpe'
$validatedAddress->country; // 'BELGIE'
$validatedAddress->toArray();
// [
// 'streetName' => 'SAMBERSTRAAT',
// 'streetNumber' => '69',
// 'boxNumber' => '',
// 'postalCode' => '2060',
// 'municipalityName' => 'ANTWERPEN',
// 'country' => 'BELGIE',
// ]
```
You can also validate up to 100 addresses at a time. An array of `ValidatedAddresses` will be returned.
```php
$addressValidator = AddressValidator::create();
$validatedAddresses = $addressValidator->validateMany([
Address::create([
'streetName' => 'Samberstraat',
'streetNumber' => '69',
'boxNumber' => 'D',
'postalCode' => '2060',
'municipalityName' => 'Antwaarpe',
'country' => 'BELGIE',
]),
// ...
]);
```
Address webservice documentation is available on [bpost.be](https://www.bpost.be/site/en/webservice-address).
## Support us
[
](https://spatie.be/github-ad-click/bpost-address-webservice)
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
## Installation
You can install the package via composer:
```bash
composer require spatie/bpost-address-webservice
```
### Testing
``` bash
composer test
```
### Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.
### Security
If you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker.
## Postcardware
You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.
We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).
## Credits
- [Sebastian De Deyne](https://github.com/sebastiandedeyne)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.