Search in sources :

Example 1 with InvoiceItems

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

the class TestAccountTimeline method testAccountTimelineWithAudits.

@Test(groups = "slow", description = "Can retrieve the timeline with audits")
public void testAccountTimelineWithAudits() throws Exception {
    final DateTime startTime = clock.getUTCNow();
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    final DateTime endTime = clock.getUTCNow();
    // Add credit
    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.setAmount(creditAmount);
    final InvoiceItems credits = new InvoiceItems();
    credits.add(credit);
    creditApi.createCredits(credits, true, NULL_PLUGIN_PROPERTIES, requestOptions);
    // Add refund
    final Payment postedPayment = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions).get(0);
    final BigDecimal refundAmount = BigDecimal.ONE;
    final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
    refund.setPaymentId(postedPayment.getPaymentId());
    refund.setAmount(refundAmount);
    invoicePaymentApi.createRefundWithAdjustments(postedPayment.getPaymentId(), refund, accountJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    // Add chargeback
    final BigDecimal chargebackAmount = BigDecimal.ONE;
    final InvoicePaymentTransaction chargeback = new InvoicePaymentTransaction();
    chargeback.setPaymentId(postedPayment.getPaymentId());
    chargeback.setAmount(chargebackAmount);
    invoicePaymentApi.createChargeback(postedPayment.getPaymentId(), chargeback, NULL_PLUGIN_PROPERTIES, requestOptions);
    // Verify payments
    verifyPayments(accountJson.getAccountId(), startTime, endTime, refundAmount, chargebackAmount);
    // Verify invoices
    verifyInvoices(accountJson.getAccountId(), startTime, endTime);
    // Verify credits
    verifyCredits(accountJson.getAccountId(), startTime, endTime, creditAmount);
    // Verify bundles
    verifyBundles(accountJson.getAccountId(), startTime, endTime);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) Invoice(org.killbill.billing.client.model.gen.Invoice) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) InvoiceItems(org.killbill.billing.client.model.InvoiceItems) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 2 with InvoiceItems

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

the class TestCredit method testAddCreditToInvoice.

@Test(groups = "slow", description = "Can add a credit to an existing invoice")
public void testAddCreditToInvoice() throws Exception {
    final DateTime effectiveDate = clock.getUTCNow();
    final BigDecimal creditAmount = BigDecimal.ONE;
    final InvoiceItem credit = new InvoiceItem();
    credit.setAccountId(accountJson.getAccountId());
    credit.setAmount(creditAmount);
    credit.setDescription("description");
    credit.setQuantity(5);
    credit.setRate(BigDecimal.TEN);
    credit.setItemDetails("itemDetails");
    final InvoiceItems credits = new InvoiceItems();
    credits.add(credit);
    InvoiceItems createdCredits = creditApi.createCredits(credits, false, NULL_PLUGIN_PROPERTIES, requestOptions);
    final UUID invoiceId = createdCredits.get(0).getInvoiceId();
    credit.setInvoiceId(invoiceId);
    createdCredits = creditApi.createCredits(credits, false, NULL_PLUGIN_PROPERTIES, requestOptions);
    // We can't just compare the object via .equals() due e.g. to the invoice id
    assertEquals(createdCredits.get(0).getAccountId(), accountJson.getAccountId());
    assertEquals(createdCredits.get(0).getInvoiceId(), invoiceId);
    assertEquals(createdCredits.get(0).getAmount().compareTo(creditAmount), 0);
    assertEquals(createdCredits.get(0).getStartDate().compareTo(effectiveDate.toLocalDate()), 0);
    assertEquals(createdCredits.get(0).getDescription().compareTo("description"), 0);
    assertEquals(createdCredits.get(0).getQuantity().compareTo(5), 0);
    assertEquals(createdCredits.get(0).getRate().compareTo(BigDecimal.TEN), 0);
    assertEquals(createdCredits.get(0).getItemDetails().compareTo("itemDetails"), 0);
}
Also used : InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) InvoiceItems(org.killbill.billing.client.model.InvoiceItems) UUID(java.util.UUID) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 3 with InvoiceItems

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

the class TestInvoice method testExternalChargesWithSameInvoice.

@Test(groups = "slow", description = "Can create multiple external charges with same invoice and external keys")
public void testExternalChargesWithSameInvoice() throws Exception {
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // 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 chargeAmount = BigDecimal.TEN;
    final InvoiceItems externalCharges = new InvoiceItems();
    // 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);
    final List<InvoiceItem> createdExternalCharges = invoiceApi.createExternalCharges(accountJson.getAccountId(), externalCharges, clock.getUTCToday(), true, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(createdExternalCharges.size(), 2);
    assertEquals(createdExternalCharges.get(0).getCurrency(), accountJson.getCurrency());
    assertEquals(createdExternalCharges.get(1).getCurrency(), accountJson.getCurrency());
}
Also used : Account(org.killbill.billing.client.model.gen.Account) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) InvoiceItems(org.killbill.billing.client.model.InvoiceItems) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 4 with InvoiceItems

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

