Checks the minimum subtotal needed to apply the coupon.

@param $minAmount
@param $throwErrors

@throws CouponException

@return bool
327232
public function checkMinAmount($minAmount, $throwErrors = true)
    {
        $laraCart = \App::make(LaraCart::SERVICE);

        if ($laraCart->subTotal(false, false, false) >= $minAmount) {
            return true;
        } else {
            if ($throwErrors) {
                throw new CouponException('You must have at least a total of '.$laraCart->formatMoney($minAmount));
            } else {
                return false;
            }
        }
    }
871609
public function checkCoupon(CouponInterface $coupon)
    {
        if (!$this->IsActive($coupon)) {
            throw new CouponNotActiveException();
        }

        if (!$this->canBeUsed($coupon)) {
            throw new CouponAppliedException();
        }

        return true;
    }
106581
private function getPriceRangeFilterConfiguration($minAmount, $maxAmount = null)
    {
        $configuration = ['filters' => ['price_range_filter' => ['min' => $minAmount]]];
        if (null !== $maxAmount) {
            $configuration['filters']['price_range_filter']['max'] = $maxAmount;
        }

        return $configuration;
    }
515557
public function validateClaims(array $claims)
    {
        if ($this->requiredClaims) {
            $missing = array_diff_key(array_flip($this->requiredClaims), $claims);
            if (count($missing)) {
                throw new MissingClaimsException("Missing claims: " . implode(', ', $missing));
            }
        }
        if ($this->issuer && !isset($claims['iss'])) {
            throw new MissingClaimsException("Claim 'iss' is required");
        }
        if ($this->minIssueTime && !isset($claims['iat'])) {
            throw new MissingClaimsException("Claim 'iat' is required");
        }
        if (!empty($this->audience) && !isset($claims['aud'])) {
            throw new MissingClaimsException("Claim 'aud' is required");
        }
        if ((!isset($claims['sub']) || empty($claims['sub'])) && (!isset($claims['prn']) || empty($claims['prn']))) {
            throw new MissingClaimsException("Missing principle subject claim");
        }
        if (isset($claims['exp']) && $claims['exp'] + $this->issuerTimeLeeway < time()) {
            throw new InvalidTimeException("Token is expired by 'exp'");
        }
        if (isset($claims['iat']) && $claims['iat'] < ($this->minIssueTime + $this->issuerTimeLeeway)) {
            throw new InvalidTimeException("Server deemed your token too old");
        }
        if (isset($claims['nbf']) && ($claims['nbf'] - $this->issuerTimeLeeway) > time()) {
            throw new InvalidTimeException("Token not valid yet");
        }
        if (isset($claims['iss']) && $claims['iss'] !== $this->issuer) {
            throw new KeyTokenMismatchException("Issuer mismatch");
        }
        if (count($this->audience) && isset($claims['aud'])) {
            if (is_array($claims['aud'])) {
                foreach ($claims['aud'] as $claim) {
                    $this->validateAudience($claim);
                }
            } else {
                $this->validateAudience($claims['aud']);
            }
        }
    }
1159446
public function min($limit, $msg)
    {
        if(strlen($this->_value) > 0 && (float)$this->_value < (float)$limit) {
            $this->_errors[] = $msg;
        }
        return $this;
    }
616021
static public function sendException($exception, $description = ''){
		if (!sfConfig::get('app_amg_sentry_enabled', false)) {
			return true;
		}
		return self::getInstance()->captureException($exception, $description);
	}
622312
public function recalculateAmount()
    {
        $amount = 0;

        foreach ($this->getLineItems() as $lineItem) {
            $amount += $lineItem->getAmount();
        }

        $this->setAmount($amount);
    }
593781
public function makeUse(CouponOnUsedEvent $event)
    {
        $coupon = $event->getCoupon();
        $coupon->makeUse();

        $this
            ->couponObjectManager
            ->flush($coupon);
    }
200584
protected function redeemCoupons()
    {
        if (!isset($this->params['cart'])) {
            throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_API_NO_CART);
        }

        if (empty($this->response)) {
            $this->response = new ShopgatePluginApiResponseAppJson($this->trace_id);
        }

        $cart       = new ShopgateCart($this->params['cart']);
        $couponData = $this->plugin->redeemCoupons($cart);

        if (!is_array($couponData)) {
            throw new ShopgateLibraryException(
                ShopgateLibraryException::PLUGIN_API_WRONG_RESPONSE_FORMAT,
                'Plugin Response: ' . var_export($couponData, true)
            );
        }

        // Workaround:
        // $couponData was specified to be a ShopgateExternalCoupon[].
        // Now supports the same format as checkCart(), i.e. array('external_coupons' => ShopgateExternalCoupon[]).
        if (!empty($couponData['external_coupons']) && is_array($couponData['external_coupons'])) {
            $couponData = $couponData['external_coupons'];
        }

        $responseData = array("external_coupons" => array());
        foreach ($couponData as $coupon) {
            if (!is_object($coupon) || !($coupon instanceof ShopgateExternalCoupon)) {
                throw new ShopgateLibraryException(
                    ShopgateLibraryException::PLUGIN_API_WRONG_RESPONSE_FORMAT,
                    'Plugin Response: ' . var_export($coupon, true)
                );
            }

            $coupon = $coupon->toArray();
            unset($coupon["order_index"]);

            $responseData["external_coupons"][] = $coupon;
        }

        $this->responseData = $responseData;
    }
