Search in sources :

Example 1 with Limit

use of org.killbill.billing.catalog.api.Limit in project killbill by killbill.

the class UsageUtils method getCapacityInArrearUnitTypes.

public static Set<String> getCapacityInArrearUnitTypes(final Usage usage) {
    Preconditions.checkArgument(usage.getBillingMode() == BillingMode.IN_ARREAR && usage.getUsageType() == UsageType.CAPACITY);
    Preconditions.checkArgument(usage.getTiers().length > 0);
    final Set<String> result = new HashSet<String>();
    for (Tier tier : usage.getTiers()) {
        for (Limit limit : tier.getLimits()) {
            result.add(limit.getUnit().getName());
        }
    }
    return result;
}
Also used : Tier(org.killbill.billing.catalog.api.Tier) Limit(org.killbill.billing.catalog.api.Limit) HashSet(java.util.HashSet)

Example 2 with Limit

use of org.killbill.billing.catalog.api.Limit in project killbill by killbill.

the class ContiguousIntervalUsageInArrear method computeToBeBilledCapacityInArrear.

/**
     * @param roUnits the list of rolled up units for the period
     * @return the price amount that should be billed for that period/unitType
     * @throws CatalogApiException
     */
@VisibleForTesting
BigDecimal computeToBeBilledCapacityInArrear(final List<RolledUpUnit> roUnits) throws CatalogApiException {
    Preconditions.checkState(isBuilt.get());
    final List<Tier> tiers = getCapacityInArrearTier(usage);
    for (final Tier cur : tiers) {
        boolean complies = true;
        for (final RolledUpUnit ro : roUnits) {
            final Limit tierLimit = getTierLimit(cur, ro.getUnitType());
            // Specifying a -1 value for last max tier will make the validation works
            if (tierLimit.getMax() != (double) -1 && ro.getAmount().doubleValue() > tierLimit.getMax()) {
                complies = false;
                break;
            }
        }
        if (complies) {
            return cur.getRecurringPrice().getPrice(getCurrency());
        }
    }
    // Probably invalid catalog config
    final Joiner joiner = Joiner.on(", ");
    joiner.join(roUnits);
    Preconditions.checkState(false, "Could not find tier for usage " + usage.getName() + "matching with data = " + joiner.join(roUnits));
    return null;
}
Also used : Joiner(com.google.common.base.Joiner) RolledUpUnit(org.killbill.billing.usage.api.RolledUpUnit) Tier(org.killbill.billing.catalog.api.Tier) UsageUtils.getCapacityInArrearTier(org.killbill.billing.invoice.usage.UsageUtils.getCapacityInArrearTier) Limit(org.killbill.billing.catalog.api.Limit) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

Limit (org.killbill.billing.catalog.api.Limit)2 Tier (org.killbill.billing.catalog.api.Tier)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Joiner (com.google.common.base.Joiner)1 HashSet (java.util.HashSet)1 UsageUtils.getCapacityInArrearTier (org.killbill.billing.invoice.usage.UsageUtils.getCapacityInArrearTier)1 RolledUpUnit (org.killbill.billing.usage.api.RolledUpUnit)1