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