@@ -78,8 +78,7 @@ public function setNumber($number)
7878
7979 $ this ->number = substr ($ numberWithoutLineBreaks , 0 , 15 );
8080
81- if (empty ($ this ->number ) && ($ this ->number === null || !is_numeric (trim ($ this ->number )))) {
82-
81+ if (empty (trim ($ this ->number ))) {
8382 $ inputName = $ this ->i18n ->getDashboard ('number ' );
8483 $ message = $ this ->i18n ->getDashboard (
8584 "The %s should not be empty! " ,
@@ -107,14 +106,8 @@ public function getStreet()
107106 */
108107 public function setStreet ($ street )
109108 {
110- $ streetWithoutComma = str_replace (
111- self ::ADDRESS_LINE_SEPARATOR ,
112- '' ,
113- $ street ?? ''
114- );
115-
116109 $ streetWithoutLineBreaks = StringFunctionsHelper::removeLineBreaks (
117- $ streetWithoutComma
110+ $ street
118111 );
119112
120113 $ this ->street = substr ($ streetWithoutLineBreaks , 0 , 64 );
@@ -137,7 +130,7 @@ public function setStreet($street)
137130 */
138131 public function getNeighborhood ()
139132 {
140- return $ this ->neighborhood ;
133+ return $ this ->neighborhood ?? '' ;
141134 }
142135
143136 /**
@@ -159,17 +152,6 @@ public function setNeighborhood($neighborhood)
159152
160153 $ this ->neighborhood = substr ($ neighborhoodWithoutLineBreaks , 0 , 64 );
161154
162- if (empty ($ this ->neighborhood )) {
163-
164- $ inputName = $ this ->i18n ->getDashboard ('neighborhood ' );
165- $ message = $ this ->i18n ->getDashboard (
166- "The %s should not be empty! " ,
167- $ inputName
168- );
169-
170- throw new \Exception ($ message , 400 );
171- }
172-
173155 return $ this ;
174156 }
175157
@@ -289,12 +271,17 @@ public function setCountry($country)
289271
290272 public function getLine1 ()
291273 {
292- $ line = [];
293- $ line [] = $ this ->getNumber ();
274+ if ($ this ->getNumber ()) {
275+ $ line [] = $ this ->getNumber ();
276+ }
277+
294278 $ line [] = $ this ->getStreet ();
295- $ line [] = $ this ->getNeighborhood ();
296279
297- return implode (self ::ADDRESS_LINE_SEPARATOR , $ line );
280+ if ($ this ->getNeighborhood ()) {
281+ $ line [] = $ this ->getNeighborhood ();
282+ }
283+
284+ return implode (self ::ADDRESS_LINE_SEPARATOR , $ line );
298285 }
299286
300287 public function getLine2 ()
@@ -334,21 +321,21 @@ public function setState($state)
334321 }
335322
336323 /**
337- * Specify data which should be serialized to JSON
338- * @link https://php.net/manual/en/jsonserializable.jsonserialize.php
339- * @return string data which can be serialized by <b>json_encode</b>,
340- * which is a value of any type other than a resource.
341- * @since 5.4.0
342- */
324+ * Specify data which should be serialized to JSON
325+ * @link https://php.net/manual/en/jsonserializable.jsonserialize.php
326+ * @return \stdClass data which can be serialized by <b>json_encode</b>,
327+ * which is a value of any type other than a resource.
328+ * @since 5.4.0
329+ */
343330 #[\ReturnTypeWillChange]
344331 public function jsonSerialize ()
345332 {
346333 $ obj = new \stdClass ();
347334
348- $ obj ->number = $ this ->number ;
349335 $ obj ->street = $ this ->street ;
350- $ obj ->neighborhood = $ this ->neighborhood ;
336+ $ obj ->number = $ this ->number ;
351337 $ obj ->complement = $ this ->complement ;
338+ $ obj ->neighborhood = $ this ->neighborhood ;
352339 $ obj ->zipCode = $ this ->zipCode ;
353340 $ obj ->city = $ this ->city ;
354341 $ obj ->state = $ this ->state ;
@@ -366,16 +353,16 @@ public function convertToSDKRequest()
366353 {
367354 $ addressRequest = new CreateAddressRequest ();
368355
369- $ addressRequest ->city = $ this ->getCity ();
356+ $ addressRequest ->street = $ this ->getStreet ();
357+ $ addressRequest ->number = $ this ->getNumber ();
370358 $ addressRequest ->complement = $ this ->getComplement ();
371- $ addressRequest ->country = $ this ->getCountry ();
372- $ addressRequest ->line1 = $ this ->getLine1 ();
373- $ addressRequest ->line2 = $ this ->getLine2 ();
374359 $ addressRequest ->neighborhood = $ this ->getNeighborhood ();
375- $ addressRequest ->number = $ this ->getNumber ();
360+ $ addressRequest ->city = $ this ->getCity ();
376361 $ addressRequest ->state = $ this ->getState ();
377- $ addressRequest ->street = $ this ->getStreet ();
362+ $ addressRequest ->country = $ this ->getCountry ();
378363 $ addressRequest ->zipCode = $ this ->getZipCode ();
364+ $ addressRequest ->line1 = $ this ->getLine1 ();
365+ $ addressRequest ->line2 = $ this ->getLine2 ();
379366
380367 return $ addressRequest ;
381368 }
0 commit comments