Search in sources :

Example 6 with InvoiceWithMetadata

use of org.killbill.billing.invoice.generator.InvoiceWithMetadata in project killbill by killbill.

the class TestInvoiceDao method testInvoiceForFreeTrialWithRecurringDiscount.

@Test(groups = "slow")
public void testInvoiceForFreeTrialWithRecurringDiscount() throws InvoiceApiException, CatalogApiException {
    final Currency currency = Currency.USD;
    final DefaultPrice zeroPrice = new DefaultPrice(BigDecimal.ZERO, Currency.USD);
    final MockInternationalPrice fixedPrice = new MockInternationalPrice(zeroPrice);
    final MockPlanPhase phase1 = new MockPlanPhase(null, fixedPrice);
    final BigDecimal cheapAmount = new BigDecimal("24.95");
    final DefaultPrice cheapPrice = new DefaultPrice(cheapAmount, Currency.USD);
    final MockInternationalPrice recurringPrice = new MockInternationalPrice(cheapPrice);
    final MockPlanPhase phase2 = new MockPlanPhase(recurringPrice, null);
    final MockPlan plan = new MockPlan();
    final SubscriptionBase subscription = getZombieSubscription();
    final DateTime effectiveDate1 = invoiceUtil.buildDate(2011, 1, 1).toDateTimeAtStartOfDay();
    final BillingEvent event1 = invoiceUtil.createMockBillingEvent(null, subscription, effectiveDate1, plan, phase1, fixedPrice.getPrice(currency), null, currency, BillingPeriod.MONTHLY, 1, BillingMode.IN_ADVANCE, "testEvent1", 1L, SubscriptionBaseTransitionType.CREATE);
    final BillingEventSet events = new MockBillingEventSet();
    events.add(event1);
    final UUID accountId = account.getId();
    final InvoiceWithMetadata invoiceWithMetadata1 = generator.generateInvoice(account, events, null, new LocalDate(effectiveDate1), Currency.USD, context);
    final Invoice invoice1 = invoiceWithMetadata1.getInvoice();
    assertNotNull(invoice1);
    assertEquals(invoice1.getNumberOfItems(), 1);
    assertEquals(invoice1.getBalance().compareTo(ZERO), 0);
    final List<Invoice> invoiceList = new ArrayList<Invoice>();
    invoiceList.add(invoice1);
    //invoiceUtil.createInvoice(invoice1, invoice1.getTargetDate().getDayOfMonth(), callcontext);
    final DateTime effectiveDate2 = effectiveDate1.plusDays(30);
    final BillingEvent event2 = invoiceUtil.createMockBillingEvent(null, subscription, effectiveDate2, plan, phase2, null, recurringPrice.getPrice(currency), currency, BillingPeriod.MONTHLY, 31, BillingMode.IN_ADVANCE, "testEvent2", 2L, SubscriptionBaseTransitionType.PHASE);
    events.add(event2);
    final InvoiceWithMetadata invoiceWithMetadata2 = generator.generateInvoice(account, events, invoiceList, new LocalDate(effectiveDate2), Currency.USD, context);
    final Invoice invoice2 = invoiceWithMetadata2.getInvoice();
    assertNotNull(invoice2);
    assertEquals(invoice2.getNumberOfItems(), 1);
    assertEquals(invoice2.getBalance().compareTo(cheapAmount), 0);
    invoiceList.add(invoice2);
    //invoiceUtil.createInvoice(invoice2, invoice2.getTargetDate().getDayOfMonth(), callcontext);
    final DateTime effectiveDate3 = effectiveDate2.plusMonths(1);
    final InvoiceWithMetadata invoiceWithMetadata3 = generator.generateInvoice(account, events, invoiceList, new LocalDate(effectiveDate3), Currency.USD, context);
    final Invoice invoice3 = invoiceWithMetadata3.getInvoice();
    assertNotNull(invoice3);
    assertEquals(invoice3.getNumberOfItems(), 1);
    assertEquals(invoice3.getBalance().compareTo(cheapAmount), 0);
//invoiceUtil.createInvoice(invoice3, invoice3.getTargetDate().getDayOfMonth(), callcontext);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) ArrayList(java.util.ArrayList) InvoiceWithMetadata(org.killbill.billing.invoice.generator.InvoiceWithMetadata) LocalDate(org.joda.time.LocalDate) MockInternationalPrice(org.killbill.billing.catalog.MockInternationalPrice) BigDecimal(java.math.BigDecimal) DateTime(org.joda.time.DateTime) SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) MockPlan(org.killbill.billing.catalog.MockPlan) MockPlanPhase(org.killbill.billing.catalog.MockPlanPhase) Currency(org.killbill.billing.catalog.api.Currency) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) BillingEventSet(org.killbill.billing.junction.BillingEventSet) BillingEvent(org.killbill.billing.junction.BillingEvent) DefaultPrice(org.killbill.billing.catalog.DefaultPrice) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 7 with InvoiceWithMetadata

use of org.killbill.billing.invoice.generator.InvoiceWithMetadata in project killbill by killbill.

the class TestInvoiceDao method testMixedModeInvoicePersistence.

@Test(groups = "slow")
public void testMixedModeInvoicePersistence() throws InvoiceApiException, CatalogApiException, EntityPersistenceException {
    final Currency currency = Currency.USD;
    final DefaultPrice zeroPrice = new DefaultPrice(BigDecimal.ZERO, Currency.USD);
    final MockInternationalPrice fixedPrice = new MockInternationalPrice(zeroPrice);
    final MockPlanPhase phase1 = new MockPlanPhase(null, fixedPrice);
    final BigDecimal cheapAmount = new BigDecimal("24.95");
    final DefaultPrice cheapPrice = new DefaultPrice(cheapAmount, Currency.USD);
    final MockInternationalPrice recurringPrice = new MockInternationalPrice(cheapPrice);
    final MockPlanPhase phase2 = new MockPlanPhase(recurringPrice, null);
    final MockPlan plan = new MockPlan();
    final SubscriptionBase subscription = getZombieSubscription();
    final DateTime effectiveDate1 = invoiceUtil.buildDate(2011, 1, 1).toDateTimeAtStartOfDay();
    final BillingEvent event1 = invoiceUtil.createMockBillingEvent(null, subscription, effectiveDate1, plan, phase1, fixedPrice.getPrice(currency), null, currency, BillingPeriod.MONTHLY, 1, BillingMode.IN_ADVANCE, "testEvent1", 1L, SubscriptionBaseTransitionType.CREATE);
    final BillingEventSet events = new MockBillingEventSet();
    events.add(event1);
    final DateTime effectiveDate2 = effectiveDate1.plusDays(30);
    final BillingEvent event2 = invoiceUtil.createMockBillingEvent(null, subscription, effectiveDate2, plan, phase2, null, recurringPrice.getPrice(currency), currency, BillingPeriod.MONTHLY, 31, BillingMode.IN_ADVANCE, "testEvent2", 2L, SubscriptionBaseTransitionType.CHANGE);
    events.add(event2);
    final InvoiceWithMetadata invoiceWithMetadata = generator.generateInvoice(account, events, null, new LocalDate(effectiveDate2), Currency.USD, context);
    final Invoice invoice = invoiceWithMetadata.getInvoice();
    assertNotNull(invoice);
    assertEquals(invoice.getNumberOfItems(), 2);
    assertEquals(invoice.getBalance().compareTo(cheapAmount), 0);
    invoiceUtil.createInvoice(invoice, context);
    final InvoiceModelDao savedInvoice = invoiceDao.getById(invoice.getId(), context);
    assertNotNull(savedInvoice);
    assertEquals(savedInvoice.getInvoiceItems().size(), 2);
    assertEquals(InvoiceModelDaoHelper.getBalance(savedInvoice).compareTo(cheapAmount), 0);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) InvoiceWithMetadata(org.killbill.billing.invoice.generator.InvoiceWithMetadata) LocalDate(org.joda.time.LocalDate) MockInternationalPrice(org.killbill.billing.catalog.MockInternationalPrice) BigDecimal(java.math.BigDecimal) DateTime(org.joda.time.DateTime) SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) MockPlan(org.killbill.billing.catalog.MockPlan) MockPlanPhase(org.killbill.billing.catalog.MockPlanPhase) Currency(org.killbill.billing.catalog.api.Currency) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) BillingEventSet(org.killbill.billing.junction.BillingEventSet) BillingEvent(org.killbill.billing.junction.BillingEvent) DefaultPrice(org.killbill.billing.catalog.DefaultPrice) Test(org.testng.annotations.Test)