the class TestInvoice method testExternalChargeOnNewInvoice.

@Test(groups = "slow", description = "Can create an external charge")
public void testExternalChargeOnNewInvoice() throws Exception {
    final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // Get the invoices
    final Invoices originalInvoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
    assertEquals(originalInvoices.size(), 2);
    final UUID firstInvoiceItemId = originalInvoices.get(0).getItems().get(0).getInvoiceItemId();
    // 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.setPlanName("SomePlan");
    externalCharge.setProductName("SomeProduct");
    externalCharge.setDescription(UUID.randomUUID().toString());
    externalCharge.setItemDetails("Item Details");
    externalCharge.setLinkedInvoiceItemId(firstInvoiceItemId);
    final LocalDate startDate = clock.getUTCToday();
    externalCharge.setStartDate(startDate);
    final LocalDate endDate = startDate.plusDays(10);
    externalCharge.setEndDate(endDate);
    final InvoiceItems itemsForCharge = new InvoiceItems();
    itemsForCharge.add(externalCharge);
    final List<InvoiceItem> createdExternalCharges = invoiceApi.createExternalCharges(accountJson.getAccountId(), itemsForCharge, clock.getUTCToday(), true, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(createdExternalCharges.size(), 1);
    final Invoice invoiceWithItems = invoiceApi.getInvoice(createdExternalCharges.get(0).getInvoiceId(), false, AuditLevel.NONE, requestOptions);
    assertEquals(invoiceWithItems.getBalance().compareTo(chargeAmount), 0);
    assertEquals(invoiceWithItems.getItems().size(), 1);
    assertEquals(invoiceWithItems.getItems().get(0).getDescription(), externalCharge.getDescription());
    assertNull(invoiceWithItems.getItems().get(0).getBundleId());
    assertEquals(invoiceWithItems.getItems().get(0).getStartDate().compareTo(startDate), 0);
    assertEquals(invoiceWithItems.getItems().get(0).getEndDate().compareTo(endDate), 0);
    assertEquals(invoiceWithItems.getItems().get(0).getItemDetails(), "Item Details");
    assertEquals(invoiceWithItems.getItems().get(0).getLinkedInvoiceItemId(), firstInvoiceItemId);
    assertEquals(invoiceWithItems.getItems().get(0).getPlanName().compareTo("SomePlan"), 0);
    assertEquals(invoiceWithItems.getItems().get(0).getProductName().compareTo("SomeProduct"), 0);
    // Verify the total number of invoices
    assertEquals(accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions).size(), 3);
}
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) Invoices(org.killbill.billing.client.model.Invoices) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 5 with InvoiceItems

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

the class TestInvoice method testExternalCharges.

@Test(groups = "slow", description = "Can create multiple external charges")
public void testExternalCharges() 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 chargeAmount = BigDecimal.TEN;
    final InvoiceItems externalCharges = new InvoiceItems();
    // 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);
    final List<InvoiceItem> createdExternalCharges = invoiceApi.createExternalCharges(accountJson.getAccountId(), externalCharges, clock.getUTCToday(), true, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(createdExternalCharges.size(), 2);
    assertEquals(createdExternalCharges.get(0).getCurrency(), accountJson.getCurrency());
    assertEquals(createdExternalCharges.get(1).getCurrency(), accountJson.getCurrency());
    // Verify the total number of invoices
    assertEquals(accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions).size(), 3);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) InvoiceItems(org.killbill.billing.client.model.InvoiceItems) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

InvoiceItems (org.killbill.billing.client.model.InvoiceItems)13 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)13 Test (org.testng.annotations.Test)13 BigDecimal (java.math.BigDecimal)11 Account (org.killbill.billing.client.model.gen.Account)9 Invoice (org.killbill.billing.client.model.gen.Invoice)7 UUID (java.util.UUID)4 DateTime (org.joda.time.DateTime)2 LocalDate (org.joda.time.LocalDate)2 Invoices (org.killbill.billing.client.model.Invoices)2 KillBillClientException (org.killbill.billing.client.KillBillClientException)1 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)1 InvoicePaymentTransaction (org.killbill.billing.client.model.gen.InvoicePaymentTransaction)1 Payment (org.killbill.billing.client.model.gen.Payment)1