Search in sources :

Example 96 with Account

use of org.killbill.billing.client.model.gen.Account 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 97 with Account

use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.

the class TestInvoice method testGetInvoicesWithFilters.

@Test(groups = "slow")
public void testGetInvoicesWithFilters() throws Exception {
    final DateTime initialDate = new DateTime(2021, 4, 18, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    Invoices invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.FULL, requestOptions);
    assertEquals(invoices.size(), 2);
    final String invoiceId1 = invoices.get(0).getInvoiceId().toString();
    final String invoiceId2 = invoices.get(1).getInvoiceId().toString();
    // Filter on dates only
    invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), new LocalDate(2021, 4, 18), new LocalDate(2021, 5, 18), false, false, false, null, AuditLevel.FULL, requestOptions);
    assertEquals(invoices.size(), 2);
    invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), new LocalDate(2021, 4, 18), new LocalDate(2021, 5, 17), false, false, false, null, AuditLevel.FULL, requestOptions);
    assertEquals(invoices.size(), 1);
    invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), new LocalDate(2021, 4, 19), new LocalDate(2021, 5, 18), false, false, false, null, AuditLevel.FULL, requestOptions);
    assertEquals(invoices.size(), 1);
    invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), new LocalDate(2021, 4, 19), new LocalDate(2021, 5, 17), false, false, false, null, AuditLevel.FULL, requestOptions);
    assertEquals(invoices.size(), 0);
    invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), new LocalDate(2021, 4, 19), new LocalDate(2021, 5, 17), false, false, false, null, AuditLevel.FULL, requestOptions);
    assertEquals(invoices.size(), 0);
    // Filter on invoiceIds only
    String idFilter = Strings.join(",", new String[] { invoiceId1, invoiceId2 });
    invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, idFilter, AuditLevel.FULL, requestOptions);
    assertEquals(invoices.size(), 2);
    idFilter = invoiceId1;
    invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, idFilter, AuditLevel.FULL, requestOptions);
    assertEquals(invoices.size(), 1);
    // Dates and id filter
    idFilter = Strings.join(",", new String[] { invoiceId1, invoiceId2 });
    invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), new LocalDate(2021, 4, 18), new LocalDate(2021, 5, 17), false, false, false, idFilter, AuditLevel.FULL, requestOptions);
    assertEquals(invoices.size(), 1);
    idFilter = invoiceId1;
    invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), new LocalDate(2021, 4, 18), new LocalDate(2021, 5, 17), false, false, false, idFilter, AuditLevel.FULL, requestOptions);
    assertEquals(invoices.size(), 1);
    idFilter = invoiceId2;
    invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), new LocalDate(2021, 4, 18), new LocalDate(2021, 5, 17), false, false, false, idFilter, AuditLevel.FULL, requestOptions);
    assertEquals(invoices.size(), 0);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Invoices(org.killbill.billing.client.model.Invoices) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 98 with Account

use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.

the class TestInvoice method testInvoiceCreatePayment.

@Test(groups = "slow", description = "Can create an insta-payment")
public void testInvoiceCreatePayment() throws Exception {
    clock.setTime(new DateTime(2012, 4, 25, 0, 3, 42, 0));
    // STEPH MISSING SET ACCOUNT AUTO_PAY_OFF
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // Get the invoices
    final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
    assertEquals(invoices.size(), 2);
    for (final Invoice cur : invoices) {
        if (cur.getBalance().compareTo(BigDecimal.ZERO) <= 0) {
            continue;
        }
        // CREATE PAYMENT
        final InvoicePayment invoicePayment = new InvoicePayment();
        invoicePayment.setPurchasedAmount(cur.getBalance());
        invoicePayment.setAccountId(accountJson.getAccountId());
        invoicePayment.setTargetInvoiceId(cur.getInvoiceId());
        final InvoicePayment objFromJson = invoiceApi.createInstantPayment(cur.getInvoiceId(), invoicePayment, true, ImmutableList.of(), null, requestOptions);
        assertEquals(cur.getBalance().compareTo(objFromJson.getPurchasedAmount()), 0);
    }
}
Also used : Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Invoice(org.killbill.billing.client.model.gen.Invoice) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 99 with Account

use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.

the class TestInvoice method testInvoiceOk.