Example 8 with InvoiceWithMetadata

use of org.killbill.billing.invoice.generator.InvoiceWithMetadata in project killbill by killbill.

the class TestInvoiceDao method testInvoiceForEmptyEventSet.

@Test(groups = "slow")
public void testInvoiceForEmptyEventSet() throws InvoiceApiException {
    final BillingEventSet events = new MockBillingEventSet();
    final InvoiceWithMetadata invoiceWithMetadata = generator.generateInvoice(account, events, null, new LocalDate(), Currency.USD, context);
    final Invoice invoice = invoiceWithMetadata.getInvoice();
    assertNull(invoice);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) DefaultInvoice(org.killbill.billing.invoice.model.DefaultInvoice) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) MockBillingEventSet(org.killbill.billing.invoice.MockBillingEventSet) BillingEventSet(org.killbill.billing.junction.BillingEventSet) InvoiceWithMetadata(org.killbill.billing.invoice.generator.InvoiceWithMetadata) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Aggregations

Invoice (org.killbill.billing.invoice.api.Invoice)8 InvoiceWithMetadata (org.killbill.billing.invoice.generator.InvoiceWithMetadata)8 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)8 LocalDate (org.joda.time.LocalDate)7 MockBillingEventSet (org.killbill.billing.invoice.MockBillingEventSet)7 BillingEventSet (org.killbill.billing.junction.BillingEventSet)7 Test (org.testng.annotations.Test)7 MockPlan (org.killbill.billing.catalog.MockPlan)6 MockPlanPhase (org.killbill.billing.catalog.MockPlanPhase)6 Currency (org.killbill.billing.catalog.api.Currency)6 BillingEvent (org.killbill.billing.junction.BillingEvent)6 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)6 DateTime (org.joda.time.DateTime)5 ArrayList (java.util.ArrayList)4 UUID (java.util.UUID)4 DefaultPrice (org.killbill.billing.catalog.DefaultPrice)4 MockInternationalPrice (org.killbill.billing.catalog.MockInternationalPrice)4 BigDecimal (java.math.BigDecimal)3 Plan (org.killbill.billing.catalog.api.Plan)2 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)2