Search in sources :

Example 71 with Account

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

the class TestInvoice method testInvoiceTransferCreditAccountNoCredit.

@Test(groups = "slow", description = "Fail to transfer credit from an account without parent account", expectedExceptions = KillBillClientException.class, expectedExceptionsMessageRegExp = ".* does not have credit")
public void testInvoiceTransferCreditAccountNoCredit() throws Exception {
    final Account parentAccount = createAccount();
    final Account childAccount = createAccount(parentAccount.getAccountId());
    // transfer credit to parent account
    killBillClient.transferChildCreditToParent(childAccount.getAccountId(), requestOptions);
}
Also used : Account(org.killbill.billing.client.model.Account) Test(org.testng.annotations.Test)

Example 72 with Account

use of org.killbill.billing.client.model.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 List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, false, false, AuditLevel.FULL);
    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);
    // Check get with & without items
    assertTrue(killBillClient.getInvoice(invoiceJson.getInvoiceId(), Boolean.FALSE).getItems().isEmpty());
    assertTrue(killBillClient.getInvoice(invoiceJson.getInvoiceNumber(), Boolean.FALSE).getItems().isEmpty());
    assertEquals(killBillClient.getInvoice(invoiceJson.getInvoiceId(), Boolean.TRUE).getItems().size(), invoiceJson.getItems().size());
    assertEquals(killBillClient.getInvoice(invoiceJson.getInvoiceNumber(), Boolean.TRUE).getItems().size(), invoiceJson.getItems().size());
    // Check we can retrieve an individual invoice
    final Invoice firstInvoice = killBillClient.getInvoice(invoiceJson.getInvoiceId());
    assertEquals(firstInvoice, invoiceJson);
    // Check we can retrieve the invoice by number
    final Invoice firstInvoiceByNumberJson = killBillClient.getInvoice(invoiceJson.getInvoiceNumber());
    assertEquals(firstInvoiceByNumberJson, invoiceJson);
    // Check we can retrieve the HTML version
    final String htmlInvoice = killBillClient.getInvoiceAsHtml(invoiceJson.getInvoiceId());
    assertEquals(htmlInvoice, "<html>\n" + "    <head>\n" + "        <style type=\"text/css\">\n" + "            th {align=left; width=225px; border-bottom: solid 2px black;}\n" + "        </style>\n" + "    </head>\n" + "    <body>\n" + "        <h1>invoiceTitle</h1>\n" + "        <table>\n" + "            <tr>\n" + "                <td rowspan=3 width=350px>Insert image here</td>\n" + "                <td width=100px/>\n" + "                <td width=225px/>\n" + "                <td width=225px/>\n" + "            </tr>\n" + "            <tr>\n" + "                <td />\n" + "                <td align=right>invoiceDate</td>\n" + "                <td>25 avr. 2012</td>\n" + "            </tr>\n" + "            <tr>\n" + "                <td />\n" + "                <td align=right>invoiceNumber</td>\n" + "                <td>" + invoiceJson.getInvoiceNumber() + "</td>\n" + "            </tr>\n" + "            <tr>\n" + "                <td>companyName</td>\n" + "                <td></td>\n" + "                <td align=right>accountOwnerName</td>\n" + "                <td>" + accountJson.getName() + "</td>\n" + "            </tr>\n" + "            <tr>\n" + "                <td>companyAddress</td>\n" + "                <td />\n" + "                <td />\n" + "                <td>" + accountJson.getEmail() + "</td>\n" + "            </tr>\n" + "            <tr>\n" + "                <td>companyCityProvincePostalCode</td>\n" + "                <td />\n" + "                <td />\n" + "                <td>" + accountJson.getPhone() + "</td>\n" + "            </tr>\n" + "            <tr>\n" + "                <td>companyCountry</td>\n" + "                <td />\n" + "                <td />\n" + "                <td />\n" + "            </tr>\n" + "            <tr>\n" + "                <td><companyUrl</td>\n" + "                <td />\n" + "                <td />\n" + "                <td />\n" + "            </tr>\n" + "        </table>\n" + "        <br />\n" + "        <br />\n" + "        <br />\n" + "        <table>\n" + "            <tr>\n" + "                <th>invoiceItemBundleName</td>\n" + "                <th>invoiceItemDescription</td>\n" + "                <th>invoiceItemServicePeriod</td>\n" + "                <th>invoiceItemAmount</td>\n" + "            </tr>\n" + "            \n" + "            <tr>\n" + "                <td>shotgun-monthly-trial</td>\n" + "                <td>Monthly shotgun plan</td>\n" + "                <td>25 avr. 2012</td>\n" + "                <td>USD 0.00</td>\n" + "            </tr>\n" + "            \n" + "            <tr>\n" + "                <td colspan=4 />\n" + "            </tr>\n" + "            <tr>\n" + "                <td colspan=2 />\n" + "                <td align=right><strong>invoiceAmount</strong></td>\n" + "                <td align=right><strong>0.00</strong></td>\n" + "            </tr>\n" + "            <tr>\n" + "                <td colspan=2 />\n" + "                <td align=right><strong>invoiceAmountPaid</strong></td>\n" + "                <td align=right><strong>0.00</strong></td>\n" + "            </tr>\n" + "            <tr>\n" + "                <td colspan=2 />\n" + "                <td align=right><strong>invoiceBalance</strong></td>\n" + "                <td align=right><strong>0.00</strong></td>\n" + "            </tr>\n" + "        </table>\n" + "    </body>\n" + "</html>\n" + "\n");
    // Then create a dryRun for next upcoming invoice
    final InvoiceDryRun dryRunArg = new InvoiceDryRun(DryRunType.UPCOMING_INVOICE, null, null, null, null, null, null, null, null, null, null, null);
    final Invoice dryRunInvoice = killBillClient.createDryRunInvoice(accountJson.getAccountId(), null, dryRunArg, createdBy, reason, comment);
    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
    killBillClient.createInvoice(accountJson.getAccountId(), futureDate, createdBy, reason, comment);
    // Check again # invoices, should be 3 this time
    final List<Invoice> newInvoiceList = killBillClient.getInvoicesForAccount(accountJson.getAccountId());
    assertEquals(newInvoiceList.size(), 3);
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) InvoiceDryRun(org.killbill.billing.client.model.InvoiceDryRun) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) AuditLog(org.killbill.billing.client.model.AuditLog) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 73 with Account

