Esempio n. 1
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;
     }
 }