/** * {@inheritDoc} */ protected function populateConfig(ArrayObject $config) { if (!class_exists('KlarnaCurrency')) { throw new \LogicException('You must install "fp/klarna-invoice" library.'); } $config->defaults(array('payum.factory_name' => 'klarna_invoice', 'payum.factory_title' => 'Klarna Invoice', 'sandbox' => true, 'pClassStorage' => 'json', 'pClassStoragePath' => './pclasses.json', 'xmlRpcVerifyHost' => 2, 'xmlRpcVerifyPeer' => true, 'payum.action.capture' => new CaptureAction(), 'payum.action.authorize' => new AuthorizeAction(), 'payum.action.status' => new StatusAction(), 'payum.action.sync' => new SyncAction(), 'payum.action.refund' => new RefundAction(), 'payum.action.api.activate' => new ActivateAction(), 'payum.action.api.activate_reservation' => new ActivateReservationAction(), 'payum.action.api.cancel_reservation' => new CancelReservationAction(), 'payum.action.api.check_order_status' => new CheckOrderStatusAction(), 'payum.action.api.get_addresses' => new GetAddressesAction(), 'payum.action.api.populate_klarna_from_details' => new PopulateKlarnaFromDetailsAction(), 'payum.action.api.credit_invoice' => new CreditInvoiceAction(), 'payum.action.api.credit_part' => new CreditPartAction(), 'payum.action.api.reserve_amount' => new ReserveAmountAction(), 'payum.action.api.return_amount' => new ReturnAmountAction(), 'payum.action.api.email_invoice' => new EmailInvoiceAction(), 'payum.action.api.send_invoice' => new SendInvoiceAction(), 'payum.action.api.update' => new UpdateAction())); if (false == $config['payum.api']) { $config['payum.default_options'] = array('eid' => '', 'secret' => '', 'country' => '', 'language' => '', 'currency' => '', 'sandbox' => true); $config->defaults($config['payum.default_options']); $config['payum.required_options'] = array('eid', 'secret', 'country', 'language', 'currency'); $config->defaults(array('sandbox' => true)); $config['payum.api'] = function (ArrayObject $config) { $config->validateNotEmpty($config['payum.required_options']); $config['mode'] = $config['sandbox'] ? \Klarna::BETA : \Klarna::LIVE; if (null === ($country = \KlarnaCountry::fromCode($config['country']))) { throw new LogicException(sprintf('Given %s country code is not valid. Klarna cannot recognize it.', $config['country'])); } if (null === ($language = \KlarnaLanguage::fromCode($config['language']))) { throw new LogicException(sprintf('Given %s language code is not valid. Klarna cannot recognize it.', $config['language'])); } if (null === ($currency = \KlarnaCurrency::fromCode($config['currency']))) { throw new LogicException(sprintf('Given %s currency code is not valid. Klarna cannot recognize it.', $config['currency'])); } $klarnaConfig = new Config(); $klarnaConfig->eid = $config['eid']; $klarnaConfig->secret = $config['secret']; $klarnaConfig->mode = $config['mode']; $klarnaConfig->country = $country; $klarnaConfig->language = $language; $klarnaConfig->currency = $currency; $klarnaConfig->pClassStorage = $config['pClassStorage']; $klarnaConfig->pClassStoragePath = $config['pClassStoragePath']; $klarnaConfig->xmlRpcVerifyHost = $config['xmlRpcVerifyHost']; $klarnaConfig->xmlRpcVerifyHost = $config['xmlRpcVerifyHost']; return $klarnaConfig; }; } }
/** * Sets the country, use either a two letter representation or the integer * constant. * * @param int $country {@link KlarnaCountry} * * @throws KlarnaException * @return void */ public function setCountry($country) { if ($country === null) { throw new Klarna_ArgumentNotSetException('Country'); } if (is_numeric($country)) { if (!is_int($country)) { $country = intval($country); } $this->country = $country; return; } if (strlen($country) == 2 || strlen($country) == 3) { $this->setCountry(KlarnaCountry::fromCode($country)); return; } throw new KlarnaException("Failed to set country! ({$country})"); }
/** * Sets the active country from a ISO country string * or a KlarnaCountry constant */ public function setCountry($country) { if (!is_numeric($country)) { $country = KlarnaCountry::fromCode($country); } else { $country = intval($country); } if ($this->oKlarna == NULL) { throw new KlarnaApiException('Error in ' . __METHOD__ . ': Klarna instance not set'); } $this->iKlarnaCountry = $country; $this->iKlarnaCurrency = $this->oKlarna->getCurrencyForCountry($country); $this->sCountryCode = $this->oKlarna->getCountryCode($country); }
/** * get the country of the locale * * @return int country constant */ public function getCountry() { return KlarnaCountry::fromCode($this->_country); }
/** * Returns the {@link KlarnaCountry country} constant from the country code. * * @param string $code Two letter code, e.g. "se", "no", etc. * @throws KlarnaException * @return int {@link KlarnaCountry Country} constant. */ public static function getCountryForCode($code) { $country = KlarnaCountry::fromCode($code); if ($country === null) { throw new KlarnaException('Error in ' . __METHOD__ . ': Unknown country! ("' . $code . '")', 50002); } return $country; }
/** * Returns the {@link KlarnaCountry country} constant from the country code. * * @param string $code Two letter code, e.g. "se", "no", etc. * * @throws KlarnaException * @return int {@link KlarnaCountry Country} constant. */ public static function getCountryForCode($code) { $country = KlarnaCountry::fromCode($code); if ($country === null) { throw new Klarna_UnknownCountryException($code); } return $country; }