@@ -58,29 +58,46 @@ public function geocodeQuery(GeocodeQuery $query): Collection
58
58
throw new InvalidArgument ('Address cannot be empty. ' );
59
59
}
60
60
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 ' ) ,
73
73
],
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 ' , '' ) ,
79
79
],
80
80
],
81
- 'DeliveringCountryISOCode ' => 'BE ' ,
82
- 'DispatchingCountryISOCode ' => 'BE ' ,
83
81
],
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 ,
84
101
],
85
102
],
86
103
'ValidateAddressOptions ' => [
0 commit comments