Search in sources :

Example 91 with Account

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

the class TestBundle method testBundleOk.

@Test(groups = "slow", description = "Can retrieve bundles by external key")
public void testBundleOk() throws Exception {
    final Account accountJson = createAccount();
    createSubscription(accountJson.getAccountId(), "123467", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
    // Retrieves by external key
    final List<Bundle> objFromJson = accountApi.getAccountBundles(accountJson.getAccountId(), "123467", null, requestOptions);
    Assert.assertEquals(objFromJson.size(), 1);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Bundle(org.killbill.billing.client.model.gen.Bundle) Test(org.testng.annotations.Test)

Example 92 with Account

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

the class TestBundle method testCreateBundleWithNoExternalKey.

@Test(groups = "slow", description = "Can create bundles without an external key")
public void testCreateBundleWithNoExternalKey() throws Exception {
    final Account accountJson;
    accountJson = createAccount();
    final Subscription subscription = createSubscription(accountJson.getAccountId(), null, "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
    Assert.assertNotNull(subscription.getBundleExternalKey());
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Subscription(org.killbill.billing.client.model.gen.Subscription) Test(org.testng.annotations.Test)

Example 93 with Account

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

the class TestInvoice method testCreateCreditInvoiceAndMoveStatus.

@Test(groups = "slow", description = "Can add a credit to a new invoice")
public void testCreateCreditInvoiceAndMoveStatus() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    final BigDecimal creditAmount = BigDecimal.TEN;
    final InvoiceItem credit = new InvoiceItem();
    credit.setAccountId(account.getAccountId());
    credit.setInvoiceId(null);
    credit.setAmount(creditAmount);
    InvoiceItems credits = new InvoiceItems();
    credits.add(credit);
    final List<InvoiceItem> creditJsons = creditApi.createCredits(credits, false, NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertEquals(creditJsons.size(), 1);
    Invoice invoice = invoiceApi.getInvoice(creditJsons.get(0).getInvoiceId(), requestOptions);
    Assert.assertEquals(invoice.getStatus(), InvoiceStatus.DRAFT);
    invoiceApi.commitInvoice(invoice.getInvoiceId(), requestOptions);
    invoice = invoiceApi.getInvoice(creditJsons.get(0).getInvoiceId(), requestOptions);
    Assert.assertEquals(invoice.getStatus(), InvoiceStatus.COMMITTED);
}
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) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 94 with Account

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

the class TestInvoice method testInvoicePayments.

@Test(groups = "slow", description = "Can retrieve invoice payments")
public void testInvoicePayments() throws Exception {
    clock.setTime(new DateTime(2012, 4, 25, 0, 3, 42, 0));
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
    assertEquals(invoices.size(), 2);
    final Invoice invoiceWithPositiveAmount = Iterables.tryFind(invoices, new Predicate<Invoice>() {

        @Override
        public boolean apply(final Invoice input) {
            return input.getAmount().compareTo(BigDecimal.ZERO) > 0;
        }
    }).orNull();
    Assert.assertNotNull(invoiceWithPositiveAmount);
    final InvoicePayments objFromJson = invoiceApi.getPaymentsForInvoice(invoiceWithPositiveAmount.getInvoiceId(), requestOptions);
    assertEquals(objFromJson.size(), 1);
    assertEquals(invoiceWithPositiveAmount.getAmount().compareTo(objFromJson.get(0).getPurchasedAmount()), 0);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Invoice(org.killbill.billing.client.model.gen.Invoice) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) DateTime(org.joda.time.DateTime) Predicate(com.google.common.base.Predicate) Test(org.testng.annotations.Test)

Example 95 with Account

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

the class TestInvoice method testPartialInvoiceItemAdjustment.

@Test(groups = "slow", description = "Can partially adjust an invoice item")
public void testPartialInvoiceItemAdjustment() throws Exception {
    final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // Get the invoices
    final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
    // 2 invoices but look for the non zero dollar one
    assertEquals(invoices.size(), 2);
    final Invoice invoice = invoices.get(1);
    // Verify the invoice we picked is non zero
    assertEquals(invoice.getAmount().compareTo(BigDecimal.ZERO), 1);
    final InvoiceItem invoiceItem = invoice.getItems().get(0);
    // Verify the item we picked is non zero
    assertEquals(invoiceItem.getAmount().compareTo(BigDecimal.ZERO), 1);
    // Adjust partially the item
    final BigDecimal adjustedAmount = invoiceItem.getAmount().divide(BigDecimal.TEN, BigDecimal.ROUND_HALF_UP);
    final InvoiceItem adjustmentInvoiceItem = new InvoiceItem();
    adjustmentInvoiceItem.setAccountId(accountJson.getAccountId());
    adjustmentInvoiceItem.setInvoiceId(invoice.getInvoiceId());
    adjustmentInvoiceItem.setInvoiceItemId(invoiceItem.getInvoiceItemId());
    adjustmentInvoiceItem.setAmount(adjustedAmount);
    adjustmentInvoiceItem.setCurrency(invoice.getCurrency());
    invoiceApi.adjustInvoiceItem(invoice.getInvoiceId(), adjustmentInvoiceItem, null, NULL_PLUGIN_PROPERTIES, requestOptions);
    // Verify the new invoice balance
    final Invoice adjustedInvoice = invoiceApi.getInvoice(invoice.getInvoiceId(), requestOptions);
    final BigDecimal adjustedInvoiceBalance = invoice.getBalance().add(adjustedAmount.negate()).setScale(2, BigDecimal.ROUND_HALF_UP);
    assertEquals(adjustedInvoice.getBalance().compareTo(adjustedInvoiceBalance), 0, String.format("Adjusted invoice balance is %s, should be %s", adjustedInvoice.getBalance(), adjustedInvoiceBalance));
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Invoice(org.killbill.billing.client.model.gen.Invoice) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) 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