use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestInvoiceDao method testWithFailedPaymentAttempt.
@Test(groups = "slow")
public void testWithFailedPaymentAttempt() throws Exception {
final UUID accountId = account.getId();
final Invoice invoice = new DefaultInvoice(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD);
invoiceUtil.createInvoice(invoice, context);
final UUID bundleId = UUID.randomUUID();
final UUID subscriptionId = UUID.randomUUID();
final RecurringInvoiceItem item1 = new RecurringInvoiceItem(invoice.getId(), accountId, bundleId, subscriptionId, "test product", "test plan", "test ZOO", null, clock.getUTCNow().plusMonths(-1).toLocalDate(), clock.getUTCNow().toLocalDate(), BigDecimal.TEN, BigDecimal.TEN, Currency.USD);
invoiceUtil.createInvoiceItem(item1, context);
final InvoiceModelDao retrievedInvoice = invoiceDao.getById(invoice.getId(), context);
assertEquals(retrievedInvoice.getInvoicePayments().size(), 0);
final UUID paymentId = UUID.randomUUID();
final DefaultInvoicePayment defaultInvoicePayment = new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, paymentId, invoice.getId(), clock.getUTCNow().plusDays(12), BigDecimal.TEN, Currency.USD, Currency.USD, "cookie", false);
invoiceDao.notifyOfPaymentCompletion(new InvoicePaymentModelDao(defaultInvoicePayment), UUID.randomUUID(), context);
final InvoiceModelDao retrievedInvoice1 = invoiceDao.getById(invoice.getId(), context);
assertEquals(retrievedInvoice1.getInvoicePayments().size(), 1);
assertEquals(retrievedInvoice1.getInvoicePayments().get(0).getSuccess(), Boolean.FALSE);
final DefaultInvoicePayment defaultInvoicePayment2 = new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, paymentId, invoice.getId(), clock.getUTCNow().plusDays(12), BigDecimal.TEN, Currency.USD, Currency.USD, "cookie", true);
invoiceDao.notifyOfPaymentCompletion(new InvoicePaymentModelDao(defaultInvoicePayment2), UUID.randomUUID(), context);
final InvoiceModelDao retrievedInvoice2 = invoiceDao.getById(invoice.getId(), context);
assertEquals(retrievedInvoice2.getInvoicePayments().size(), 1);
assertEquals(retrievedInvoice2.getInvoicePayments().get(0).getSuccess(), Boolean.TRUE);
}
use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestInvoiceDao method testGetUnpaidInvoicesByAccountIdWithDraftInvoice.
@Test(groups = "slow")
public void testGetUnpaidInvoicesByAccountIdWithDraftInvoice() throws EntityPersistenceException, InvoiceApiException {
final UUID accountId = account.getId();
final UUID bundleId = UUID.randomUUID();
final LocalDate targetDate1 = new LocalDate(2011, 10, 6);
final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCToday(), targetDate1, Currency.USD);
invoiceUtil.createInvoice(invoice1, context);
final LocalDate startDate = new LocalDate(2011, 3, 1);
final LocalDate endDate = startDate.plusMonths(1);
final BigDecimal rate1 = new BigDecimal("17.0");
final BigDecimal rate2 = new BigDecimal("42.0");
final RecurringInvoiceItem item1 = new RecurringInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test product", "test plan", "test phase A", null, startDate, endDate, rate1, rate1, Currency.USD);
invoiceUtil.createInvoiceItem(item1, context);
final RecurringInvoiceItem item2 = new RecurringInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test product", "test plan", "test phase B", null, startDate, endDate, rate2, rate2, Currency.USD);
invoiceUtil.createInvoiceItem(item2, context);
LocalDate upToDate;
Collection<InvoiceModelDao> invoices;
upToDate = new LocalDate(2011, 1, 1);
invoices = invoiceDao.getUnpaidInvoicesByAccountId(accountId, null, upToDate, context);
assertEquals(invoices.size(), 0);
upToDate = new LocalDate(2012, 1, 1);
invoices = invoiceDao.getUnpaidInvoicesByAccountId(accountId, null, upToDate, context);
assertEquals(invoices.size(), 1);
List<InvoiceModelDao> allInvoicesByAccount = invoiceDao.getInvoicesByAccount(false, new LocalDate(2011, 1, 1), null, context);
assertEquals(allInvoicesByAccount.size(), 1);
// insert DRAFT invoice
createCredit(accountId, new LocalDate(2011, 12, 31), BigDecimal.TEN, true);
allInvoicesByAccount = invoiceDao.getInvoicesByAccount(false, new LocalDate(2011, 1, 1), null, context);
assertEquals(allInvoicesByAccount.size(), 2);
assertEquals(allInvoicesByAccount.get(0).getStatus(), InvoiceStatus.COMMITTED);
assertEquals(allInvoicesByAccount.get(1).getStatus(), InvoiceStatus.DRAFT);
upToDate = new LocalDate(2012, 1, 1);
invoices = invoiceDao.getUnpaidInvoicesByAccountId(accountId, null, upToDate, context);
assertEquals(invoices.size(), 1);
}
use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestInvoiceDao method testGetByInvoiceItemId.
@Test(groups = "slow")
public void testGetByInvoiceItemId() throws EntityPersistenceException, InvoiceApiException {
final Invoice invoice1 = new DefaultInvoice(account.getId(), clock.getUTCToday(), clock.getUTCToday(), Currency.USD);
invoiceUtil.createInvoice(invoice1, context);
final UUID invoiceId1 = invoice1.getId();
LocalDate startDate = new LocalDate(2011, 3, 1);
LocalDate endDate = startDate.plusMonths(1);
final RecurringInvoiceItem recurringItem1 = new RecurringInvoiceItem(invoiceId1, account.getId(), UUID.randomUUID(), UUID.randomUUID(), "test product", "test plan", "test A", null, startDate, endDate, BigDecimal.ONE, BigDecimal.ONE, Currency.USD);
invoiceUtil.createInvoiceItem(recurringItem1, context);
final InvoiceModelDao targetInvoice = invoiceDao.getByInvoiceItem(recurringItem1.getId(), internalCallContext);
assertNotNull(targetInvoice);
assertEquals(targetInvoice.getId(), invoiceId1);
assertEquals(targetInvoice.getInvoiceItems().size(), 1);
assertEquals(targetInvoice.getInvoiceItems().get(0).getId(), recurringItem1.getId());
}
use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestInvoiceDao method testRefundedInvoiceWithInvoiceItemAdjustmentWithRepair.
@Test(groups = "slow")
public void testRefundedInvoiceWithInvoiceItemAdjustmentWithRepair() throws InvoiceApiException, EntityPersistenceException {
final UUID accountId = account.getId();
final UUID subscriptionId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
final LocalDate startDate = new LocalDate(2010, 1, 1);
((ClockMock) clock).setDay(startDate);
final LocalDate recuringStartDate = clock.getUTCNow().plusDays(30).toLocalDate();
final LocalDate recuringEndDate = recuringStartDate.plusMonths(1);
final LocalDate targetDate = recuringStartDate.plusDays(1);
// FIRST CREATE INITIAL INVOICE WITH ONE RECURRING ITEM
final Invoice invoice = new DefaultInvoice(accountId, targetDate, targetDate, Currency.USD);
final UUID invoiceId = invoice.getId();
final InvoiceItem invoiceItem = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, "test product", "test-plan", "test-phase-rec", null, recuringStartDate, recuringEndDate, new BigDecimal("239.00"), new BigDecimal("239.00"), Currency.USD);
invoice.addInvoiceItem(invoiceItem);
invoiceUtil.createInvoice(invoice, context);
((ClockMock) clock).addDays(1);
// SECOND CREATE THE PAYMENT
final BigDecimal paymentAmount = new BigDecimal("239.00");
final UUID paymentId = UUID.randomUUID();
final DefaultInvoicePayment defaultInvoicePayment = new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, paymentId, invoiceId, clock.getUTCNow(), paymentAmount, Currency.USD, Currency.USD, "cookie", true);
invoiceDao.notifyOfPaymentCompletion(new InvoicePaymentModelDao(defaultInvoicePayment), UUID.randomUUID(), context);
// AND THEN THIRD THE REFUND
final Map<UUID, BigDecimal> invoiceItemMap = new HashMap<UUID, BigDecimal>();
invoiceItemMap.put(invoiceItem.getId(), new BigDecimal("239.00"));
invoiceDao.createRefund(paymentId, UUID.randomUUID(), paymentAmount, true, invoiceItemMap, UUID.randomUUID().toString(), true, context);
final InvoiceModelDao savedInvoice = invoiceDao.getById(invoiceId, context);
assertNotNull(savedInvoice);
assertEquals(savedInvoice.getInvoiceItems().size(), 2);
final List<Invoice> invoices = new ArrayList<Invoice>();
invoices.add(new DefaultInvoice(savedInvoice));
// NOW COMPUTE A DIFFERENT ITEM TO TRIGGER REPAIR
final BillingEventSet events = new MockBillingEventSet();
final SubscriptionBase subscription = getZombieSubscription(subscriptionId);
final Product product = Mockito.mock(Product.class);
Mockito.when(product.getName()).thenReturn("product");
final Plan plan = Mockito.mock(Plan.class);
Mockito.when(plan.getName()).thenReturn("plan");
Mockito.when(plan.getProduct()).thenReturn(product);
Mockito.when(plan.getRecurringBillingMode()).thenReturn(BillingMode.IN_ADVANCE);
final PlanPhase phase1 = Mockito.mock(PlanPhase.class);
Mockito.when(phase1.getName()).thenReturn("plan-phase1");
final BillingEvent event1 = invoiceUtil.createMockBillingEvent(null, subscription, recuringStartDate.toDateTimeAtStartOfDay(), plan, phase1, null, TEN, Currency.USD, BillingPeriod.MONTHLY, 31, BillingMode.IN_ADVANCE, "new-event", 1L, SubscriptionBaseTransitionType.CREATE);
events.add(event1);
final InvoiceWithMetadata newInvoiceWithMetadata = generator.generateInvoice(account, events, new AccountInvoices(null, null, invoices), null, targetDate, Currency.USD, null, context);
final Invoice newInvoice = newInvoiceWithMetadata.getInvoice();
invoiceUtil.createInvoice(newInvoice, context);
// VERIFY THAT WE STILL HAVE ONLY 2 ITEMS, MEANING THERE WERE NO REPAIR AND NO CBA GENERATED
final Invoice firstInvoice = new DefaultInvoice(invoiceDao.getById(invoiceId, context));
assertNotNull(firstInvoice);
assertEquals(firstInvoice.getInvoiceItems().size(), 2);
}
use of org.killbill.billing.invoice.model.RecurringInvoiceItem in project killbill by killbill.
the class TestSubscriptionItemTree method testRepairWithFullItemAdjustment.
@Test(groups = "fast")
public void testRepairWithFullItemAdjustment() {
final LocalDate startDate = new LocalDate(2014, 1, 1);
final LocalDate itemAdjDate = new LocalDate(2014, 1, 2);
final LocalDate endDate = new LocalDate(2014, 2, 1);
final LocalDate cancelDate = new LocalDate(2014, 1, 23);
final BigDecimal rate1 = new BigDecimal("12.00");
final BigDecimal amount1 = rate1;
final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
final InvoiceItem originalAdjusted = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, endDate, amount1, rate1, currency);
final InvoiceItem itemAdj = new ItemAdjInvoiceItem(originalAdjusted, itemAdjDate, amount1.negate(), currency);
// Simulate
final InvoiceItem newItem = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, cancelDate, amount1, rate1, currency);
tree.addItem(originalAdjusted);
tree.addItem(itemAdj);
tree.addItem(newItem);
tree.flatten(true);
tree.mergeProposedItem(new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, startDate, cancelDate, amount1, rate1, currency));
tree.buildForMerge();
final List<InvoiceItem> expectedResult = Lists.newLinkedList();
verifyResult(tree.getView(), expectedResult);
}
Aggregations