def round_to_billable_unit(
        billsec,
        rate_per_min,
        free_seconds=0,
        billable_unit=1):
    """
    Round the call up to the billable units
      round_to_billable_unit(5, 60) = 5
      round_to_billable_unit(5, 60, 10) = 0
      round_to_billable_unit(5, 60, 0, 30) = 30
      round_to_billable_unit(5, 60, 0, 60) = 60
      round_to_billable_unit(61, 60, 0, 60) = 120

    Args:
      billsec: the number of billable seconds
      rate_per_min: the tariff per minute, in the internal currency representation
      free_seconds: the allotment of free seconds
      billable_unit: the minimum billable amount in seconds
        (e.g., bill for every 30 seconds)


    Returns:
      integer cost
    """
    # Account for "free seconds"
    billsec = max(0, int(billsec) - int(free_seconds))

    # Round up raw seconds to seconds of billable units
    units = int(billsec / billable_unit) + (billsec % billable_unit > 0)
    normalized_billsec = units * billable_unit

    # Determine the cost given per-min rate
    return int(normalized_billsec * rate_per_min / 60.0)