@Test(groups = "slow", description = "Can search and retrieve invoices with and without items")
public void testInvoiceOk() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    final Invoices invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.FULL, requestOptions);
    assertEquals(invoices.size(), 2);
    for (final Invoice invoiceJson : invoices) {
        Assert.assertEquals(invoiceJson.getAuditLogs().size(), 1);
        final AuditLog auditLogJson = invoiceJson.getAuditLogs().get(0);
        Assert.assertEquals(auditLogJson.getChangeType(), "INSERT");
        Assert.assertEquals(auditLogJson.getChangedBy(), "SubscriptionBaseTransition");
        Assert.assertFalse(auditLogJson.getChangeDate().isBefore(initialDate));
        Assert.assertNotNull(auditLogJson.getUserToken());
        Assert.assertNull(auditLogJson.getReasonCode());
        Assert.assertNull(auditLogJson.getComments());
    }
    final Invoice invoiceJson = invoices.get(0);
    assertEquals(invoiceJson.getItems().size(), 1);
    final InvoiceItem invoiceItem = invoiceJson.getItems().get(0);
    assertEquals(invoiceItem.getProductName(), "Shotgun");
    assertEquals(invoiceItem.getPrettyProductName(), "Shotgun");
    assertEquals(invoiceItem.getPlanName(), "shotgun-monthly");
    assertEquals(invoiceItem.getPrettyPlanName(), "Shotgun Monthly");
    assertEquals(invoiceItem.getPhaseName(), "shotgun-monthly-trial");
    assertEquals(invoiceItem.getPrettyPhaseName(), "shotgun-monthly-trial");
    // Check item is correctly returned with catalog effective date
    assertEquals(invoiceItem.getCatalogEffectiveDate().compareTo(ISODateTimeFormat.dateTimeParser().parseDateTime("2011-01-01T00:00:00+00:00")), 0);
    assertEquals(invoiceApi.getInvoice(invoiceJson.getInvoiceId(), Boolean.TRUE, AuditLevel.NONE, requestOptions).getItems().size(), invoiceJson.getItems().size());
    assertEquals(invoiceApi.getInvoiceByNumber(Integer.valueOf(invoiceJson.getInvoiceNumber()), Boolean.FALSE, AuditLevel.NONE, requestOptions).getItems().size(), invoiceJson.getItems().size());
    assertEquals(invoiceApi.getInvoiceByItemId(invoiceItem.getInvoiceItemId(), false, AuditLevel.NONE, requestOptions).getItems().size(), invoiceJson.getItems().size());
    // Check we can retrieve an individual invoice
    final Invoice firstInvoice = invoiceApi.getInvoice(invoiceJson.getInvoiceId(), false, AuditLevel.FULL, requestOptions);
    assertEquals(firstInvoice, invoiceJson);
    // Check we can retrieve the invoice by number
    final Invoice firstInvoiceByNumberJson = invoiceApi.getInvoiceByNumber(Integer.valueOf(invoiceJson.getInvoiceNumber()), false, AuditLevel.FULL, requestOptions);
    assertEquals(firstInvoiceByNumberJson, invoiceJson);
    // Check we can retrieve the HTML version
    final String htmlInvoice = invoiceApi.getInvoiceAsHTML(invoiceJson.getInvoiceId(), requestOptions);
    // Disabled this test as different output is produced by Java 8 and Java 11.
    // assertEquals(htmlInvoice,"<!doctype html>\r\n" +
    // "<html>\r\n" +
    // "<head>\r\n" +
    // "    <meta charset=\"utf-8\">\r\n" +
    // "    <title>invoiceTitle</title>\r\n" +
    // "    <style>\r\n" +
    // "        /*!\r\n" +
    // "         * https://www.sparksuite.com/open-source/invoice.html\r\n" +
    // "         * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)\r\n" +
    // "         */\r\n" +
    // "        .invoice-box{max-width:800px;margin:auto;padding:30px;border:1px solid #eee;box-shadow:0 0 10px rgba(0,0,0,.15);font-size:16px;line-height:24px;font-family:'Helvetica Neue',Helvetica,Helvetica,Arial,sans-serif;color:#555}.invoice-box table{width:100%;line-height:inherit;text-align:left}.invoice-box table td{padding:5px;vertical-align:top}.invoice-box table tr td:nth-child(3){text-align:right}.invoice-box table tr.top table td{padding-bottom:20px}.invoice-box table tr.top table td.title{font-size:45px;line-height:45px;color:#333}.invoice-box table tr.information table td{padding-bottom:40px}.invoice-box table tr.heading td{background:#eee;border-bottom:1px solid #ddd;font-weight:700}.invoice-box table tr.details td{padding-bottom:20px}.invoice-box table tr.item td{border-bottom:1px solid #eee}.invoice-box table tr.item.last td{border-bottom:none}.invoice-box table tr.total td:nth-child(3){border-top:2px solid #eee;font-weight:700}@media only screen and (max-width:600px){.invoice-box table tr.top table td{width:100%;display:block;text-align:center}.invoice-box table tr.information table td{width:100%;display:block;text-align:center}}.rtl{direction:rtl;font-family:Tahoma,'Helvetica Neue',Helvetica,Helvetica,Arial,sans-serif}.rtl table{text-align:right}.rtl table tr td:nth-child(3){text-align:left}\r\n" +
    // "    </style>\r\n" +
    // "</head>\r\n" +
    // "<body>\r\n" +
    // "<div class=\"invoice-box\">\r\n" +
    // "    <table cellpadding=\"0\" cellspacing=\"0\">\r\n" +
    // "        <tr class=\"top\">\r\n" +
    // "            <td colspan=\"3\">\r\n" +
    // "                <table>\r\n" +
    // "                    <tr>\r\n" +
    // "                        <td class=\"title\">\r\n" +
    // "                            <img src=\"https://raw.githubusercontent.com/killbill/killbill-docs/v3/userguide/assets/img/logo.png\" style=\"width:100%; max-width:300px;\">\r\n" +
    // "                        </td>\r\n" +
    // "                        <td></td>\r\n" +
    // "                        <td>\r\n" +
    // "                            invoiceTitle INV#"+invoiceJson.getInvoiceNumber()+"<br>\r\n" +
    // "                            invoiceDate25 avr. 2012\r\n" +
    // "                        </td>\r\n" +
    // "                    </tr>\r\n" +
    // "                </table>\r\n" +
    // "            </td>\r\n" +
    // "        </tr>\r\n" +
    // "        <tr class=\"information\">\r\n" +
    // "            <td colspan=\"3\">\r\n" +
    // "                <table>\r\n" +
    // "                    <tr>\r\n" +
    // "                        <td>\r\n" +
    // "                            companyName<br>\r\n" +
    // "                            companyAddress<br>\r\n" +
    // "                            companyCityProvincePostalCode<br>\r\n" +
    // "                            companyCountry\r\n" +
    // "                        </td>\r\n" +
    // "                        <td></td>\r\n" +
    // "                        <td>\r\n" +
    // "                            "+accountJson.getName()+"<br>\r\n"+
    // "                            Renault<br>\r\n" +
    // "                            12 rue des ecoles<br>\r\n" +
    // "                            Quelque part, Poitou 44 567<br>\r\n" +
    // "                            France\r\n" +
    // "                        </td>\r\n" +
    // "                    </tr>\r\n" +
    // "                </table>\r\n" +
    // "            </td>\r\n" +
    // "        </tr>\r\n" +
    // "        <tr class=\"heading\">\r\n" +
    // "            <td>invoiceItemServicePeriod</td>\r\n" +
    // "            <td>invoiceItemDescription</td>\r\n" +
    // "            <td>invoiceItemAmount</td>\r\n" +
    // "        </tr>\r\n" +
    // "            <tr class=\"item last\">\r\n" +
    // "                <td>25 avr. 2012</td>\r\n" +
    // "                <td>Shotgun Monthly</td>\r\n" +
    // "                <td>0,00 USD</td>\r\n" +
    // "            </tr>\r\n" +
    // "        <tr class=\"total\">\r\n" +
    // "            <td></td>\r\n" +
    // "            <td></td>\r\n" +
    // "            <td>invoiceAmount0,00 US$</td>\r\n" +
    // "        </tr>\r\n" +
    // "        <tr class=\"total\">\r\n" +
    // "            <td></td>\r\n" +
    // "            <td></td>\r\n" +
    // "            <td>invoiceAmountPaid0,00 US$</td>\r\n" +
    // "        </tr>\r\n" +
    // "        <tr class=\"total\">\r\n" +
    // "            <td></td>\r\n" +
    // "            <td></td>\r\n" +
    // "            <td>invoiceBalance0,00 US$</td>\r\n" +
    // "        </tr>\r\n" +
    // "    </table>\r\n" +
    // "</div>\r\n" +
    // "</body>\r\n" +
    // "</html>"
    // );
    // Then create a dryRun for next upcoming invoice
    final InvoiceDryRun dryRunArg = new InvoiceDryRun().setDryRunType(DryRunType.UPCOMING_INVOICE);
    final Invoice dryRunInvoice = invoiceApi.generateDryRunInvoice(dryRunArg, accountJson.getAccountId(), null, requestOptions);
    assertEquals(dryRunInvoice.getBalance(), new BigDecimal("249.95"));
    assertEquals(dryRunInvoice.getTargetDate(), new LocalDate(2012, 6, 25));
    assertEquals(dryRunInvoice.getItems().size(), 1);
    assertEquals(dryRunInvoice.getItems().get(0).getStartDate(), new LocalDate(2012, 6, 25));
    assertEquals(dryRunInvoice.getItems().get(0).getEndDate(), new LocalDate(2012, 7, 25));
    assertEquals(dryRunInvoice.getItems().get(0).getAmount(), new BigDecimal("249.95"));
    final LocalDate futureDate = dryRunInvoice.getTargetDate();
    // The one more time with no DryRun
    invoiceApi.createFutureInvoice(accountJson.getAccountId(), futureDate, requestOptions);
    // Check again # invoices, should be 3 this time
    final List<Invoice> newInvoiceList = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
    assertEquals(newInvoiceList.size(), 3);
}
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) Invoices(org.killbill.billing.client.model.Invoices) InvoiceDryRun(org.killbill.billing.client.model.gen.InvoiceDryRun) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) AuditLog(org.killbill.billing.client.model.gen.AuditLog) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 100 with Account

