public function testParseFirstLine() { $this->assertSame(['Hauptstraße', '12'], AddressParser::parseFirstLine('Hauptstraße 12')); $this->assertSame(['Hlavné n.', null], AddressParser::parseFirstLine(' Hlavné n. ')); $this->assertSame(['Hlavné n.', '245 / B'], AddressParser::parseFirstLine('Hlavné n. 245 / B ')); $this->assertSame(['Náměstí 15. pluku', '1224 / IV,V / 24a'], AddressParser::parseFirstLine('Náměstí 15. pluku 1224 / IV,V / 24a')); $this->assertSame(['Vedľajšia ulica', '5 / i-iv'], AddressParser::parseFirstLine('Vedľajšia ulica 5 / i-iv')); $this->assertSame(['Street A. Lt.', '12 / B -E'], AddressParser::parseFirstLine('Street A. Lt. 12 / B -E')); $this->assertSame(['Local Vi.', 'VI.'], AddressParser::parseFirstLine('Local Vi. VI.')); $this->assertSame(['Square of the Day of the 1st vic.', 'VI. - III.'], AddressParser::parseFirstLine('Square of the Day of the 1st vic. VI. - III. ')); $this->assertSame(['Square of the Day of the 1st vic', 'VI. - III.'], AddressParser::parseFirstLine('Square of the Day of the 1st vic VI. - III. ')); $this->assertSame(['Square of the Day of the 1st Vi.', 'VI. - III.'], AddressParser::parseFirstLine('Square of the Day of the 1st Vi. VI. - III. ')); $this->assertSame(['Square of the Day of the', '1st VI. VI. - III.'], AddressParser::parseFirstLine('Square of the Day of the 1st VI. VI. - III. ')); $this->assertSame(['Square of the Day of the', '1st vi. vi. - iii.'], AddressParser::parseFirstLine('Square of the Day of the 1st vi. vi. - iii. ')); $this->assertSame(['Meierskamp', '31b'], AddressParser::parseFirstLine('Meierskamp 31b')); $this->assertSame(['Meierskamp', '31b'], AddressParser::parseFirstLine('Meierskamp31b')); $this->assertSame(['Meierskamp', '31b'], AddressParser::parseFirstLine('Meierskamp,31b')); $this->assertSame(['Meierskamp', '315XI'], AddressParser::parseFirstLine('Meierskamp315XI')); $this->assertSame(['Hauptstraße', '12'], AddressParser::parseFirstLine('Hauptstraße,12')); $this->assertSame(['Hauptstraße', ''], AddressParser::parseFirstLine('Hauptstraße,')); $this->assertSame(['Hauptstraße', null], AddressParser::parseFirstLine('Hauptstraße')); $this->assertSame(['Hauptstraße', '12'], AddressParser::parseFirstLine('Hauptstraße,,,12')); $this->assertSame(['Hauptstraße', '12'], AddressParser::parseFirstLine('Hauptstraße12')); }
/** * @param CreditCard $card * @param bool $isShipping * @return KlarnaAddr */ protected function createKlarnaAddr(CreditCard $card, $isShipping = false) { $phone = $isShipping ? $card->getShippingPhone() : $card->getPhone(); $mobile = $isShipping ? $card->getShippingMobile() : $card->getMobile(); $firstName = $isShipping ? $card->getShippingFirstName() : $card->getFirstName(); $lastName = $isShipping ? $card->getShippingLastName() : $card->getLastName(); $postCode = $isShipping ? $card->getShippingPostcode() : $card->getPostcode(); $city = $isShipping ? $card->getShippingCity() : $card->getCity(); $country = strtoupper($isShipping ? $card->getShippingCountry() : $card->getCountry()); $address1 = $isShipping ? $card->getShippingAddress1() : $card->getAddress1(); $address2 = $isShipping ? $card->getShippingAddress2() : $card->getAddress2(); $company = $isShipping ? $card->getShippingCompany() : $card->getCompany(); $careof = ''; $street = $address1; $houseNo = null; $houseExt = null; if ('AT' === $country or 'DE' === $country or 'NL' === $country) { if (is_null($address2)) { list($street, $houseNo) = AddressParser::parseFirstLine($address1); } else { $houseNo = $address2; } } else { if ($address2) { $street .= ' ' . $address2; } } $result = new KlarnaAddr($card->getEmail(), $phone, $mobile, $firstName, $lastName, $careof, $street, $postCode, $city, KlarnaCountry::fromCode($country), $houseNo, $houseExt); if ($company) { $result->setCompanyName($company); $result->isCompany = true; } return $result; }