use of org.killbill.billing.client.model.Account 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 Credit credit = new Credit();
    credit.setAccountId(childAccount.getAccountId());
    credit.setInvoiceId(null);
    credit.setCreditAmount(creditAmount);
    // insert credit to child account
    final Credit creditJson = killBillClient.createCredit(credit, true, requestOptions);
    Invoices childInvoices = killBillClient.getInvoicesForAccount(childAccount.getAccountId(), true, false);
    Assert.assertEquals(childInvoices.size(), 1);
    Assert.assertEquals(childInvoices.get(0).getCreditAdj().compareTo(BigDecimal.TEN), 0);
    Invoices parentInvoices = killBillClient.getInvoicesForAccount(parentAccount.getAccountId(), true, false);
    Assert.assertEquals(parentInvoices.size(), 0);
    // transfer credit to parent account
    killBillClient.transferChildCreditToParent(childAccount.getAccountId(), requestOptions);
    childInvoices = killBillClient.getInvoicesForAccount(childAccount.getAccountId(), true, false);
    Assert.assertEquals(childInvoices.size(), 2);
    Assert.assertEquals(childInvoices.get(1).getCreditAdj().compareTo(BigDecimal.TEN.negate()), 0);
    parentInvoices = killBillClient.getInvoicesForAccount(parentAccount.getAccountId(), true, false);
    Assert.assertEquals(parentInvoices.size(), 1);
    Assert.assertEquals(parentInvoices.get(0).getCreditAdj().compareTo(BigDecimal.TEN), 0);
}
Also used : Account(org.killbill.billing.client.model.Account) Credit(org.killbill.billing.client.model.Credit) Invoices(org.killbill.billing.client.model.Invoices) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 74 with Account

