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;
}
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;
}
Aggregations