/**
  * @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;
 }
 /**
  * @param CreditCard $card
  * @param array $data
  * @return array
  */
 protected function addDataFromCard(CreditCard $card, array $data)
 {
     if ($card->getFirstName()) {
         $data['NAME.GIVEN'] = $card->getFirstName();
     }
     if ($card->getLastName()) {
         $data['NAME.FAMILY'] = $card->getLastName();
     }
     if ($card->getSalutation()) {
         $data['NAME.SALUTATION'] = $card->getSalutation();
     }
     if ($card->getTitle()) {
         $data['NAME.TITLE'] = $card->getTitle();
     }
     if ($card->getGender()) {
         $gender = $card->getGender();
         if (CreditCard::GENDER_MALE === $gender) {
             $data['NAME.SEX'] = 'M';
         } elseif (CreditCard::GENDER_FEMALE === $gender) {
             $data['NAME.SEX'] = 'F';
         } else {
             $data['NAME.SEX'] = strtoupper(substr($gender, 0, 1));
         }
     }
     if ($card->getBirthday()) {
         $data['NAME.BIRTHDATE'] = $card->getBirthday();
     }
     if ($card->getCompany()) {
         $data['NAME.COMPANY'] = $card->getCompany();
     }
     if ($card->getCountry()) {
         $data['ADDRESS.COUNTRY'] = $card->getCountry();
     }
     if ($card->getState()) {
         $data['ADDRESS.STATE'] = $card->getState();
     }
     if ($card->getCity()) {
         $data['ADDRESS.CITY'] = $card->getCity();
     }
     if ($card->getPostcode()) {
         $data['ADDRESS.ZIP'] = $card->getPostcode();
     }
     $street = '';
     if ($card->getAddress1()) {
         $street = $card->getAddress1();
     }
     if ($card->getAddress2()) {
         $street .= "\n" . $card->getAddress2();
     }
     $street = trim($street);
     if ($street) {
         $data['ADDRESS.STREET'] = $street;
     }
     if ($card->getEmail()) {
         $data['CONTACT.EMAIL'] = $card->getEmail();
     }
     if ($card->getPhone()) {
         $data['CONTACT.PHONE'] = $card->getPhone();
     }
     if ($card->getMobile()) {
         $data['CONTACT.MOBILE'] = $card->getMobile();
     }
     if ($card->getIdentificationDocumentType() and $card->getIdentificationDocumentNumber()) {
         $data['CUSTOMER.IDENTIFICATION.PAPER'] = $card->getIdentificationDocumentType();
         $data['CUSTOMER.IDENTIFICATION.VALUE'] = $card->getIdentificationDocumentNumber();
     }
     if ($card->getShippingContactDifferences()) {
         $data = $this->addShippingDataFromCard($card, $data);
     }
     return $data;
 }