コード例 #1
0
 /**
  * @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;
 }
コード例 #2
0
 protected function addShippingDataFromCard(CreditCard $card, array $data)
 {
     if ($card->getShippingFirstName()) {
         $data['CUSTOMER.SHIPPING.NAME.GIVEN'] = $card->getShippingFirstName();
     }
     if ($card->getShippingLastName()) {
         $data['CUSTOMER.SHIPPING.NAME.FAMILY'] = $card->getShippingLastName();
     }
     $street = '';
     if ($card->getShippingAddress1()) {
         $street = $card->getShippingAddress1();
     }
     if ($card->getShippingAddress2()) {
         $street .= "\n" . $card->getShippingAddress2();
     }
     $street = trim($street);
     if ($street) {
         $data['CUSTOMER.SHIPPING.ADDRESS.STREET'] = $street;
     }
     if ($card->getShippingCity()) {
         $data['CUSTOMER.SHIPPING.ADDRESS.CITY'] = $card->getShippingCity();
     }
     if ($card->getShippingPostcode()) {
         $data['CUSTOMER.SHIPPING.ADDRESS.ZIP'] = $card->getShippingPostcode();
     }
     if ($card->getShippingState()) {
         $data['CUSTOMER.SHIPPING.ADDRESS.STATE'] = $card->getShippingState();
     }
     if ($card->getShippingCountry()) {
         $data['CUSTOMER.SHIPPING.ADDRESS.COUNTRY'] = $card->getShippingCountry();
     }
     if ($card->getShippingPhone()) {
         $data['CUSTOMER.SHIPPING.CONTACT.PHONE'] = $card->getShippingPhone();
     }
     if ($card->getShippingMobile()) {
         $data['CUSTOMER.SHIPPING.CONTACT.MOBILE'] = $card->getShippingMobile();
     }
     return $data;
 }