Process given Coupon in order to get their cumulative effects

@param array $coupons CouponInterface to process

@return float discount
197393
protected function getEffect(array $coupons)
    {
        $discount = 0.00;
        /** @var CouponInterface $coupon */
        foreach ($coupons as $coupon) {
            $discount += $coupon->exec($this->facade);
        }

        return $discount;
    }
177437
public function getCoupons($code = null)
    {
        $requestData = new Get\RequestData($code);
        $request = new Get\Request($requestData);

        $apiResponse = $this->sendRequest($request, Get\ApiResponse::class);
        /** @var Get\Response $response */
        $response = $apiResponse->getResponse();
        foreach ($response->getCoupons() as $coupon) {
            $validFrom = $coupon->getValidFrom();
            if ($validFrom !== null) {
                $validFrom->setTime(0, 0, 0);
            }

            $validTo = $coupon->getValidTo();
            if ($validTo !== null) {
                $validTo->setTime(0, 0, 0);
            }
        }

        return $apiResponse;
    }
729058
public function toArray()
	{
		$list = parent::toArray();

		$list['coupon.config'] = $this->getConfig();
		$list['coupon.label'] = $this->getLabel();
		$list['coupon.datestart'] = $this->getDateStart();
		$list['coupon.dateend'] = $this->getDateEnd();
		$list['coupon.provider'] = $this->getProvider();
		$list['coupon.status'] = $this->getStatus();

		return $list;
	}
907745
public function discount($throwErrors = false)
    {
        $subTotal = app(LaraCart::SERVICE)->subTotal(false);

        if (config('laracart.discountOnFees', false)) {
            $subTotal = $subTotal + app(LaraCart::SERVICE)->feeTotals(false);
        }

        $total = $subTotal - $this->value;

        if ($total < 0) {
            return $subTotal;
        }

        return $this->value;
    }
839636
protected function gatherExitCodes(array $processes): int
    {
        foreach ($processes as $process) {
            if ($process->getExitCode() > 0) {
                return $process->getExitCode();
            }
        }

        return 0;
    }
1202791
function (coupon, cb) {

		Coupon.findOrCreate(coupon.id, coupon)
	    .exec(function (err, foundCoupon){
	      if (err) return cb(err);
	      if (foundCoupon.lastStripeEvent > coupon.lastStripeEvent) return cb(null, foundCoupon);
	      if (foundCoupon.lastStripeEvent == coupon.lastStripeEvent) return Coupon.afterStripeCouponCreated(foundCoupon, function(err, coupon){ return cb(err, coupon)});
	      Coupon.update(foundCoupon.id, coupon)
	      .exec(function(err, updatedCoupons){
	      	if (err) return cb(err);
	      	Coupon.afterStripeCouponCreated(updatedCoupons[0], function(err, coupon){
	      		cb(err, coupon);
	      	});
	      });
	    });
	}
301644
protected static function getBigger(array $values)
    {
        $bigger = null;

        foreach ($values as $value => $repeat) {
            if ($bigger === null || $repeat > $values[$bigger]) {
                $bigger = $value;
            }
        }

        return $bigger;
    }
593781
public function makeUse(CouponOnUsedEvent $event)
    {
        $coupon = $event->getCoupon();
        $coupon->makeUse();

        $this
            ->couponObjectManager
            ->flush($coupon);
    }
74682
public function apply(array &$tokens)
		{
		$r = 0;
		for ($i = 0, $l = count($tokens); $i < $l; $i++)
			{
			$current	= get_class($tokens[$i]);
			$next		= isset($tokens[$i + 1]) ? get_class($tokens[$i + 1]) : false;
			if (($current === "CssRulesetStartToken" && $next === "CssRulesetEndToken") ||
				($current === "CssAtKeyframesRulesetStartToken" && $next === "CssAtKeyframesRulesetEndToken" && !array_intersect(array("from", "0%", "to", "100%"), array_map("strtolower", $tokens[$i]->Selectors)))
				)
				{
				$tokens[$i]		= null;
				$tokens[$i + 1]	= null;
				$i++;
				$r = $r + 2;
				}
			}
		return $r;
		}
424688
public function discount($throwErrors = false)
    {
        $subTotal = app(LaraCart::SERVICE)->subTotal(false);
        if (config('laracart.discountOnFees', false)) {
            $subTotal = $subTotal + app(LaraCart::SERVICE)->feeTotals(false);
        }

        return LaraCart::formatMoney(
            $subTotal * $this->value,
            null,
            null,
            false
        );
    }
