- How do I install and set up spatie/bpost-address-webservice in Laravel?
- Run `composer require spatie/bpost-address-webservice` and register the service provider in `config/app.php`. Configure your Bpost API credentials (username/password) in `.env` under `BPOST_USERNAME` and `BPOST_PASSWORD`. The package integrates seamlessly with Laravel’s service container.
- Does this package support Laravel 9 or 10? Will it break in newer versions?
- The package is officially tested for Laravel 7/8 but may work with newer versions if no breaking changes are introduced. Check the [GitHub issues](https://github.com/spatie/bpost-address-webservice/issues) for compatibility reports. Test thoroughly in a staging environment before upgrading.
- How do I validate an address in a Laravel Form Request?
- Use the `AddressValidator` in your Form Request’s `validate()` method. For example, inject the validator via the constructor and call `$validator->validate($request->addressData)`. Return the errors/warnings to the user via `$validator->hasErrors()` or `$validator->errors()`.
- What happens if Bpost’s API is down or rate-limited? Does the package handle retries?
- The package does not include built-in retry logic or fallback mechanisms. You’ll need to implement caching (e.g., `Cache::remember()`) or a retry strategy (e.g., using `spatie/laravel-activitylog`). For high availability, consider a backup validator like Google Maps or manual validation.
- Can I mock the Bpost API for unit testing? How do I test edge cases?
- Use Laravel’s `Http` facade or Mockery to stub the Bpost API responses. For example, mock the `AddressValidator` to return predefined errors/warnings. Test edge cases like invalid postal codes, API timeouts, or malformed responses by simulating these scenarios in your tests.
- Are there any rate limits or quotas I should know about for Bpost’s API?
- Bpost’s API quotas are not documented in the package, but SOAP APIs often have strict limits (e.g., requests per minute). Monitor your API calls and implement caching for frequent addresses. Check Bpost’s official documentation or contact their support for exact limits.
- Does this package work with non-Belgian addresses? Can I use it for international shipping?
- No, this package is specifically for Belgian addresses (Bpost API). For international shipping, consider alternatives like Google Maps API or other country-specific address validation services. The package enforces Belgian postal code and municipality formats.
- How do I handle authentication? Does the package support OAuth or token-based auth?
- The package currently uses static username/password credentials configured in `.env`. If Bpost requires OAuth or token-based auth, you’ll need to extend the `AddressValidator` class or fork the package to support the new authentication method.
- Can I store validated addresses in my database? How does this integrate with Eloquent?
- Yes, you can store validated addresses in your database. The `ValidatedAddress` object can be converted to an array with `$validatedAddress->toArray()`. Extend your Eloquent models (e.g., `Customer`) to use the validator in accessors or observers for automatic validation.
- What are the alternatives to spatie/bpost-address-webservice for Belgian address validation?
- If this package doesn’t meet your needs, consider direct SOAP integration using `php-soap` or libraries like `wsdl2php`. For broader address validation, use Google Maps API or PostcodeAnywhere. However, none of these will enforce Belgian postal regulations as strictly as Bpost’s official API.