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);
}
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);
}
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) {
}
}
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);
}
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);
}
Aggregations