381861
public function buildCouponFromCode($couponCode)
    {
        /** @var Coupon $couponModel */
        $couponModel = $this->facade->findOneCouponByCode($couponCode);
        if ($couponModel === null) {
            return false;
        }

        // check if coupon is enabled
        if (!$couponModel->getIsEnabled()) {
            throw new InactiveCouponException($couponCode);
        }

        $nowDateTime = new \DateTime();

        // Check coupon start date
        if ($couponModel->getStartDate() !== null && $couponModel->getStartDate() > $nowDateTime) {
            throw new CouponNotReleaseException($couponCode);
        }

        // Check coupon expiration date
        if ($couponModel->getExpirationDate() < $nowDateTime) {
            throw new CouponExpiredException($couponCode);
        }

        // Check coupon usage count
        if (! $couponModel->isUsageUnlimited()) {
            if (null === $customer = $this->facade->getCustomer()) {
                throw new UnmatchableConditionException($couponCode);
            }

            if ($couponModel->getUsagesLeft($customer->getId()) <= 0) {
                throw new CouponNoUsageLeftException($couponCode);
            }
        }

        /** @var CouponInterface $couponInterface */
        $couponInterface = $this->buildCouponFromModel($couponModel);

        if ($couponInterface && $couponInterface->getConditions()->count() == 0) {
            throw new InvalidConditionException(
                \get_class($couponInterface)
            );
        }

        return $couponInterface;
    }
1239076
public function getCouponAbsoluteValue(
        CartInterface $cart,
        CouponInterface $coupon
    ) {
        $couponPercent = $coupon->getDiscount();

        return $cart
            ->getPurchasableAmount()
            ->multiply($couponPercent / 100);
    }
648278
public function amountOff()
    {
        if (isset($this->invoice->discount->coupon->amount_off)) {
            return $this->formatAmount($this->invoice->discount->coupon->amount_off);
        }

        return $this->formatAmount(0);
    }
575926
public static function stop($throw = false)
    {
        $errorException = null;

        if (static::$stack) {
            $errorException = array_pop(static::$stack);

            if (!static::$stack) {
                restore_error_handler();
            }

            if ($errorException && $throw) {
                throw $errorException;
            }
        }

        return $errorException;
    }
109581
public function byAmount( $nAmount ) {
		$oTheOne = null;
		foreach ( $this as $oBankTxn ) {
			if ( (string)$oBankTxn->amount == (string)$nAmount ) {
				$oTheOne = $oBankTxn;
				break;
			}
		}
		return $oTheOne;
	}
1323989
private function isActive(CouponInterface $coupon, \DateTime $now = null)
    {
        if (!$coupon->isEnabled()) {
            return false;
        }

        $now = $now ?: $this
            ->dateTimeFactory
            ->create();

        if ($coupon->getValidFrom() > $now) {
            return false;
        }

        $validTo = $coupon->getValidTo();
        if ($validTo && $now > $validTo) {
            return false;
        }

        return true;
    }
622136
protected function CheckBasketVoucherAvailable($sMessageConsumer)
    {
        $bBasketVoucherAvailable = true;
        $oVoucherList = $this->GetVoucherList();
        $oMessageManager = TCMSMessageManager::GetInstance();
        if ($oVoucherList) {
            if ($oVoucherList->Length() > 0) {
                $oVoucherList->GoToStart();
                while ($oBasketVoucher = $oVoucherList->Next()) {
                    $sVoucherCode = $oBasketVoucher->fieldCode;
                    $sBasketVoucherKey = $oBasketVoucher->sBasketVoucherKey;
                    $sBasketVoucherSeriesId = $oBasketVoucher->fieldShopVoucherSeriesId;
                    $oVoucher = TdbShopVoucher::GetNewInstance();
                    $bVoucherLoaded = $oVoucher->Load($oBasketVoucher->id);
                    if (($bVoucherLoaded && $oVoucher->fieldIsUsedUp) || !$bVoucherLoaded) {
                        $oNextAvailableVoucher = $this->GetNextAvailableVoucher($sVoucherCode, $sBasketVoucherSeriesId, $sMessageConsumer);

                        /**
                         * next voucher with same code is available, so auto add that one.
                         * as we do not want to inform the customer that this happened,
                         * we create a temporary message consumer for RemoveVoucher and AddVoucher messages and clear them afterwards.
                         */
                        if (!is_null($oNextAvailableVoucher)) {
                            $this->RemoveVoucher($sBasketVoucherKey, $sMessageConsumer.'-TO-BE-REMOVED');
                            $this->AddVoucher($oNextAvailableVoucher, $sMessageConsumer.'-TO-BE-REMOVED');
                            $oMessageManager->ClearMessages($sMessageConsumer.'-TO-BE-REMOVED');
                        } else {
                            $this->RemoveVoucher($sBasketVoucherKey, $sMessageConsumer);
                            $bBasketVoucherAvailable = false;
                            $this->bMarkAsRecalculationNeeded = true;
                            $oMsgManager = TCMSMessageManager::GetInstance();
                            $oMsgManager->AddMessage($sMessageConsumer, 'ERROR-ORDER-REQUEST-VOUCHER-NOT-LONGER-AVAILABLE', array('sVoucherCode' => $sVoucherCode));
                        }
                    }
                }
            }
        }

        return $bBasketVoucherAvailable;
    }
1281035
private static function validateComp($component, $value, $min, $max)
    {
        if ($value < $min || $value > $max) {
            throw new Exception(
              "{$component} component {$value} must be {$min}-{$max}");
        }
    }