Search in sources :

Example 16 with InvoiceItem

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

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

use of org.killbill.billing.client.model.gen.InvoiceItem 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)

Example 19 with InvoiceItem

use of org.killbill.billing.client.model.gen.InvoiceItem 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 = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
    // 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());
    invoiceApi.adjustInvoiceItem(invoice.getInvoiceId(), adjustmentInvoiceItem, null, NULL_PLUGIN_PROPERTIES, requestOptions);
    // Verify the new invoice balance
    final Invoice adjustedInvoice = invoiceApi.getInvoice(invoice.getInvoiceId(), requestOptions);
    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.gen.Account) Invoice(org.killbill.billing.client.model.gen.Invoice) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 20 with InvoiceItem

use of org.killbill.billing.client.model.gen.InvoiceItem 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)

Aggregations

InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)27 Test (org.testng.annotations.Test)26 Account (org.killbill.billing.client.model.gen.Account)19 BigDecimal (java.math.BigDecimal)16 Invoice (org.killbill.billing.client.model.gen.Invoice)14 InvoiceItems (org.killbill.billing.client.model.InvoiceItems)13 Invoices (org.killbill.billing.client.model.Invoices)9 DateTime (org.joda.time.DateTime)7 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)7 InvoicePaymentTransaction (org.killbill.billing.client.model.gen.InvoicePaymentTransaction)7 Payment (org.killbill.billing.client.model.gen.Payment)7 UUID (java.util.UUID)5 AuditLog (org.killbill.billing.client.model.gen.AuditLog)4 LocalDate (org.joda.time.LocalDate)3 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)3 Payments (org.killbill.billing.client.model.Payments)3 Predicate (com.google.common.base.Predicate)1 KillBillClientException (org.killbill.billing.client.KillBillClientException)1 RequestOptions (org.killbill.billing.client.RequestOptions)1 CustomFields (org.killbill.billing.client.model.CustomFields)1