Search in sources :

Example 1 with PaymentResponse

use of org.killbill.billing.payment.api.PaymentResponse in project killbill by killbill.

the class BillingStateCalculator method calculateBillingState.

public BillingState calculateBillingState(final ImmutableAccountData account, final InternalTenantContext context) throws OverdueException {
    final SortedSet<Invoice> unpaidInvoices = unpaidInvoicesForAccount(account.getId(), account.getTimeZone(), context);
    final int numberOfUnpaidInvoices = unpaidInvoices.size();
    final BigDecimal unpaidInvoiceBalance = sumBalance(unpaidInvoices);
    LocalDate dateOfEarliestUnpaidInvoice = null;
    UUID idOfEarliestUnpaidInvoice = null;
    final Invoice invoice = earliest(unpaidInvoices);
    if (invoice != null) {
        dateOfEarliestUnpaidInvoice = invoice.getInvoiceDate();
        idOfEarliestUnpaidInvoice = invoice.getId();
    }
    //TODO MDW
    final PaymentResponse responseForLastFailedPayment = PaymentResponse.INSUFFICIENT_FUNDS;
    final List<Tag> accountTags = tagApi.getTags(account.getId(), ObjectType.ACCOUNT, context);
    final Tag[] tags = accountTags.toArray(new Tag[accountTags.size()]);
    return new BillingState(account.getId(), numberOfUnpaidInvoices, unpaidInvoiceBalance, dateOfEarliestUnpaidInvoice, account.getTimeZone(), idOfEarliestUnpaidInvoice, responseForLastFailedPayment, tags);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) Tag(org.killbill.billing.util.tag.Tag) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) BillingState(org.killbill.billing.overdue.config.api.BillingState) PaymentResponse(org.killbill.billing.payment.api.PaymentResponse)

Aggregations

BigDecimal (java.math.BigDecimal)1 UUID (java.util.UUID)1 LocalDate (org.joda.time.LocalDate)1 Invoice (org.killbill.billing.invoice.api.Invoice)1 BillingState (org.killbill.billing.overdue.config.api.BillingState)1 PaymentResponse (org.killbill.billing.payment.api.PaymentResponse)1 Tag (org.killbill.billing.util.tag.Tag)1