@@ -129,15 +129,16 @@ public function setParameter($key, $value)
129129 $ this ->parameters [$ key ] = $ value ;
130130 break ;
131131
132- // maximum 2 chars
132+ // maximum 2 chars
133133 case 'customerCountry ' :
134134 if (mb_strlen ($ value ) > 2 ) {
135135 throw new BpostInvalidLengthException ($ key , mb_strlen ($ value ), 2 );
136136 }
137137 $ this ->parameters [$ key ] = (string ) $ value ;
138138 break ;
139139
140- // maximum 8 chars
140+ // maximum 8 chars
141+ case 'customerPostalCode ' :
141142 case 'customerStreetNumber ' :
142143 case 'customerBox ' :
143144 if (mb_strlen ($ value ) > 8 ) {
@@ -146,35 +147,42 @@ public function setParameter($key, $value)
146147 $ this ->parameters [$ key ] = (string ) $ value ;
147148 break ;
148149
149- // maximum 20 chars
150+ // maximum 20 chars
150151 case 'customerPhoneNumber ' :
151152 if (mb_strlen ($ value ) > 20 ) {
152153 throw new BpostInvalidLengthException ($ key , mb_strlen ($ value ), 20 );
153154 }
154155 $ this ->parameters [$ key ] = (string ) $ value ;
155156 break ;
156157
157- // maximum 32 chars
158- case 'customerPostalCode ' :
159- if (mb_strlen ($ value ) > 32 ) {
160- throw new BpostInvalidLengthException ($ key , mb_strlen ($ value ), 32 );
158+ // maximum 40 chars
159+ case 'customerCompany ' :
160+ case 'customerStreet ' :
161+ case 'customerCity ' :
162+ if (mb_strlen ($ value ) > 40 ) {
163+ throw new BpostInvalidLengthException ($ key , mb_strlen ($ value ), 40 );
161164 }
162165 $ this ->parameters [$ key ] = (string ) $ value ;
163166 break ;
164167
165- // maximum 40 chars
168+ // sum = maximum 40 chars
166169 case 'customerFirstName ' :
167170 case 'customerLastName ' :
168- case 'customerCompany ' :
169- case 'customerStreet ' :
170- case 'customerCity ' :
171- if (mb_strlen ($ value ) > 40 ) {
172- throw new BpostInvalidLengthException ($ key , mb_strlen ($ value ), 40 );
171+ $ names = array (
172+ 'customerFirstName ' => $ this ->parameters ['customerFirstName ' ] ?: '' ,
173+ 'customerLastName ' => $ this ->parameters ['customerLastName ' ] ?: '' ,
174+ );
175+ $ names [$ key ] = $ value ;
176+ $ sum = array_sum (array_map (function ($ item ) {
177+ return mb_strlen ($ item );
178+ }, $ names ));
179+ if ($ sum > 40 ) {
180+ throw new BpostInvalidLengthException ($ key , $ sum , 40 );
173181 }
174182 $ this ->parameters [$ key ] = (string ) $ value ;
175183 break ;
176184
177- // maximum 50 chars
185+ // maximum 50 chars
178186 case 'orderReference ' :
179187 case 'costCenter ' :
180188 case 'customerEmail ' :
@@ -184,21 +192,21 @@ public function setParameter($key, $value)
184192 $ this ->parameters [$ key ] = (string ) $ value ;
185193 break ;
186194
187- // integers
195+ // integers
188196 case 'orderTotalPrice ' :
189197 case 'orderWeight ' :
190198 $ this ->parameters [$ key ] = (int ) $ value ;
191199 break ;
192200
193- // array
201+ // array
194202 case 'orderLine ' :
195203 if (!isset ($ this ->parameters [$ key ])) {
196204 $ this ->parameters [$ key ] = array ();
197205 }
198206 $ this ->parameters [$ key ][] = $ value ;
199207 break ;
200208
201- // unknown
209+ // unknown
202210 case 'deliveryMethodOverrides ' :
203211 case 'extra ' :
204212 case 'extraSecure ' :
0 commit comments