use of org.killbill.billing.client.model.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
    createEntitlement(childAccount1.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, true);
    createEntitlement(childAccount2.getAccountId(), UUID.randomUUID().toString(), "Pistol", ProductCategory.BASE, BillingPeriod.MONTHLY, true);
    createEntitlement(childAccount3.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, true);
    clock.addDays(32);
    crappyWaitForLackOfProperSynchonization();
    final List<Invoice> child1Invoices = killBillClient.getInvoicesForAccount(childAccount1.getAccountId(), true, false, requestOptions);
    final List<Invoice> child2Invoices = killBillClient.getInvoicesForAccount(childAccount2.getAccountId(), true, false, requestOptions);
    final List<Invoice> child3Invoices = killBillClient.getInvoicesForAccount(childAccount3.getAccountId(), true, false, 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 = killBillClient.getInvoicesForAccount(parentAccount.getAccountId(), true, false, requestOptions);
    assertEquals(parentInvoices.size(), 2);
    // check parent invoice with child invoice items and no adjustments
    // parameters: withItems = true, withChildrenItems = true
    Invoice parentInvoiceWithChildItems = killBillClient.getInvoice(parentInvoices.get(1).getInvoiceId(), true, true, 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 = killBillClient.adjustInvoiceItem(adjustmentInvoiceItem, requestOptions);
    final InvoiceItem child1AdjInvoiceItem = killBillClient.getInvoice(invoiceAdjustment.getInvoiceId(), requestOptions).getItems().get(1);
    // check parent invoice with child invoice items and adjustments
    // parameters: withItems = true, withChildrenItems = true
    parentInvoiceWithChildItems = killBillClient.getInvoice(parentInvoices.get(1).getInvoiceId(), true, true, 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 = killBillClient.getInvoice(parentInvoices.get(1).getInvoiceId(), true, false, 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 = killBillClient.getInvoice(parentInvoices.get(1).getInvoiceId(), false, true, 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.Account) Invoice(org.killbill.billing.client.model.Invoice) InvoiceItem(org.killbill.billing.client.model.InvoiceItem) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 75 with Account

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

the class TestInvoice method testPartialInvoiceItemAdjustment.

@Test(groups = "slow", description = "Can partially adjust an invoice item")
public void testPartialInvoiceItemAdjustment() throws Exception {
    final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // Get the invoices
    final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, false);
    // 2 invoices but look for the non zero dollar one
    assertEquals(invoices.size(), 2);
    final Invoice invoice = invoices.get(1);
    // Verify the invoice we picked is non zero
    assertEquals(invoice.getAmount().compareTo(BigDecimal.ZERO), 1);
    final InvoiceItem invoiceItem = invoice.getItems().get(0);
    // Verify the item we picked is non zero
    assertEquals(invoiceItem.getAmount().compareTo(BigDecimal.ZERO), 1);
    // Adjust partially the item
    final BigDecimal adjustedAmount = invoiceItem.getAmount().divide(BigDecimal.TEN, BigDecimal.ROUND_HALF_UP);
    final InvoiceItem adjustmentInvoiceItem = new InvoiceItem();
    adjustmentInvoiceItem.setAccountId(accountJson.getAccountId());
    adjustmentInvoiceItem.setInvoiceId(invoice.getInvoiceId());
    adjustmentInvoiceItem.setInvoiceItemId(invoiceItem.getInvoiceItemId());
    adjustmentInvoiceItem.setAmount(adjustedAmount);
    adjustmentInvoiceItem.setCurrency(invoice.getCurrency().name());
    killBillClient.adjustInvoiceItem(adjustmentInvoiceItem, createdBy, reason, comment);
    // Verify the new invoice balance
    final Invoice adjustedInvoice = killBillClient.getInvoice(invoice.getInvoiceId());
    final BigDecimal adjustedInvoiceBalance = invoice.getBalance().add(adjustedAmount.negate()).setScale(2, BigDecimal.ROUND_HALF_UP);
    assertEquals(adjustedInvoice.getBalance().compareTo(adjustedInvoiceBalance), 0, String.format("Adjusted invoice balance is %s, should be %s", adjustedInvoice.getBalance(), adjustedInvoiceBalance));
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) InvoiceItem(org.killbill.billing.client.model.InvoiceItem) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

Account (org.killbill.billing.client.model.Account)123 Test (org.testng.annotations.Test)109 UUID (java.util.UUID)32 DateTime (org.joda.time.DateTime)32 Invoice (org.killbill.billing.client.model.Invoice)30 BigDecimal (java.math.BigDecimal)27 Payment (org.killbill.billing.client.model.Payment)24 Subscription (org.killbill.billing.client.model.Subscription)24 ComboPaymentTransaction (org.killbill.billing.client.model.ComboPaymentTransaction)17 InvoiceItem (org.killbill.billing.client.model.InvoiceItem)16 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)16 KillBillClientException (org.killbill.billing.client.KillBillClientException)14 InvoicePayment (org.killbill.billing.client.model.InvoicePayment)14 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)13 PaymentMethod (org.killbill.billing.client.model.PaymentMethod)13 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)10 Payments (org.killbill.billing.client.model.Payments)10 Tags (org.killbill.billing.client.model.Tags)10 Invoices (org.killbill.billing.client.model.Invoices)9 PaymentMethodPluginDetail (org.killbill.billing.client.model.PaymentMethodPluginDetail)9