예제 #1
0
 /**
  * Help function to sort the address for update digest.
  *
  * @param KlarnaAddr|null $address KlarnaAddr object or null
  *
  * @return array
  */
 private function _addressDigestPart(KlarnaAddr $address = null)
 {
     if ($address === null) {
         return array();
     }
     $keyOrder = array('careof', 'street', 'zip', 'city', 'country', 'fname', 'lname');
     $holder = $address->toArray();
     $digest = array();
     foreach ($keyOrder as $key) {
         if ($holder[$key] != "") {
             $digest[] = $holder[$key];
         }
     }
     return $digest;
 }
예제 #2
0
 /**
  * Returns an associative array used to send the address to Klarna.
  *
  * @ignore Do not show this in PHPDoc.
  * @param  string      $method  __METHOD__, the method calling assembleAddr.
  * @param  KlarnaAddr  $addr    Address object to assemble.
  * @throws KlarnaException
  * @return array The address for the specified method.
  */
 protected function assembleAddr($method, $addr)
 {
     if (!$addr instanceof KlarnaAddr) {
         throw new KlarnaException('Error in ' . $method . ': Specified address is not a KlarnaAddr object! (Call setAddress first?!)', 50013);
     }
     $tmp = $addr->toArray();
     //Check address!
     if ($tmp['country'] === KlarnaCountry::NL || $tmp['country'] === KlarnaCountry::DE) {
         if (strlen($tmp['house_number']) == 0) {
             throw new KlarnaException("Error in " . $method . ': House number needs to be specified for Netherlands and Germany!', 50014);
         }
     }
     if (strlen($tmp['email']) == 0) {
         throw new KlarnaException("Error in " . $method . ': Email address not set!', 50015);
     }
     //Check email against a regular expression.
     if (!preg_match("/^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*(\\.[a-zA-Z0-9-][a-zA-Z0-9-]+)+\$/", $tmp['email'])) {
         throw new KlarnaException("Error in " . $method . ': Email address is not valid! (' . $tmp['email'] . ')', 50016);
     }
     //Only check fname and lname if company isn't set.
     if (strlen($tmp['company']) == 0) {
         if (strlen($tmp['fname']) == 0) {
             throw new KlarnaException("Error in " . $method . ': First name not set!', 50017);
         }
         if (strlen($tmp['lname']) == 0) {
             throw new KlarnaException("Error in " . $method . ': Last name not set!', 50018);
         }
     }
     if (strlen($tmp['street']) == 0) {
         throw new KlarnaException("Error in " . $method . ': Street address not set!', 50019);
     }
     if (strlen($tmp['zip']) == 0) {
         throw new KlarnaException("Error in " . $method . ': Zip code not set!', 50020);
     }
     if (strlen($tmp['city']) == 0) {
         throw new KlarnaException("Error in " . $method . ': City not set!', 50021);
     }
     if ($tmp['country'] <= 0) {
         throw new KlarnaException("Error in " . $method . ': Country not set!', 50022);
     }
     return $tmp;
 }
예제 #3
0
 /**
  * Returns an associative array used to send the address to Klarna.
  *
  *
  * @param KlarnaAddr $addr Address object to assemble.
  *
  * @throws KlarnaException
  * @return array The address for the specified method.
  */
 protected function assembleAddr($addr)
 {
     if (!$addr instanceof KlarnaAddr) {
         throw new Klarna_InvalidKlarnaAddrException();
     }
     return $addr->toArray();
 }