/** * Attempt to locate where a user is from based on currency, * language and address. * * @param string $currency iso-4217 currency code * @param string $language iso-639-1 language code * @param KlarnaAddr $address Customers KlarnaAddr object * @param string $ipAddress Customer IPAddress for eventual geoIP lookup * * @return Country iso-3166-alpha-2 code if a match is found, null * otherwise. */ public function locate($currency = null, $language = null, $address = null, $ipAddress = null) { // Polish input to be the expected uppercase and lowercase if ($currency !== null) { $currency = strtoupper($currency); } if ($language !== null) { $language = strtolower($language); } // If the currency is not in the list of supported currencies, exit if ($this->_lookup->getCountries($currency) === null) { return null; } // If we do have an address, check if it is valid to sell to. If it is, // return it, otherwise exit if ($address !== null) { $country = strtoupper(KlarnaCountry::getCode($address->getCountry())); return $this->_getValid($country, $currency); } // Get all possible valid candidates based on currency and language. $candidates = $this->_getCandidates($currency, $language); // If there is only one valid candidate, return it if (count($candidates) === 1) { return $candidates[0]; } // Check if the default store is a valid candidate, and if it is, // return it. $default = $this->_getDefaultCountry(); if ($default !== null && in_array($default, $candidates)) { return $default; } // No match has been found, exit. return null; }