/**
  * Gets payment method list for specified currency
  *
  * @param string $currency
  *
  * @return WebToPay_PaymentMethodList
  *
  * @throws WebToPayException
  */
 public function getPaymentMethodList($currency)
 {
     if (!isset($this->methodListCache[$currency])) {
         $xmlAsString = $this->webClient->get(WebToPay::XML_URL . $this->projectId . '/currency:' . $currency);
         $useInternalErrors = libxml_use_internal_errors(false);
         $rootNode = simplexml_load_string($xmlAsString);
         libxml_clear_errors();
         libxml_use_internal_errors($useInternalErrors);
         if (!$rootNode) {
             throw new WebToPayException('Unable to load XML from remote server');
         }
         $methodList = new WebToPay_PaymentMethodList($this->projectId, $currency);
         $methodList->fromXmlNode($rootNode);
         $this->methodListCache[$currency] = $methodList;
     }
     return $this->methodListCache[$currency];
 }
Example #2
0
 /**
  * Returns new payment method list instance with only those payment methods, which are available for provided
  * amount.
  * Returns itself, if list is already filtered and filter amount matches the given one.
  *
  * @param integer $amount
  * @param string  $currency
  *
  * @return WebToPay_PaymentMethodList
  *
  * @throws WebToPayException    if this list is already filtered and not for provided amount
  */
 public function filterForAmount($amount, $currency)
 {
     if ($currency !== $this->currency) {
         throw new WebToPayException('Currencies do not match. Given currency: ' . $currency . ', currency in list: ' . $this->currency);
     }
     if ($this->isFiltered()) {
         if ($this->amount === $amount) {
             return $this;
         } else {
             throw new WebToPayException('This list is already filtered, use unfiltered list instead');
         }
     } else {
         $list = new WebToPay_PaymentMethodList($this->projectId, $currency, $this->defaultLanguage, $amount);
         foreach ($this->getCountries() as $country) {
             $country = $country->filterForAmount($amount, $currency);
             if (!$country->isEmpty()) {
                 $list->addCountry($country);
             }
         }
         return $list;
     }
 }