Search in sources :

Example 6 with InvoiceItems

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

the class TestInvoice method testAddTaxItemsOnNewInvoice.

@Test(groups = "slow", description = "Can create tax items for a bundle")
public void testAddTaxItemsOnNewInvoice() 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 taxAmount = BigDecimal.TEN;
    final UUID bundleId = UUID.randomUUID();
    final InvoiceItem taxItem = new InvoiceItem();
    taxItem.setAccountId(accountJson.getAccountId());
    taxItem.setAmount(taxAmount);
    taxItem.setCurrency(accountJson.getCurrency());
    taxItem.setBundleId(bundleId);
    final InvoiceItems input = new InvoiceItems();
    input.add(taxItem);
    final List<InvoiceItem> createdTaxItems = invoiceApi.createTaxItems(accountJson.getAccountId(), input, true, clock.getUTCToday(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(createdTaxItems.size(), 1);
    final Invoice invoiceWithItems = invoiceApi.getInvoice(createdTaxItems.get(0).getInvoiceId(), null, AuditLevel.NONE, requestOptions);
    assertEquals(invoiceWithItems.getBalance().compareTo(taxAmount), 0);
    assertEquals(invoiceWithItems.getItems().size(), 1);
    assertEquals(invoiceWithItems.getItems().get(0).getBundleId(), bundleId);
    assertEquals(invoiceWithItems.getItems().get(0).getItemType(), InvoiceItemType.TAX);
    // 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 7 with InvoiceItems

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

the class TestCredit method testAddCreditToCommittedInvoice.

@Test(groups = "slow", description = "Can add a credit to an existing account", expectedExceptions = KillBillClientException.class, expectedExceptionsMessageRegExp = ".*it is already in COMMITTED status")
public void testAddCreditToCommittedInvoice() throws Exception {
    final Invoice invoice = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions).get(1);
    final BigDecimal creditAmount = BigDecimal.ONE;
    final InvoiceItem credit = new InvoiceItem();
    credit.setAccountId(accountJson.getAccountId());
    credit.setInvoiceId(invoice.getInvoiceId());
    credit.setAmount(creditAmount);
    final InvoiceItems credits = new InvoiceItems();
    credits.add(credit);
    final InvoiceItems objFromJson = creditApi.createCredits(credits, true, NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertTrue(objFromJson.get(0).getAmount().compareTo(creditAmount) == 0);
}
Also used : Invoice(org.killbill.billing.client.model.gen.Invoice) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) InvoiceItems(org.killbill.billing.client.model.InvoiceItems) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 8 with InvoiceItems

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

the class TestCredit method testBadRequest.

@Test(groups = "slow", description = "Cannot credit a badly formatted credit")
public void testBadRequest() throws Exception {
    final InvoiceItem credit = new InvoiceItem();
    credit.setAccountId(accountJson.getAccountId());
    credit.setAmount(BigDecimal.TEN.negate());
    final InvoiceItems credits = new InvoiceItems();
    credits.add(credit);
    // Try to create the credit
    try {
        creditApi.createCredits(credits, true, NULL_PLUGIN_PROPERTIES, requestOptions);
        fail();
    } catch (final KillBillClientException e) {
    }
}
Also used : InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) InvoiceItems(org.killbill.billing.client.model.InvoiceItems) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Example 9 with InvoiceItems

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

the class TestCredit method testAccountDoesNotExist.

@Test(groups = "slow", description = "Cannot add a credit if the account doesn't exist")
public void testAccountDoesNotExist() throws Exception {
    final InvoiceItem credit = new InvoiceItem();
    credit.setAccountId(UUID.randomUUID());
    credit.setAmount(BigDecimal.TEN);
    final InvoiceItems credits = new InvoiceItems();
    credits.add(credit);
    // Try to create the credit
    final InvoiceItems result = creditApi.createCredits(credits, true, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(result.size(), 0);
}
Also used : InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) InvoiceItems(org.killbill.billing.client.model.InvoiceItems) Test(org.testng.annotations.Test)

Example 10 with InvoiceItems

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

the class TestInvoice method testCreateCreditInvoiceAndMoveStatus.

@Test(groups = "slow", description = "Can add a credit to a new invoice")
public void testCreateCreditInvoiceAndMoveStatus() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    final BigDecimal creditAmount = BigDecimal.TEN;
    final InvoiceItem credit = new InvoiceItem();
    credit.setAccountId(account.getAccountId());
    credit.setInvoiceId(null);
    credit.setAmount(creditAmount);
    InvoiceItems credits = new InvoiceItems();
    credits.add(credit);
    final List<InvoiceItem> creditJsons = creditApi.createCredits(credits, false, NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertEquals(creditJsons.size(), 1);
    Invoice invoice = invoiceApi.getInvoice(creditJsons.get(0).getInvoiceId(), requestOptions);
    Assert.assertEquals(invoice.getStatus(), InvoiceStatus.DRAFT);
    invoiceApi.commitInvoice(invoice.getInvoiceId(), requestOptions);
    invoice = invoiceApi.getInvoice(creditJsons.get(0).getInvoiceId(), requestOptions);
    Assert.assertEquals(invoice.getStatus(), InvoiceStatus.COMMITTED);
}
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) 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