@@ -58,29 +58,46 @@ public function geocodeQuery(GeocodeQuery $query): Collection
5858 throw new InvalidArgument ('Address cannot be empty. ' );
5959 }
6060
61- $ request = [] ;
62- $ request [ ' ValidateAddressesRequest ' ] = [
63- ' AddressToValidateList ' => [
64- ' AddressToValidate ' => [
65- [
66- ' @id ' => 1 ,
67- ' PostalAddress ' => [
68- ' DeliveryPointLocation ' => [
69- ' StructuredDeliveryPointLocation ' => [
70- ' StreetName ' => $ query -> getData ( ' streetName ' ),
71- ' StreetNumber ' => $ query ->getData ('streetNumber ' ),
72- ] ,
61+ $ address = $ query -> getText () ;
62+ $ streetName = $ query -> getData ( ' streetName ' );
63+ $ streetNumber = $ query -> getData ( ' streetNumber ' );
64+
65+ if (! is_null ( $ streetName ) && ! is_null ( $ streetNumber )) {
66+ $ addressToValidate = [
67+ ' @id ' => 1 ,
68+ ' PostalAddress ' => [
69+ ' DeliveryPointLocation ' => [
70+ ' StructuredDeliveryPointLocation ' => [
71+ ' StreetName ' => $ query ->getData ('streetName ' ),
72+ ' StreetNumber ' => $ query -> getData ( ' streetNumber ' ) ,
7373 ],
74- ' PostalCodeMunicipality ' => [
75- ' StructuredPostalCodeMunicipality ' => [
76- ' PostalCode ' => $ query -> getData ( ' postalCode ' , '' ),
77- ' MunicipalityName ' => $ query ->getData ('locality ' , '' ),
78- ] ,
74+ ],
75+ ' PostalCodeMunicipality ' => [
76+ ' StructuredPostalCodeMunicipality ' => [
77+ ' PostalCode ' => $ query ->getData ('postalCode ' , '' ),
78+ ' MunicipalityName ' => $ query -> getData ( ' locality ' , '' ) ,
7979 ],
8080 ],
81- 'DeliveringCountryISOCode ' => 'BE ' ,
82- 'DispatchingCountryISOCode ' => 'BE ' ,
8381 ],
82+ 'DeliveringCountryISOCode ' => 'BE ' ,
83+ 'DispatchingCountryISOCode ' => 'BE ' ,
84+ ];
85+ } else {
86+ $ addressToValidate = [
87+ '@id ' => 1 ,
88+ 'AddressBlockLines ' => [
89+ 'UnstructuredAddressLine ' => $ address
90+ ],
91+ 'DeliveringCountryISOCode ' => 'BE ' ,
92+ 'DispatchingCountryISOCode ' => 'BE ' ,
93+ ];
94+ }
95+
96+ $ request = [];
97+ $ request ['ValidateAddressesRequest ' ] = [
98+ 'AddressToValidateList ' => [
99+ 'AddressToValidate ' => [
100+ $ addressToValidate ,
84101 ],
85102 ],
86103 'ValidateAddressOptions ' => [
0 commit comments