Search in sources :

Example 6 with Invoice

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

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

the class TestEntitlement method testCreateEntitlementsWithAddOns.

@Test(groups = "slow", description = "Create a bulk of base entitlement and addOns under the same transaction")
public void testCreateEntitlementsWithAddOns() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithDefaultPaymentMethod();
    final Subscription base = new Subscription();
    base.setAccountId(accountJson.getAccountId());
    base.setProductName("Shotgun");
    base.setProductCategory(ProductCategory.BASE);
    base.setBillingPeriod(BillingPeriod.MONTHLY);
    base.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final Subscription addOn1 = new Subscription();
    addOn1.setAccountId(accountJson.getAccountId());
    addOn1.setProductName("Telescopic-Scope");
    addOn1.setProductCategory(ProductCategory.ADD_ON);
    addOn1.setBillingPeriod(BillingPeriod.MONTHLY);
    addOn1.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final Subscription addOn2 = new Subscription();
    addOn2.setAccountId(accountJson.getAccountId());
    addOn2.setProductName("Laser-Scope");
    addOn2.setProductCategory(ProductCategory.ADD_ON);
    addOn2.setBillingPeriod(BillingPeriod.MONTHLY);
    addOn2.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final List<Subscription> subscriptions = new ArrayList<Subscription>();
    subscriptions.add(base);
    subscriptions.add(addOn1);
    subscriptions.add(addOn2);
    final List<BulkBaseSubscriptionAndAddOns> bulkList = new ArrayList<BulkBaseSubscriptionAndAddOns>();
    bulkList.add(new BulkBaseSubscriptionAndAddOns(subscriptions));
    bulkList.add(new BulkBaseSubscriptionAndAddOns(subscriptions));
    final Bundles bundles = killBillClient.createSubscriptionsWithAddOns(bulkList, null, 10, requestOptions);
    assertNotNull(bundles);
    assertEquals(bundles.size(), 2);
    assertFalse(bundles.get(0).getExternalKey().equals(bundles.get(1).getExternalKey()));
    final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, false, false, requestOptions);
    assertEquals(invoices.size(), 1);
}
Also used : Account(org.killbill.billing.client.model.Account) BulkBaseSubscriptionAndAddOns(org.killbill.billing.client.model.BulkBaseSubscriptionAndAddOns) Invoice(org.killbill.billing.client.model.Invoice) ArrayList(java.util.ArrayList) Subscription(org.killbill.billing.client.model.Subscription) DateTime(org.joda.time.DateTime) Bundles(org.killbill.billing.client.model.Bundles) Test(org.testng.annotations.Test)

Example 8 with Invoice

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

the class TestEntitlement method testEntitlementWithAddOns.

@Test(groups = "slow", description = "Create a base entitlement and also addOns entitlements under the same bundle")
public void testEntitlementWithAddOns() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithDefaultPaymentMethod();
    final Subscription base = new Subscription();
    base.setAccountId(accountJson.getAccountId());
    base.setExternalKey("base");
    base.setProductName("Shotgun");
    base.setProductCategory(ProductCategory.BASE);
    base.setBillingPeriod(BillingPeriod.MONTHLY);
    base.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final Subscription addOn1 = new Subscription();
    addOn1.setAccountId(accountJson.getAccountId());
    addOn1.setExternalKey("");
    addOn1.setProductName("Telescopic-Scope");
    addOn1.setProductCategory(ProductCategory.ADD_ON);
    addOn1.setBillingPeriod(BillingPeriod.MONTHLY);
    addOn1.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final Subscription addOn2 = new Subscription();
    addOn2.setAccountId(accountJson.getAccountId());
    addOn2.setExternalKey("");
    addOn2.setProductName("Laser-Scope");
    addOn2.setProductCategory(ProductCategory.ADD_ON);
    addOn2.setBillingPeriod(BillingPeriod.MONTHLY);
    addOn2.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final List<Subscription> subscriptions = new ArrayList<Subscription>();
    subscriptions.add(base);
    subscriptions.add(addOn1);
    subscriptions.add(addOn2);
    final Bundle bundle = killBillClient.createSubscriptionWithAddOns(subscriptions, null, 10, "createdBy", "", "");
    assertNotNull(bundle);
    assertEquals(bundle.getExternalKey(), "base");
    assertEquals(bundle.getSubscriptions().size(), 3);
    final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, false, false, AuditLevel.FULL);
    assertEquals(invoices.size(), 1);
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) Bundle(org.killbill.billing.client.model.Bundle) ArrayList(java.util.ArrayList) Subscription(org.killbill.billing.client.model.Subscription) DateTime(org.joda.time.DateTime) 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