use of org.killbill.billing.client.model.Invoice in project killbill by killbill.
the class TestInvoice method testExternalChargeForBundleOnExistingInvoice.
@Test(groups = "slow", description = "Can create an external charge for a bundle on an existing invoice")
public void testExternalChargeForBundleOnExistingInvoice() 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 UUID invoiceId = invoices.get(1).getInvoiceId();
final BigDecimal originalInvoiceAmount = invoices.get(1).getAmount();
final int originalNumberOfItemsForInvoice = invoices.get(1).getItems().size();
// Post an external charge
final BigDecimal chargeAmount = BigDecimal.TEN;
final UUID bundleId = UUID.randomUUID();
final InvoiceItem externalCharge = new InvoiceItem();
externalCharge.setAccountId(accountJson.getAccountId());
externalCharge.setAmount(chargeAmount);
externalCharge.setCurrency(accountJson.getCurrency());
externalCharge.setInvoiceId(invoiceId);
externalCharge.setBundleId(bundleId);
final InvoiceItem createdExternalCharge = killBillClient.createExternalCharge(externalCharge, clock.getUTCToday(), false, true, createdBy, reason, comment);
final Invoice invoiceWithItems = killBillClient.getInvoice(createdExternalCharge.getInvoiceId(), true);
assertEquals(invoiceWithItems.getItems().size(), originalNumberOfItemsForInvoice + 1);
assertEquals(invoiceWithItems.getItems().get(originalNumberOfItemsForInvoice).getBundleId(), bundleId);
// Verify the new invoice balance
final Invoice adjustedInvoice = killBillClient.getInvoice(invoiceId);
final BigDecimal adjustedInvoiceBalance = originalInvoiceAmount.add(chargeAmount.setScale(2, RoundingMode.HALF_UP));
assertEquals(adjustedInvoice.getBalance().compareTo(adjustedInvoiceBalance), 0);
}
use of org.killbill.billing.client.model.Invoice in project killbill by killbill.
the class TestInvoice method testPayAllInvoices.
@Test(groups = "slow", description = "Can pay invoices")
public void testPayAllInvoices() throws Exception {
clock.setTime(new DateTime(2012, 4, 25, 0, 3, 42, 0));
// No payment method
final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
// Check there was no payment made
assertEquals(killBillClient.getPaymentsForAccount(accountJson.getAccountId()).size(), 0);
// Get the invoices
final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId());
assertEquals(invoices.size(), 2);
final Invoice invoiceToPay = invoices.get(1);
assertEquals(invoiceToPay.getBalance().compareTo(BigDecimal.ZERO), 1);
// Pay all invoices
killBillClient.payAllInvoices(accountJson.getAccountId(), true, null, createdBy, reason, comment);
for (final Invoice invoice : killBillClient.getInvoicesForAccount(accountJson.getAccountId())) {
assertEquals(invoice.getBalance().compareTo(BigDecimal.ZERO), 0);
}
assertEquals(killBillClient.getPaymentsForAccount(accountJson.getAccountId()).size(), 1);
}
use of org.killbill.billing.client.model.Invoice in project killbill by killbill.
the class TestInvoiceNotification method testTriggerNotification.
@Test(groups = "slow", description = "Can trigger an invoice notification")
public void testTriggerNotification() throws Exception {
final Account accountJson = createScenarioWithOneInvoice();
final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId());
Assert.assertEquals(invoices.size(), 1);
final Invoice invoice = invoices.get(0);
killBillClient.triggerInvoiceNotification(invoice.getInvoiceId(), createdBy, reason, comment);
}
use of org.killbill.billing.client.model.Invoice in project killbill by killbill.
the class TestInvoice method testExternalChargeOnExistingInvoiceWithAutomaticPayment.
@Test(groups = "slow", description = "Can create an external charge on an existing invoice and trigger a payment")
public void testExternalChargeOnExistingInvoiceWithAutomaticPayment() throws Exception {
final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
// 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 UUID invoiceId = invoices.get(1).getInvoiceId();
final BigDecimal originalInvoiceAmount = invoices.get(1).getAmount();
final int originalNumberOfItemsForInvoice = invoices.get(1).getItems().size();
// Post an external charge
final BigDecimal chargeAmount = BigDecimal.TEN;
final InvoiceItem externalCharge = new InvoiceItem();
externalCharge.setAccountId(accountJson.getAccountId());
externalCharge.setAmount(chargeAmount);
externalCharge.setCurrency(accountJson.getCurrency());
externalCharge.setInvoiceId(invoiceId);
final InvoiceItem createdExternalCharge = killBillClient.createExternalCharge(externalCharge, clock.getUTCToday(), true, true, createdBy, reason, comment);
final Invoice invoiceWithItems = killBillClient.getInvoice(createdExternalCharge.getInvoiceId(), true);
assertEquals(invoiceWithItems.getItems().size(), originalNumberOfItemsForInvoice + 1);
assertNull(invoiceWithItems.getItems().get(originalNumberOfItemsForInvoice).getBundleId());
// Verify the new invoice balance
final Invoice adjustedInvoice = killBillClient.getInvoice(invoiceId);
assertEquals(adjustedInvoice.getBalance().compareTo(BigDecimal.ZERO), 0);
}
use of org.killbill.billing.client.model.Invoice in project killbill by killbill.
the class TestInvoice method testExternalChargeOnNewInvoiceWithAutomaticPayment.
@Test(groups = "slow", description = "Can create an external charge and trigger a payment")
public void testExternalChargeOnNewInvoiceWithAutomaticPayment() throws Exception {
final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
// Get the invoices
assertEquals(killBillClient.getInvoicesForAccount(accountJson.getAccountId()).size(), 2);
// Post an external charge
final BigDecimal chargeAmount = BigDecimal.TEN;
final InvoiceItem externalCharge = new InvoiceItem();
externalCharge.setAccountId(accountJson.getAccountId());
externalCharge.setAmount(chargeAmount);
externalCharge.setCurrency(accountJson.getCurrency());
final InvoiceItem createdExternalCharge = killBillClient.createExternalCharge(externalCharge, clock.getUTCToday(), true, true, createdBy, reason, comment);
final Invoice invoiceWithItems = killBillClient.getInvoice(createdExternalCharge.getInvoiceId(), true);
assertEquals(invoiceWithItems.getBalance().compareTo(BigDecimal.ZERO), 0);
assertEquals(invoiceWithItems.getItems().size(), 1);
assertNull(invoiceWithItems.getItems().get(0).getBundleId());
// Verify the total number of invoices
assertEquals(killBillClient.getInvoicesForAccount(accountJson.getAccountId()).size(), 3);
}
Aggregations