Search in sources :

Example 1 with BillingState

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));
}
Also used : ObjectType(org.killbill.billing.ObjectType) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultControlTag(org.killbill.billing.util.tag.DefaultControlTag) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) BillingState(org.killbill.billing.overdue.config.api.BillingState) DescriptiveTag(org.killbill.billing.util.tag.DescriptiveTag) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 2 with BillingState

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()));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) BillingState(org.killbill.billing.overdue.config.api.BillingState) Test(org.testng.annotations.Test)

Example 3 with BillingState

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;
}
Also used : BlockingState(org.killbill.billing.entitlement.api.BlockingState) BillingState(org.killbill.billing.overdue.config.api.BillingState) OverdueState(org.killbill.billing.overdue.api.OverdueState)

Example 4 with BillingState

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");
}
Also used : LocalDate(org.joda.time.LocalDate) BillingState(org.killbill.billing.overdue.config.api.BillingState) Test(org.testng.annotations.Test)

Example 5 with BillingState

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

BillingState (org.killbill.billing.overdue.config.api.BillingState)8 LocalDate (org.joda.time.LocalDate)7 UUID (java.util.UUID)6 Test (org.testng.annotations.Test)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)5 BigDecimal (java.math.BigDecimal)5 ObjectType (org.killbill.billing.ObjectType)1 BlockingState (org.killbill.billing.entitlement.api.BlockingState)1 Invoice (org.killbill.billing.invoice.api.Invoice)1 OverdueState (org.killbill.billing.overdue.api.OverdueState)1 PaymentResponse (org.killbill.billing.payment.api.PaymentResponse)1 DefaultControlTag (org.killbill.billing.util.tag.DefaultControlTag)1 DescriptiveTag (org.killbill.billing.util.tag.DescriptiveTag)1 Tag (org.killbill.billing.util.tag.Tag)1