Search in sources :

Example 26 with Account

use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.

the class TestExportAccount method testExportAccount.

@Test(groups = "slow")
public void testExportAccount() throws Exception {
    final Account emptyAccount = new Account();
    final Account account = accountApi.createAccount(emptyAccount, requestOptions);
    final OutputStream outputStream = new ByteArrayOutputStream();
    final int statusCode = exportApi.exportDataForAccount(account.getAccountId(), outputStream, requestOptions);
    outputStream.flush();
    Assert.assertEquals(statusCode, 200);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test)

Example 27 with Account

use of org.killbill.billing.client.model.gen.Account 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 28 with Account

use of org.killbill.billing.client.model.gen.Account 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 29 with Account

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

Example 30 with Account

use of org.killbill.billing.client.model.gen.Account 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);
}
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) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

Account (org.killbill.billing.client.model.gen.Account)153 Test (org.testng.annotations.Test)139 DateTime (org.joda.time.DateTime)43 UUID (java.util.UUID)38 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)37 Subscription (org.killbill.billing.client.model.gen.Subscription)34 Invoice (org.killbill.billing.client.model.gen.Invoice)33 BigDecimal (java.math.BigDecimal)29 Payment (org.killbill.billing.client.model.gen.Payment)28 PaymentTransaction (org.killbill.billing.client.model.gen.PaymentTransaction)21 KillBillClientException (org.killbill.billing.client.KillBillClientException)19 Invoices (org.killbill.billing.client.model.Invoices)19 ComboPaymentTransaction (org.killbill.billing.client.model.gen.ComboPaymentTransaction)19 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)19 LocalDate (org.joda.time.LocalDate)13 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)13 Tags (org.killbill.billing.client.model.Tags)13 PaymentMethod (org.killbill.billing.client.model.gen.PaymentMethod)12 InvoicePaymentTransaction (org.killbill.billing.client.model.gen.InvoicePaymentTransaction)11 Payments (org.killbill.billing.client.model.Payments)10