use of org.killbill.billing.overdue.config.api.BillingState in project killbill by killbill.
the class TestCondition method testHasControlTag.
@Test(groups = "fast")
public void testHasControlTag() throws Exception {
final String xml = "<condition>" + " <controlTagInclusion>OVERDUE_ENFORCEMENT_OFF</controlTagInclusion>" + "</condition>";
final InputStream is = new ByteArrayInputStream(xml.getBytes());
final MockCondition c = XMLLoader.getObjectFromStreamNoValidation(is, MockCondition.class);
final UUID unpaidInvoiceId = UUID.randomUUID();
final LocalDate now = new LocalDate();
final ObjectType objectType = ObjectType.BUNDLE;
final UUID objectId = new UUID(0L, 1L);
final BillingState state0 = new BillingState(objectId, 0, BigDecimal.ZERO, null, DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.LOST_OR_STOLEN_CARD, new Tag[] { new DefaultControlTag(ControlTagType.AUTO_INVOICING_OFF, objectType, objectId, clock.getUTCNow()), new DescriptiveTag(UUID.randomUUID(), objectType, objectId, clock.getUTCNow()) });
final BillingState state1 = new BillingState(objectId, 1, new BigDecimal("100.00"), now.minusDays(10), DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[] { new DefaultControlTag(ControlTagType.OVERDUE_ENFORCEMENT_OFF, objectType, objectId, clock.getUTCNow()) });
final BillingState state2 = new BillingState(objectId, 1, new BigDecimal("200.00"), now.minusDays(20), DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.DO_NOT_HONOR, new Tag[] { new DefaultControlTag(ControlTagType.OVERDUE_ENFORCEMENT_OFF, objectType, objectId, clock.getUTCNow()), new DefaultControlTag(ControlTagType.AUTO_INVOICING_OFF, objectType, objectId, clock.getUTCNow()), new DescriptiveTag(UUID.randomUUID(), objectType, objectId, clock.getUTCNow()) });
Assert.assertTrue(!c.evaluate(state0, now));
Assert.assertTrue(c.evaluate(state1, now));
Assert.assertTrue(c.evaluate(state2, now));
}
use of org.killbill.billing.overdue.config.api.BillingState in project killbill by killbill.
the class TestCondition method testNumberOfUnpaidInvoicesEqualsOrExceeds.
@Test(groups = "fast")
public void testNumberOfUnpaidInvoicesEqualsOrExceeds() throws Exception {
final String xml = "<condition>" + " <numberOfUnpaidInvoicesEqualsOrExceeds>1</numberOfUnpaidInvoicesEqualsOrExceeds>" + "</condition>";
final InputStream is = new ByteArrayInputStream(xml.getBytes());
final MockCondition c = XMLLoader.getObjectFromStreamNoValidation(is, MockCondition.class);
final UUID unpaidInvoiceId = UUID.randomUUID();
final BillingState state0 = new BillingState(new UUID(0L, 1L), 0, BigDecimal.ZERO, new LocalDate(), DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[] {});
final BillingState state1 = new BillingState(new UUID(0L, 1L), 1, BigDecimal.ZERO, new LocalDate(), DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[] {});
final BillingState state2 = new BillingState(new UUID(0L, 1L), 2, BigDecimal.ZERO, new LocalDate(), DateTimeZone.UTC, unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[] {});
Assert.assertTrue(!c.evaluate(state0, new LocalDate()));
Assert.assertTrue(c.evaluate(state1, new LocalDate()));
Assert.assertTrue(c.evaluate(state2, new LocalDate()));
}
use of org.killbill.billing.overdue.config.api.BillingState in project killbill by killbill.
the class OverdueWrapper method refreshWithLock.
private OverdueState refreshWithLock(final DateTime effectiveDate, final InternalCallContext context) throws OverdueException, OverdueApiException {
final BillingState billingState = billingState(context);
final BlockingState blockingStateForService = api.getBlockingStateForService(overdueable.getId(), BlockingStateType.ACCOUNT, OverdueService.OVERDUE_SERVICE_NAME, context);
final String previousOverdueStateName = blockingStateForService != null ? blockingStateForService.getStateName() : OverdueWrapper.CLEAR_STATE_NAME;
final OverdueState currentOverdueState = overdueStateSet.findState(previousOverdueStateName);
final OverdueState nextOverdueState = overdueStateSet.calculateOverdueState(billingState, clock.getToday(billingState.getAccountTimeZone()));
overdueStateApplicator.apply(effectiveDate, overdueStateSet, billingState, overdueable, currentOverdueState, nextOverdueState, context);
return nextOverdueState;
}
use of org.killbill.billing.overdue.config.api.BillingState in project killbill by killbill.
the class TestDefaultBillingStateFormatter method testBalanceFormatting.
@Test(groups = "fast")
public void testBalanceFormatting() throws Exception {
final BillingState billingState = new BillingState(UUID.randomUUID(), 2, BigDecimal.TEN, new LocalDate(), DateTimeZone.UTC, UUID.randomUUID(), null, null);
final DefaultBillingStateFormatter formatter = new DefaultBillingStateFormatter(billingState);
Assert.assertEquals(formatter.getFormattedBalanceOfUnpaidInvoices(), "10.00");
}
use of org.killbill.billing.overdue.config.api.BillingState 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