Search in sources :

Example 11 with InvoiceItems

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);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Invoice(org.killbill.billing.client.model.gen.Invoice) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) InvoiceItems(org.killbill.billing.client.model.InvoiceItems) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 12 with InvoiceItems

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);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) Invoice(org.killbill.billing.client.model.gen.Invoice) InvoiceItems(org.killbill.billing.client.model.InvoiceItems) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 13 with InvoiceItems

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);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) InvoiceItems(org.killbill.billing.client.model.InvoiceItems) Invoices(org.killbill.billing.client.model.Invoices) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

InvoiceItems (org.killbill.billing.client.model.InvoiceItems)13 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)13 Test (org.testng.annotations.Test)13 BigDecimal (java.math.BigDecimal)11 Account (org.killbill.billing.client.model.gen.Account)9 Invoice (org.killbill.billing.client.model.gen.Invoice)7 UUID (java.util.UUID)4 DateTime (org.joda.time.DateTime)2 LocalDate (org.joda.time.LocalDate)2 Invoices (org.killbill.billing.client.model.Invoices)2 KillBillClientException (org.killbill.billing.client.KillBillClientException)1 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)1 InvoicePaymentTransaction (org.killbill.billing.client.model.gen.InvoicePaymentTransaction)1 Payment (org.killbill.billing.client.model.gen.Payment)1