public function getCheapestPClass($sum, $flags)
    {
        if (!is_numeric($sum)) {
            throw new Klarna_InvalidPriceException($sum);
        }

        if (!is_numeric($flags)
            || !in_array(
                $flags, array(
                    KlarnaFlags::CHECKOUT_PAGE, KlarnaFlags::PRODUCT_PAGE)
            )
        ) {
            throw new Klarna_InvalidTypeException(
                'flags',
                KlarnaFlags::CHECKOUT_PAGE . ' or ' . KlarnaFlags::PRODUCT_PAGE
            );
        }

        $lowest_pp = $lowest = false;

        foreach ($this->getPClasses() as $pclass) {
            $lowest_payment = KlarnaCalc::get_lowest_payment_for_account(
                $pclass->getCountry()
            );
            if ($pclass->getType() < 2 && $sum >= $pclass->getMinAmount()) {
                $minpay = KlarnaCalc::calc_monthly_cost(
                    $sum, $pclass, $flags
                );

                if ($minpay < $lowest_pp || $lowest_pp === false) {
                    if ($pclass->getType() == KlarnaPClass::ACCOUNT
                        || $minpay >= $lowest_payment
                    ) {
                        $lowest_pp = $minpay;
                        $lowest = $pclass;
                    }
                }
            }
        }

        return $lowest;
    }
public function getCheapestPClass($sum, $flags)
    {
        if (!is_numeric($sum)) {
            throw new Klarna_InvalidPriceException($sum);
        }

        if (!is_numeric($flags)
            || !in_array(
                $flags, array(
                    KlarnaFlags::CHECKOUT_PAGE, KlarnaFlags::PRODUCT_PAGE)
            )
        ) {
            throw new Klarna_InvalidTypeException(
                'flags',
                KlarnaFlags::CHECKOUT_PAGE . ' or ' . KlarnaFlags::PRODUCT_PAGE
            );
        }

        $lowest_pp = $lowest = false;

        foreach ($this->getPClasses() as $pclass) {
            $lowest_payment = KlarnaCalc::get_lowest_payment_for_account(
                $pclass->getCountry()
            );
            if ($pclass->getType() < 2 && $sum >= $pclass->getMinAmount()) {
                $minpay = KlarnaCalc::calc_monthly_cost(
                    $sum, $pclass, $flags
                );

                if ($minpay < $lowest_pp || $lowest_pp === false) {
                    if ($pclass->getType() == KlarnaPClass::ACCOUNT
                        || $minpay >= $lowest_payment
                    ) {
                        $lowest_pp = $minpay;
                        $lowest = $pclass;
                    }
                }
            }
        }

        return $lowest;
    }
public function getCheapestPClass ( $ sum , $ flags ) { if ( ! is_numeric ( $ sum ) ) { throw new Klarna_InvalidPriceException ( $ sum ) ; } if ( ! is_numeric ( $ flags ) || ! in_array ( $ flags , array ( KlarnaFlags :: CHECKOUT_PAGE , KlarnaFlags :: PRODUCT_PAGE ) ) ) { throw new Klarna_InvalidTypeException ( 'flags' , KlarnaFlags :: CHECKOUT_PAGE . ' or ' . KlarnaFlags :: PRODUCT_PAGE ) ; } $ lowest_pp = $ lowest = false ; foreach ( $ this -> getPClasses ( ) as $ pclass ) { $ lowest_payment = KlarnaCalc :: get_lowest_payment_for_account ( $ pclass -> getCountry ( ) ) ; if ( $ pclass -> getType ( ) < 2 && $ sum >= $ pclass -> getMinAmount ( ) ) { $ minpay = KlarnaCalc :: calc_monthly_cost ( $ sum , $ pclass , $ flags ) ; if ( $ minpay < $ lowest_pp || $ lowest_pp === false ) { if ( $ pclass -> getType ( ) == KlarnaPClass :: ACCOUNT || $ minpay >= $ lowest_payment ) { $ lowest_pp = $ minpay ; $ lowest = $ pclass ; } } } } return $ lowest ; }
Returns the cheapest, per month, PClass related to the specified sum.

<b>Note</b>: This choose the cheapest PClass for the current country.<br>
{@link Klarna::setCountry()}

<b>Flags can be</b>:<br>
{@link KlarnaFlags::CHECKOUT_PAGE}<br>
{@link KlarnaFlags::PRODUCT_PAGE}<br>

@param float $sum   The product cost, or total sum of the cart.
@param int   $flags Which type of page the info will be displayed on.

@throws KlarnaException
@return KlarnaPClass or false if none was found.
Returns the cheapest per month PClass related to the specified sum .