use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.

the class TestInvoice method testParentInvoiceWithChildItems.

@Test(groups = "slow", description = "Can search and retrieve parent and children invoices with and without children items")
public void testParentInvoiceWithChildItems() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account parentAccount = createAccount();
    final Account childAccount1 = createAccount(parentAccount.getAccountId());
    final Account childAccount2 = createAccount(parentAccount.getAccountId());
    final Account childAccount3 = createAccount(parentAccount.getAccountId());
    // Add a bundle, subscription and move the clock to get the first invoice
    createSubscription(childAccount1.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
    createSubscription(childAccount2.getAccountId(), UUID.randomUUID().toString(), "Pistol", ProductCategory.BASE, BillingPeriod.MONTHLY);
    createSubscription(childAccount3.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
    callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_CREATION);
    clock.addDays(32);
    callbackServlet.assertListenerStatus();
    final List<Invoice> child1Invoices = accountApi.getInvoicesForAccount(childAccount1.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
    final List<Invoice> child2Invoices = accountApi.getInvoicesForAccount(childAccount2.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
    final List<Invoice> child3Invoices = accountApi.getInvoicesForAccount(childAccount3.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
    assertEquals(child1Invoices.size(), 2);
    final Invoice child1RecurringInvoice = child1Invoices.get(1);
    final InvoiceItem child1RecurringInvoiceItem = child1RecurringInvoice.getItems().get(0);
    final InvoiceItem child2RecurringInvoiceItem = child2Invoices.get(1).getItems().get(0);
    final InvoiceItem child3RecurringInvoiceItem = child3Invoices.get(1).getItems().get(0);
    final List<Invoice> parentInvoices = accountApi.getInvoicesForAccount(parentAccount.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
    assertEquals(parentInvoices.size(), 2);
    // check parent invoice with child invoice items and no adjustments
    // parameters: withItems = true, withChildrenItems = true
    Invoice parentInvoiceWithChildItems = invoiceApi.getInvoice(parentInvoices.get(1).getInvoiceId(), true, AuditLevel.NONE, requestOptions);
    assertEquals(parentInvoiceWithChildItems.getItems().size(), 3);
    assertEquals(parentInvoiceWithChildItems.getItems().get(0).getChildItems().size(), 1);
    assertEquals(parentInvoiceWithChildItems.getItems().get(1).getChildItems().size(), 1);
    assertEquals(parentInvoiceWithChildItems.getItems().get(2).getChildItems().size(), 1);
    // add an item adjustment
    final InvoiceItem adjustmentInvoiceItem = new InvoiceItem();
    adjustmentInvoiceItem.setAccountId(childAccount1.getAccountId());
    adjustmentInvoiceItem.setInvoiceId(child1RecurringInvoice.getInvoiceId());
    adjustmentInvoiceItem.setInvoiceItemId(child1RecurringInvoiceItem.getInvoiceItemId());
    adjustmentInvoiceItem.setAmount(BigDecimal.TEN);
    adjustmentInvoiceItem.setCurrency(child1RecurringInvoiceItem.getCurrency());
    final Invoice invoiceAdjustment = invoiceApi.adjustInvoiceItem(child1RecurringInvoice.getInvoiceId(), adjustmentInvoiceItem, null, NULL_PLUGIN_PROPERTIES, requestOptions);
    final InvoiceItem child1AdjInvoiceItem = invoiceApi.getInvoice(invoiceAdjustment.getInvoiceId(), true, AuditLevel.NONE, requestOptions).getItems().get(1);
    // check parent invoice with child invoice items and adjustments
    // parameters: withItems = true, withChildrenItems = true
    parentInvoiceWithChildItems = invoiceApi.getInvoice(parentInvoices.get(1).getInvoiceId(), true, AuditLevel.NONE, requestOptions);
    assertEquals(parentInvoiceWithChildItems.getItems().size(), 3);
    assertEquals(parentInvoiceWithChildItems.getItems().get(0).getChildItems().size(), 2);
    assertEquals(parentInvoiceWithChildItems.getItems().get(1).getChildItems().size(), 1);
    assertEquals(parentInvoiceWithChildItems.getItems().get(2).getChildItems().size(), 1);
    final InvoiceItem child1InvoiceItemFromParent = parentInvoiceWithChildItems.getItems().get(0).getChildItems().get(0);
    final InvoiceItem child1AdjInvoiceItemFromParent = parentInvoiceWithChildItems.getItems().get(0).getChildItems().get(1);
    final InvoiceItem child2InvoiceItemFromParent = parentInvoiceWithChildItems.getItems().get(1).getChildItems().get(0);
    final InvoiceItem child3InvoiceItemFromParent = parentInvoiceWithChildItems.getItems().get(2).getChildItems().get(0);
    // check children items for each PARENT_SUMMARY item
    assertTrue(child1InvoiceItemFromParent.equals(child1RecurringInvoiceItem));
    assertTrue(child1AdjInvoiceItemFromParent.equals(child1AdjInvoiceItem));
    assertTrue(child2InvoiceItemFromParent.equals(child2RecurringInvoiceItem));
    assertTrue(child3InvoiceItemFromParent.equals(child3RecurringInvoiceItem));
    // check parent invoice without child invoice items
    parentInvoiceWithChildItems = invoiceApi.getInvoice(parentInvoices.get(1).getInvoiceId(), false, AuditLevel.NONE, requestOptions);
    assertEquals(parentInvoiceWithChildItems.getItems().size(), 3);
    assertNull(parentInvoiceWithChildItems.getItems().get(0).getChildItems());
    assertNull(parentInvoiceWithChildItems.getItems().get(1).getChildItems());
    assertNull(parentInvoiceWithChildItems.getItems().get(2).getChildItems());
    // check parent invoice without items but with child invoice items and adjustment. Should return items anyway.
    // parameters: withItems = false, withChildrenItems = true
    parentInvoiceWithChildItems = invoiceApi.getInvoice(parentInvoices.get(1).getInvoiceId(), true, AuditLevel.NONE, requestOptions);
    assertEquals(parentInvoiceWithChildItems.getItems().size(), 3);
    assertEquals(parentInvoiceWithChildItems.getItems().get(0).getChildItems().size(), 2);
    assertEquals(parentInvoiceWithChildItems.getItems().get(1).getChildItems().size(), 1);
    assertEquals(parentInvoiceWithChildItems.getItems().get(2).getChildItems().size(), 1);
}
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) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

Account (org.killbill.billing.client.model.gen.Account)153 Test (org.testng.annotations.Test)139 DateTime (org.joda.time.DateTime)43 UUID (java.util.UUID)38 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)37 Subscription (org.killbill.billing.client.model.gen.Subscription)34 Invoice (org.killbill.billing.client.model.gen.Invoice)33 BigDecimal (java.math.BigDecimal)29 Payment (org.killbill.billing.client.model.gen.Payment)28 PaymentTransaction (org.killbill.billing.client.model.gen.PaymentTransaction)21 KillBillClientException (org.killbill.billing.client.KillBillClientException)19 Invoices (org.killbill.billing.client.model.Invoices)19 ComboPaymentTransaction (org.killbill.billing.client.model.gen.ComboPaymentTransaction)19 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)19 LocalDate (org.joda.time.LocalDate)13 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)13 Tags (org.killbill.billing.client.model.Tags)13 PaymentMethod (org.killbill.billing.client.model.gen.PaymentMethod)12 InvoicePaymentTransaction (org.killbill.billing.client.model.gen.InvoicePaymentTransaction)11 Payments (org.killbill.billing.client.model.Payments)10