use of org.killbill.billing.invoice.model.ExternalChargeInvoiceItem in project killbill by killbill.
the class TestWithTaxItems method testUpdateTaxItems.
@Test(groups = "slow")
public void testUpdateTaxItems() throws Exception {
clock.setDay(new LocalDate(2012, 4, 1));
final AccountData accountData = getAccountData(1);
final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
// Create original subscription (Trial PHASE) -> $0 invoice.
final DefaultEntitlement bpSubscription = createBaseEntitlementAndCheckForCompletion(account.getId(), "bundleKey", "Pistol", ProductCategory.BASE, BillingPeriod.MONTHLY, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
invoiceChecker.checkInvoice(account.getId(), 1, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 4, 1), null, InvoiceItemType.FIXED, new BigDecimal("0")));
subscriptionChecker.checkSubscriptionCreated(bpSubscription.getId(), internalCallContext);
// Add tags to keep DRAFT invoices and reuse them
add_AUTO_INVOICING_DRAFT_Tag(account.getId(), ObjectType.ACCOUNT);
add_AUTO_INVOICING_REUSE_DRAFT_Tag(account.getId(), ObjectType.ACCOUNT);
// Make sure TestInvoicePluginApi will return an additional TAX item
final UUID invoiceTaxItemId = UUID.randomUUID();
testInvoicePluginApi.addTaxItem(new TaxInvoiceItem(invoiceTaxItemId, null, account.getId(), null, "Tax Item", new LocalDate(2012, 4, 1), BigDecimal.ONE, account.getCurrency()));
// Insert external charge autoCommit = false => Invoice will be in DRAFT
invoiceUserApi.insertExternalCharges(account.getId(), clock.getUTCNow().toLocalDate(), ImmutableList.<InvoiceItem>of(new ExternalChargeInvoiceItem(null, account.getId(), null, "foo", new LocalDate(2012, 4, 1), null, new BigDecimal("33.80"), account.getCurrency(), null)), false, null, callContext);
// Make sure TestInvoicePluginApi **update** the original TAX item
testInvoicePluginApi.addTaxItem(new TaxInvoiceItem(invoiceTaxItemId, null, account.getId(), null, "Tax Item", new LocalDate(2012, 4, 1), new BigDecimal("12.45"), account.getCurrency()));
// Move to Evergreen PHASE, but invoice remains in DRAFT mode
busHandler.pushExpectedEvents(NextEvent.PHASE);
clock.addDays(30);
assertListenerStatus();
final List<Invoice> accountInvoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, false, callContext);
assertEquals(accountInvoices.size(), 2);
// Commit invoice
busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
invoiceUserApi.commitInvoice(accountInvoices.get(1).getId(), callContext);
assertListenerStatus();
invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 4, 1), null, InvoiceItemType.EXTERNAL_CHARGE, new BigDecimal("33.80")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 6, 1), InvoiceItemType.RECURRING, new BigDecimal("29.95")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 4, 1), null, InvoiceItemType.TAX, new BigDecimal("12.45")));
}
use of org.killbill.billing.invoice.model.ExternalChargeInvoiceItem in project killbill by killbill.
the class TestInvoiceDao method testExternalChargeWithCBA.
@Test(groups = "slow")
public void testExternalChargeWithCBA() throws InvoiceApiException, EntityPersistenceException {
final UUID accountId = account.getId();
final UUID bundleId = UUID.randomUUID();
final InvoiceItemModelDao credit = createCredit(accountId, clock.getUTCToday(), new BigDecimal("20.0"), true);
final String description = UUID.randomUUID().toString();
final InvoiceModelDao invoiceForExternalCharge = new InvoiceModelDao(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD, false);
final InvoiceItemModelDao externalCharge = new InvoiceItemModelDao(new ExternalChargeInvoiceItem(invoiceForExternalCharge.getId(), accountId, bundleId, description, clock.getUTCToday(), clock.getUTCToday(), new BigDecimal("15.0"), Currency.USD, null));
invoiceForExternalCharge.addInvoiceItem(externalCharge);
final InvoiceItemModelDao charge = invoiceDao.createInvoices(ImmutableList.<InvoiceModelDao>of(invoiceForExternalCharge), null, ImmutableSet.of(), context).get(0);
InvoiceModelDao newInvoice = invoiceDao.getById(charge.getInvoiceId(), context);
List<InvoiceItemModelDao> items = newInvoice.getInvoiceItems();
// No CBA consumed yet since the credit was created on a DRAFT invoice
assertEquals(items.size(), 1);
assertEquals(items.get(0).getType(), InvoiceItemType.EXTERNAL_CHARGE);
assertEquals(items.get(0).getDescription(), description);
invoiceDao.changeInvoiceStatus(credit.getInvoiceId(), InvoiceStatus.COMMITTED, context);
// CBA should have been consumed
newInvoice = invoiceDao.getById(charge.getInvoiceId(), context);
items = newInvoice.getInvoiceItems();
assertEquals(items.size(), 2);
for (final InvoiceItemModelDao cur : items) {
if (cur.getId().equals(charge.getId())) {
assertEquals(cur.getType(), InvoiceItemType.EXTERNAL_CHARGE);
assertEquals(cur.getDescription(), description);
} else {
assertEquals(cur.getType(), InvoiceItemType.CBA_ADJ);
assertTrue(cur.getAmount().compareTo(new BigDecimal("-15.00")) == 0);
}
}
}
use of org.killbill.billing.invoice.model.ExternalChargeInvoiceItem in project killbill by killbill.
the class TestDefaultInvoiceUserApi method testPostExternalChargeForBundleOnNewInvoice.
@Test(groups = "slow")
public void testPostExternalChargeForBundleOnNewInvoice() throws Exception {
final Account account = invoiceUtil.createAccount(callContext);
final UUID accountId = account.getId();
final UUID invoiceId = invoiceUtil.generateRegularInvoice(account, null, callContext);
// Initial account balance
final BigDecimal accountBalance = invoiceUserApi.getAccountBalance(accountId, callContext);
// Post an external charge
final BigDecimal externalChargeAmount = BigDecimal.TEN;
final UUID bundleId = UUID.randomUUID();
final InvoiceItem externalCharge = new ExternalChargeInvoiceItem(null, accountId, bundleId, UUID.randomUUID().toString(), clock.getUTCToday(), clock.getUTCToday(), externalChargeAmount, accountCurrency, null);
final InvoiceItem externalChargeInvoiceItem = invoiceUserApi.insertExternalCharges(accountId, clock.getUTCToday(), ImmutableList.<InvoiceItem>of(externalCharge), true, null, callContext).get(0);
verifyExternalChargeOnNewInvoice(accountId, invoiceId, accountBalance, bundleId, externalChargeAmount, externalChargeInvoiceItem);
}
use of org.killbill.billing.invoice.model.ExternalChargeInvoiceItem in project killbill by killbill.
the class TestDefaultInvoiceUserApi method testVoidInvoiceWithUsedCredits.
@Test(groups = "slow")
public void testVoidInvoiceWithUsedCredits() throws Exception {
final Account account = invoiceUtil.createAccount(callContext);
final UUID accountId = account.getId();
final InvoiceItem creditItem = new CreditAdjInvoiceItem(null, accountId, clock.getUTCToday(), "something", new BigDecimal("200.00"), accountCurrency, null);
invoiceUserApi.insertCredits(accountId, clock.getUTCToday(), ImmutableList.of(creditItem), true, null, callContext);
final InvoiceItem externalCharge1 = new ExternalChargeInvoiceItem(null, accountId, null, "description", clock.getUTCToday(), clock.getUTCToday(), new BigDecimal("100.00"), accountCurrency, null);
final List<InvoiceItem> items1 = invoiceUserApi.insertExternalCharges(accountId, clock.getUTCToday(), ImmutableList.<InvoiceItem>of(externalCharge1), true, null, callContext);
assertEquals(items1.size(), 1);
final Invoice invoice1 = invoiceUserApi.getInvoice(items1.get(0).getInvoiceId(), callContext);
final InvoiceItem externalCharge2 = new ExternalChargeInvoiceItem(null, accountId, null, "description", clock.getUTCToday(), clock.getUTCToday(), new BigDecimal("50.00"), accountCurrency, null);
final List<InvoiceItem> items2 = invoiceUserApi.insertExternalCharges(accountId, clock.getUTCToday(), ImmutableList.<InvoiceItem>of(externalCharge2), true, null, callContext);
assertEquals(items2.size(), 1);
final Invoice invoice2 = invoiceUserApi.getInvoice(items2.get(0).getInvoiceId(), callContext);
final BigDecimal accountBalance = invoiceUserApi.getAccountBalance(accountId, callContext);
final BigDecimal accountCBA = invoiceUserApi.getAccountCBA(accountId, callContext);
Assert.assertEquals(accountBalance.compareTo(new BigDecimal("-50")), 0);
Assert.assertEquals(accountCBA.compareTo(new BigDecimal("50")), 0);
invoiceUserApi.voidInvoice(invoice1.getId(), callContext);
// We verify that credit *used* on invoice1 is reclaimed, i.e the system ignores it as the invoice was voided.
final BigDecimal accountBalance2 = invoiceUserApi.getAccountBalance(accountId, callContext);
final BigDecimal accountCBA2 = invoiceUserApi.getAccountCBA(accountId, callContext);
Assert.assertEquals(accountBalance2.compareTo(new BigDecimal("-150")), 0);
Assert.assertEquals(accountCBA2.compareTo(new BigDecimal("150")), 0);
}
use of org.killbill.billing.invoice.model.ExternalChargeInvoiceItem in project killbill by killbill.
the class TestDefaultInvoiceUserApi method testOriginalAmountCharged.
@Test(groups = "slow")
public void testOriginalAmountCharged() throws Exception {
final Account account = invoiceUtil.createAccount(callContext);
final UUID accountId = account.getId();
final UUID invoiceId = invoiceUtil.generateRegularInvoice(account, null, callContext);
// Post an external charge
final BigDecimal externalChargeAmount = BigDecimal.TEN;
final InvoiceItem externalCharge = new ExternalChargeInvoiceItem(null, accountId, null, UUID.randomUUID().toString(), clock.getUTCToday(), null, externalChargeAmount, accountCurrency, null);
final InvoiceItem externalChargeInvoiceItem = invoiceUserApi.insertExternalCharges(accountId, clock.getUTCToday(), ImmutableList.<InvoiceItem>of(externalCharge), true, null, callContext).get(0);
final Invoice newInvoice = invoiceUserApi.getInvoice(externalChargeInvoiceItem.getInvoiceId(), callContext);
final BigDecimal newAmountCharged = newInvoice.getChargedAmount();
Assert.assertEquals(newInvoice.getOriginalChargedAmount().compareTo(externalChargeAmount), 0);
Assert.assertEquals(newAmountCharged.compareTo(externalChargeAmount), 0);
}
Aggregations