Interface BillingDatabaseClient

All Known Implementing Classes:
BillingDatabaseClientMock

public interface BillingDatabaseClient
Interface that talks about bills in the billing API. It is a layer on top of the SQL database where we store data about bills.
Author:
olaa, ogronnesby
  • Method Details

    • setActivePaymentInstrument

      boolean setActivePaymentInstrument(InstrumentOwner paymentInstrument)
    • getDefaultPaymentInstrumentForTenant

      Optional<InstrumentOwner> getDefaultPaymentInstrumentForTenant(com.yahoo.config.provision.TenantName from)
    • createBill

      Bill.Id createBill(com.yahoo.config.provision.TenantName tenant, ZonedDateTime startTime, ZonedDateTime endTime, String agent)
      Create a completely new Bill in the open state with no LineItems.
      Parameters:
      tenant - The name of the tenant the bill is for
      agent - The agent that created the bill
      Returns:
      The Id of the new bill
    • readBill

      Optional<Bill> readBill(Bill.Id billId)
      Read the given bill from the data source
      Parameters:
      billId - The Id of the bill to retrieve
      Returns:
      The Bill if it exists, Optional.empty() if not.
    • readBillsForTenant

      List<Bill> readBillsForTenant(com.yahoo.config.provision.TenantName tenant)
      Get all bills for a given tenant, ordered by date
      Parameters:
      tenant - The name of the tenant
      Returns:
      List of all bills ordered by date
    • readBills

      List<Bill> readBills()
      Read all bills, ordered by date
      Returns:
      List of all bills ordered by date
    • addLineItem

      String addLineItem(com.yahoo.config.provision.TenantName tenantName, Bill.LineItem lineItem, Optional<Bill.Id> billId)
      Add a line item to an open bill
      Parameters:
      lineItem - The line item to add
      billId - The optional ID of the bill this line item is for
      Returns:
      The Id of the new line item
      Throws:
      RuntimeException - if the bill is not in OPEN state
    • setStatus

      void setStatus(Bill.Id billId, String agent, String status)
      Set status for the given bill
      Parameters:
      billId - The ID of the bill this status is for
      agent - The agent that added the status
      status - The new status of the bill
    • getUnusedLineItems

      List<Bill.LineItem> getUnusedLineItems(com.yahoo.config.provision.TenantName tenantName)
    • deleteLineItem

      void deleteLineItem(String lineItemId)
      Delete a line item This is only allowed if the line item has not yet been associated with an bill
      Parameters:
      lineItemId - The ID of the line item
      Throws:
      RuntimeException - if the line item is associated with an bill
    • commitLineItems

      void commitLineItems(com.yahoo.config.provision.TenantName tenantName, Bill.Id billId)
      Associate all uncommitted line items to a given bill This is only allowed if the line item has not already been associated with an bill
      Parameters:
      tenantName - The tenant we want to commit line items for
      billId - The ID of the line item
      Throws:
      RuntimeException - if the line item is already associated with an bill
    • getPlan

      Optional<Plan> getPlan(com.yahoo.config.provision.TenantName tenantName)
      Return the plan for the given tenant
      Parameters:
      tenantName - The tenant to retrieve the plan for
      Returns:
      Optional.of the plan if present in DN, else Optional.empty
    • getPlans

      Map<com.yahoo.config.provision.TenantName,Optional<Plan>> getPlans(List<com.yahoo.config.provision.TenantName> tenants)
      Return the plan for the given tenants if present. If the database does not know of the tenant, the tenant is not included in the result.
    • getPlanCount

      default Map<Plan,Long> getPlanCount(List<com.yahoo.config.provision.TenantName> tenants, Plan defaultPlan)
      Returns a map with the count of plan usage. Plans that are not in use will not appear in this result.
    • setPlan

      void setPlan(com.yahoo.config.provision.TenantName tenantName, Plan plan)
      Set the current plan for the given tenant
      Parameters:
      tenantName - The tenant to set the plan for
      plan - The plan to use
    • deactivateDefaultPaymentInstrument

      void deactivateDefaultPaymentInstrument(com.yahoo.config.provision.TenantName tenant)
      Deactivates the default payment instrument for a tenant, if it exists. Used during tenant deletion
    • getCollectionMethod

      Optional<CollectionMethod> getCollectionMethod(com.yahoo.config.provision.TenantName tenantName)
      Get the current collection method for the tenant - if one has persisted
      Returns:
      Optional.empty if no collection method has been persisted for the tenant
    • setCollectionMethod

      void setCollectionMethod(com.yahoo.config.provision.TenantName tenantName, CollectionMethod collectionMethod)
      Set the collection method for the tenant
      Parameters:
      tenantName - The name of the tenant to set collection method for
      collectionMethod - The collection method for the tenant
    • maintain

      void maintain()
      Performs necessary maintenance operations