1181837
public function apply(array &$tokens)
		{
		$r = 0;
		$transformations = &$this->transformations;
		for ($i = 0, $l = count($tokens); $i < $l; $i++)
			{
			if (get_class($tokens[$i]) === "CssRulesetDeclarationToken")
				{
				$tProperty = $tokens[$i]->Property;
				if (isset($transformations[$tProperty]))
					{
					$result = array();
					if (is_callable($transformations[$tProperty]))
						{
						$result = call_user_func_array($transformations[$tProperty], array($tokens[$i]));
						if (!is_array($result) && is_object($result))
							{
							$result = array($result);
							}
						}
					else
						{
						$tValue			= $tokens[$i]->Value;
						$tMediaTypes	= $tokens[$i]->MediaTypes;
						foreach ($transformations[$tProperty] as $property)
							{
							if ($property !== null)
								{
								$result[] = new CssRulesetDeclarationToken($property, $tValue, $tMediaTypes);
								}
							}
						}
					if (count($result) > 0)
						{
						array_splice($tokens, $i + 1, 0, $result);
						$i += count($result);
						$l += count($result);
						}
					}
				}
			}
		return $r;
		}
999787
public function browseAction()
    {
        if (null !== $response = $this->checkAuth(AdminResources::COUPON, [], AccessManager::VIEW)) {
            return $response;
        }

        return $this->render('coupon-list', [
            'coupon_order' => $this->getListOrderFromSession('coupon', 'coupon_order', 'code')
        ]);
    }
1002130
public function process(array $items)
    {
        foreach ($items as $key => $item) {
            $items[$key] = $this->doClean($item);
        }

        return $items;
    }
1333478
public function discount(Product $product)
    {
        $discountTotal = $this->money($product);

        // "Global" Basket Discount
        foreach ($product->discounts as $discount) {
            $discountTotal = $discountTotal->add(
                $discount->product($product)->multiply($product->quantity)
            );
        }

        // Coupons
        foreach ($product->coupons as $coupon) {
            // Each discount of an coupon
            foreach ($coupon->discounts() as $productDiscount) {
                // Calculate the amount of discount
                $discount = $productDiscount->product($product);
                $discount = $discount->multiply($product->quantity);

                // Add the discount to the discount total
                $discount = new Money($discount->getAmount(), $product->price->getCurrency());
                $discountTotal = $discountTotal->add($discount);
            }
        }

        return $discountTotal;
    }
303764
public function decrementQuantity(Coupon $coupon, $customerId = null)
    {
        if ($coupon->isUsageUnlimited()) {
            return true;
        } else {
            try {
                $usageLeft = $coupon->getUsagesLeft($customerId);

                if ($usageLeft > 0) {
                    // If the coupon usage is per user, add an entry to coupon customer usage count table
                    if ($coupon->getPerCustomerUsageCount()) {
                        if (null == $customerId) {
                            throw new \LogicException("Customer should not be null at this time.");
                        }

                        $ccc = CouponCustomerCountQuery::create()
                            ->filterByCouponId($coupon->getId())
                            ->filterByCustomerId($customerId)
                            ->findOne()
                        ;

                        if ($ccc === null) {
                            $ccc = new CouponCustomerCount();

                            $ccc
                                ->setCustomerId($customerId)
                                ->setCouponId($coupon->getId())
                                ->setCount(0);
                        }

                        $newCount = 1 + $ccc->getCount();

                        $ccc
                            ->setCount($newCount)
                            ->save()
                        ;

                        return $usageLeft - $newCount;
                    } else {
                        $coupon->setMaxUsage(--$usageLeft);

                        $coupon->save();

                        return $usageLeft;
                    }
                }
            } catch (\Exception $ex) {
                // Just log the problem.
                Tlog::getInstance()->addError(sprintf("Failed to decrement coupon %s: %s", $coupon->getCode(), $ex->getMessage()));
            }
        }

        return false;
    }
1174684
public function applyDiscount($percentage, $couponId = null)
    {
        if ($percentage > 100) {
            throw new IncorrectDiscount('Maximum percentage discount can be 100%.');
        }

        if ($this->subtotal == 0) {
            throw new IncorrectDiscount('Discount cannot be applied on an empty cart.');
        }

        $this->discountPercentage = $percentage;
        $this->couponId = $couponId;
        $this->discount = round(($this->subtotal * $percentage) / 100, 2);

        $cartData = $this->cartUpdates($isNewItem = false, $keepDiscount = true);

        event(new DiscountApplied($cartData));

        return $cartData;
    }
506591
public function coupons()
    {
        $coupons = [];

        foreach ($this->transaction->discounts as $discount) {
            $coupons[] = $discount->id;
        }

        return $coupons;
    }