/** * Get the currency used in a given country * * @param string|int $country country iso code * * @return iso-4217 currency code or null if no match was found. */ public function getCurrency($country) { $country = KiTT_Locale::parseCountry($country); foreach (self::$lookup as $currency => $countries) { if (array_key_exists($country, $countries)) { return $currency; } } return null; }
/** * Get the formatted street required for a Klarna Addr * * @param string $street The street to split * @param mixed $country The country to split for * * @return array */ public static function splitStreet($street, $country) { $country = KiTT_Locale::parseCountry($country); $split = KiTT_CountryLogic::getSplit($country); $elements = self::splitAddress($street); $result = array('street' => $elements[0]); if (in_array('house_extension', $split)) { $result['house_extension'] = $elements[2]; } else { $elements[1] .= ' ' . $elements[2]; } if (in_array('house_number', $split)) { $result['house_number'] = $elements[1]; } else { $result['street'] .= ' ' . $elements[1]; } return array_map('trim', $result); }
/** * Create a new Klarna instance with the configuration provided * * Required: * + Configuration value 'api' which must hold the KlarnaConfig keys: * - mode * - pcStorage * - pcURI * + Configuration value 'module' * + Configuration value 'version' * * @param string|int $country KlarnaCountry constant or string representative * * @throws InvalidArgumentException, KiTT_MissingSalesCountryException, * KiTT_MissingConfigurationException, KlarnaException * * @return KiTT_API */ public static function api($country) { $country = KiTT_Locale::parseCountry($country); if ($country === null) { throw new InvalidArgumentException('$country must be a valid Klarna country'); } $configuration = self::configuration(); $salesCountry = $configuration->get("sales_countries/{$country}"); $array = new ArrayObject(array_merge($salesCountry, $configuration->get("api"))); $klarna = new KiTT_API($configuration); $klarna->setConfig($array); return $klarna; }