use of org.killbill.billing.client.model.InvoiceItems in project killbill by killbill.
the class TestInvoice method testInvoiceMigration.
@Test(groups = "slow", description = "Can create a migration invoice")
public void testInvoiceMigration() throws Exception {
final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
// Get the invoices
final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, true, false, false, null, AuditLevel.NONE, requestOptions);
assertEquals(invoices.size(), 2);
// Migrate an invoice with one external charge
final BigDecimal chargeAmount = BigDecimal.TEN;
final InvoiceItem externalCharge = new InvoiceItem();
externalCharge.setStartDate(new LocalDate());
externalCharge.setAccountId(accountJson.getAccountId());
externalCharge.setAmount(chargeAmount);
externalCharge.setItemType(InvoiceItemType.EXTERNAL_CHARGE);
externalCharge.setCurrency(accountJson.getCurrency());
final InvoiceItems inputInvoice = new InvoiceItems();
inputInvoice.add(externalCharge);
final Account accountWithBalance = accountApi.getAccount(accountJson.getAccountId(), true, true, AuditLevel.NONE, requestOptions);
final Multimap<String, String> queryFollowParams = HashMultimap.<String, String>create(requestOptions.getQueryParamsForFollow());
queryFollowParams.put(JaxrsResource.QUERY_INVOICE_WITH_ITEMS, "true");
final Invoice migrationInvoice = invoiceApi.createMigrationInvoice(accountJson.getAccountId(), inputInvoice, null, requestOptions.extend().withQueryParamsForFollow(queryFollowParams).build());
assertEquals(migrationInvoice.getBalance(), BigDecimal.ZERO);
assertEquals(migrationInvoice.getItems().size(), 1);
assertEquals(migrationInvoice.getItems().get(0).getAmount().compareTo(chargeAmount), 0);
assertEquals(migrationInvoice.getItems().get(0).getCurrency(), accountJson.getCurrency());
final List<Invoice> invoicesWithMigration = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, true, false, false, null, AuditLevel.NONE, requestOptions);
assertEquals(invoicesWithMigration.size(), 3);
final Account accountWithBalanceAfterMigration = accountApi.getAccount(accountJson.getAccountId(), true, true, AuditLevel.NONE, requestOptions);
assertEquals(accountWithBalanceAfterMigration.getAccountBalance().compareTo(accountWithBalance.getAccountBalance()), 0);
}
use of org.killbill.billing.client.model.InvoiceItems in project killbill by killbill.
the class TestInvoice method testExternalChargeForBundleOnNewInvoice.
@Test(groups = "slow", description = "Can create an external charge for a bundle")
public void testExternalChargeForBundleOnNewInvoice() throws Exception {
final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
// Get the invoices
assertEquals(accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions).size(), 2);
// Post an external charge
final BigDecimal chargeAmount = BigDecimal.TEN;
final UUID bundleId = UUID.randomUUID();
final InvoiceItem externalCharge = new InvoiceItem();
externalCharge.setAccountId(accountJson.getAccountId());
externalCharge.setAmount(chargeAmount);
externalCharge.setCurrency(accountJson.getCurrency());
externalCharge.setBundleId(bundleId);
final InvoiceItems input = new InvoiceItems();
input.add(externalCharge);
final List<InvoiceItem> createdExternalCharges = invoiceApi.createExternalCharges(accountJson.getAccountId(), input, clock.getUTCToday(), true, NULL_PLUGIN_PROPERTIES, requestOptions);
assertEquals(createdExternalCharges.size(), 1);
final Invoice invoiceWithItems = invoiceApi.getInvoice(createdExternalCharges.get(0).getInvoiceId(), null, AuditLevel.NONE, requestOptions);
assertEquals(invoiceWithItems.getBalance().compareTo(chargeAmount), 0);
assertEquals(invoiceWithItems.getItems().size(), 1);
assertEquals(invoiceWithItems.getItems().get(0).getBundleId(), bundleId);
// Verify the total number of invoices
assertEquals(accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions).size(), 3);
}
use of org.killbill.billing.client.model.InvoiceItems in project killbill by killbill.
the class TestInvoice method testInvoiceTransferCreditToParentAccount.
@Test(groups = "slow", description = "Can transfer credit to parent account")
public void testInvoiceTransferCreditToParentAccount() throws Exception {
final Account parentAccount = createAccount();
final Account childAccount = createAccount(parentAccount.getAccountId());
final BigDecimal creditAmount = BigDecimal.TEN;
final InvoiceItem credit = new InvoiceItem();
credit.setAccountId(childAccount.getAccountId());
credit.setInvoiceId(null);
credit.setAmount(creditAmount);
// insert credit to child account
InvoiceItems credits = new InvoiceItems();
credits.add(credit);
final List<InvoiceItem> creditJsons = creditApi.createCredits(credits, true, NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.assertEquals(creditJsons.size(), 1);
Invoices childInvoices = accountApi.getInvoicesForAccount(childAccount.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
Assert.assertEquals(childInvoices.size(), 1);
Assert.assertEquals(childInvoices.get(0).getCreditAdj().compareTo(BigDecimal.TEN), 0);
Invoices parentInvoices = accountApi.getInvoicesForAccount(parentAccount.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
Assert.assertEquals(parentInvoices.size(), 0);
// transfer credit to parent account
accountApi.transferChildCreditToParent(childAccount.getAccountId(), requestOptions);
childInvoices = accountApi.getInvoicesForAccount(childAccount.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
Assert.assertEquals(childInvoices.size(), 2);
Assert.assertEquals(childInvoices.get(1).getCreditAdj().compareTo(BigDecimal.TEN.negate()), 0);
parentInvoices = accountApi.getInvoicesForAccount(parentAccount.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
Assert.assertEquals(parentInvoices.size(), 1);
Assert.assertEquals(parentInvoices.get(0).getCreditAdj().compareTo(BigDecimal.TEN), 0);
}
Aggregations