Search in sources :

Example 1 with InvoiceItem

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

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

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

Example 4 with InvoiceItem

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

the class TestInvoice method testExternalChargeOnExistingInvoice.

@Test(groups = "slow", description = "Can create an external charge on an existing invoice")
public void testExternalChargeOnExistingInvoice() 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 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(), false, 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);
    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 5 with InvoiceItem

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

the class TestInvoice method testExternalChargesWithSameInvoiceAndExternalKeys.

@Test(groups = "slow", description = "Can create multiple external charges with same invoice and external keys")
public void testExternalChargesWithSameInvoiceAndExternalKeys() 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 List<InvoiceItem> externalCharges = new ArrayList<InvoiceItem>();
    // Does not pass currency to test on purpose that we will default to account currency
    final InvoiceItem externalCharge1 = new InvoiceItem();
    externalCharge1.setAccountId(accountJson.getAccountId());
    externalCharge1.setAmount(chargeAmount);
    externalCharge1.setDescription(UUID.randomUUID().toString());
    externalCharges.add(externalCharge1);
    final InvoiceItem externalCharge2 = new InvoiceItem();
    externalCharge2.setAccountId(accountJson.getAccountId());
    externalCharge2.setAmount(chargeAmount);
    externalCharge2.setCurrency(accountJson.getCurrency());
    externalCharge2.setDescription(UUID.randomUUID().toString());
    externalCharges.add(externalCharge2);
    String paymentExternalKey = "anyPaymentExternalKey";
    String transactionExternalKey = "anyTransactionExternalKey";
    final List<InvoiceItem> createdExternalCharges = killBillClient.createExternalCharges(externalCharges, clock.getUTCToday(), true, true, paymentExternalKey, transactionExternalKey, RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).build());
    assertEquals(createdExternalCharges.size(), 2);
    assertEquals(createdExternalCharges.get(0).getCurrency().toString(), accountJson.getCurrency());
    assertEquals(createdExternalCharges.get(1).getCurrency().toString(), accountJson.getCurrency());
    // Verify the total number of invoices
    assertEquals(killBillClient.getInvoicesForAccount(accountJson.getAccountId()).size(), 3);
    Payments payments = killBillClient.getPaymentsForAccount(accountJson.getAccountId(), AuditLevel.NONE, RequestOptions.empty());
    assertNotNull(payments);
    // Verify payment with paymentExternalKey provided
    assertEquals(payments.get(payments.size() - 1).getPaymentExternalKey(), paymentExternalKey);
    // Verify transactions with transactionExternalKey provided
    assertEquals(payments.get(payments.size() - 1).getTransactions().get(0).getTransactionExternalKey(), transactionExternalKey);
}
Also used : Account(org.killbill.billing.client.model.Account) InvoiceItem(org.killbill.billing.client.model.InvoiceItem) ArrayList(java.util.ArrayList) Payments(org.killbill.billing.client.model.Payments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

BigDecimal (java.math.BigDecimal)5 Account (org.killbill.billing.client.model.Account)5 InvoiceItem (org.killbill.billing.client.model.InvoiceItem)5 Test (org.testng.annotations.Test)5 Invoice (org.killbill.billing.client.model.Invoice)4 UUID (java.util.UUID)3 ArrayList (java.util.ArrayList)1 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)1 Payments (org.killbill.billing.client.model.Payments)1