Search in sources :

Example 1 with Invoice

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);
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) InvoiceItem(org.killbill.billing.client.model.InvoiceItem) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 2 with Invoice

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);
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 3 with Invoice

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);
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) Test(org.testng.annotations.Test)

Example 4 with Invoice

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);
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) InvoiceItem(org.killbill.billing.client.model.InvoiceItem) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 5 with Invoice

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);
}
Also used : Account(org.killbill.billing.client.model.Account) InvoiceItem(org.killbill.billing.client.model.InvoiceItem) Invoice(org.killbill.billing.client.model.Invoice) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

Account (org.killbill.billing.client.model.Account)8 Invoice (org.killbill.billing.client.model.Invoice)8 Test (org.testng.annotations.Test)8 BigDecimal (java.math.BigDecimal)4 InvoiceItem (org.killbill.billing.client.model.InvoiceItem)4 UUID (java.util.UUID)3 DateTime (org.joda.time.DateTime)3 ArrayList (java.util.ArrayList)2 Subscription (org.killbill.billing.client.model.Subscription)2 BulkBaseSubscriptionAndAddOns (org.killbill.billing.client.model.BulkBaseSubscriptionAndAddOns)1 Bundle (org.killbill.billing.client.model.Bundle)1 Bundles (org.killbill.billing.client.model.Bundles)1