Search in sources :

Example 6 with Bundles

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

the class TestEntitlement method testEntitlementsWithAddOnsAndAlreadyExistingBP.

@Test(groups = "slow", description = "Create addOns in a bundle where BP subscription already exist")
public void testEntitlementsWithAddOnsAndAlreadyExistingBP() 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 input = new Subscription();
    input.setAccountId(accountJson.getAccountId());
    input.setBundleExternalKey("foobarxyz");
    input.setProductName("Shotgun");
    input.setProductCategory(ProductCategory.BASE);
    input.setBillingPeriod(BillingPeriod.MONTHLY);
    input.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final Subscription subscription = subscriptionApi.createSubscription(input, null, null, null, null, null, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
    final Subscription addOn1 = new Subscription();
    addOn1.setAccountId(accountJson.getAccountId());
    addOn1.setBundleId(subscription.getBundleId());
    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.setBundleId(subscription.getBundleId());
    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(addOn1);
    subscriptions.add(addOn2);
    final BulkSubscriptionsBundles bulkSubscriptionsBundles = new BulkSubscriptionsBundles();
    final BulkSubscriptionsBundle bulkSubscriptionsBundle = new BulkSubscriptionsBundle();
    bulkSubscriptionsBundle.setBaseEntitlementAndAddOns(subscriptions);
    bulkSubscriptionsBundles.add(bulkSubscriptionsBundle);
    final Bundles bundles = subscriptionApi.createSubscriptionsWithAddOns(bulkSubscriptionsBundles, null, null, false, false, null, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertNotNull(bundles);
    assertEquals(bundles.size(), 1);
    assertEquals(bundles.get(0).getSubscriptions().size(), 3);
    final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
    assertEquals(invoices.size(), 2);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Invoice(org.killbill.billing.client.model.gen.Invoice) ArrayList(java.util.ArrayList) BulkSubscriptionsBundle(org.killbill.billing.client.model.gen.BulkSubscriptionsBundle) BulkSubscriptionsBundles(org.killbill.billing.client.model.BulkSubscriptionsBundles) Subscription(org.killbill.billing.client.model.gen.Subscription) DateTime(org.joda.time.DateTime) BulkSubscriptionsBundles(org.killbill.billing.client.model.BulkSubscriptionsBundles) Bundles(org.killbill.billing.client.model.Bundles) Test(org.testng.annotations.Test)

Example 7 with Bundles

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

the class TestEntitlement method testCreateEntitlementsWithAddOnsThenCloseAccountWithItemAdjustment.

@Test(groups = "slow", description = "Create a bulk of base entitlement and addOns under the same transaction")
public void testCreateEntitlementsWithAddOnsThenCloseAccountWithItemAdjustment() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccount();
    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 BulkSubscriptionsBundle bulkList = new BulkSubscriptionsBundle();
    bulkList.setBaseEntitlementAndAddOns(subscriptions);
    final BulkSubscriptionsBundles input = new BulkSubscriptionsBundles();
    input.add(bulkList);
    input.add(bulkList);
    callbackServlet.pushExpectedEvents(ExtBusEventType.ACCOUNT_CHANGE, ExtBusEventType.ENTITLEMENT_CREATION, ExtBusEventType.ENTITLEMENT_CREATION, ExtBusEventType.ENTITLEMENT_CREATION, ExtBusEventType.ENTITLEMENT_CREATION, ExtBusEventType.ENTITLEMENT_CREATION, ExtBusEventType.ENTITLEMENT_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_FAILED);
    final Bundles bundles = subscriptionApi.createSubscriptionsWithAddOns(input, null, null, false, false, null, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
    callbackServlet.assertListenerStatus();
    assertNotNull(bundles);
    assertEquals(bundles.size(), 2);
    assertFalse(bundles.get(0).getExternalKey().equals(bundles.get(1).getExternalKey()));
    final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
    assertEquals(invoices.size(), 1);
    assertEquals(invoices.get(0).getBalance().compareTo(BigDecimal.ZERO), 1);
    assertEquals(invoiceApi.getInvoiceTags(invoices.get(0).getInvoiceId(), requestOptions).size(), 0);
    final Bundles accountBundles = accountApi.getAccountBundles(accountJson.getAccountId(), null, null, requestOptions);
    assertEquals(accountBundles.size(), 2);
    for (final Bundle bundle : accountBundles) {
        for (final Subscription subscription : bundle.getSubscriptions()) {
            assertEquals(subscription.getState(), EntitlementState.ACTIVE);
        }
    }
    clock.addDays(1);
    callbackServlet.assertListenerStatus();
    callbackServlet.pushExpectedEvents(ExtBusEventType.TAG_CREATION, ExtBusEventType.ENTITLEMENT_CANCEL, ExtBusEventType.ENTITLEMENT_CANCEL, ExtBusEventType.ENTITLEMENT_CANCEL, ExtBusEventType.ENTITLEMENT_CANCEL, ExtBusEventType.ENTITLEMENT_CANCEL, ExtBusEventType.ENTITLEMENT_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.INVOICE_ADJUSTMENT, ExtBusEventType.INVOICE_ADJUSTMENT, ExtBusEventType.INVOICE_ADJUSTMENT, ExtBusEventType.INVOICE_ADJUSTMENT, ExtBusEventType.BLOCKING_STATE);
    accountApi.closeAccount(accountJson.getAccountId(), true, false, true, true, requestOptions);
    callbackServlet.assertListenerStatus();
    final Bundles accountBundlesAfterClose = accountApi.getAccountBundles(accountJson.getAccountId(), null, null, requestOptions);
    assertEquals(accountBundlesAfterClose.size(), 2);
    for (final Bundle bundle : accountBundlesAfterClose) {
        for (final Subscription subscription : bundle.getSubscriptions()) {
            assertEquals(subscription.getState(), EntitlementState.CANCELLED);
        }
    }
    final List<Invoice> invoicesAfterClose = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
    assertEquals(invoicesAfterClose.size(), 1);
    assertEquals(invoicesAfterClose.get(0).getBalance().compareTo(BigDecimal.ZERO), 0);
    assertEquals(invoiceApi.getInvoiceTags(invoicesAfterClose.get(0).getInvoiceId(), requestOptions).size(), 0);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Invoice(org.killbill.billing.client.model.gen.Invoice) BulkSubscriptionsBundle(org.killbill.billing.client.model.gen.BulkSubscriptionsBundle) Bundle(org.killbill.billing.client.model.gen.Bundle) ArrayList(java.util.ArrayList) BulkSubscriptionsBundle(org.killbill.billing.client.model.gen.BulkSubscriptionsBundle) BulkSubscriptionsBundles(org.killbill.billing.client.model.BulkSubscriptionsBundles) Subscription(org.killbill.billing.client.model.gen.Subscription) DateTime(org.joda.time.DateTime) BulkSubscriptionsBundles(org.killbill.billing.client.model.BulkSubscriptionsBundles) Bundles(org.killbill.billing.client.model.Bundles) Test(org.testng.annotations.Test)

Example 8 with Bundles

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

the class TestEntitlement method testEntitlementWithAddOnsWithWRITTEN_OFF.

@Test(groups = "slow", description = "Create a base entitlement and also addOns entitlements under the same bundle")
public void testEntitlementWithAddOnsWithWRITTEN_OFF() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final String bundleExternalKey = "bundleKey12346542";
    final Account accountJson = createAccount();
    final Subscription base = new Subscription();
    base.setAccountId(accountJson.getAccountId());
    base.setBundleExternalKey(bundleExternalKey);
    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");
    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");
    addOn2.setProductName("Laser-Scope");
    addOn2.setProductCategory(ProductCategory.ADD_ON);
    addOn2.setBillingPeriod(BillingPeriod.MONTHLY);
    addOn2.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final Subscriptions subscriptions = new Subscriptions();
    subscriptions.add(base);
    subscriptions.add(addOn1);
    subscriptions.add(addOn2);
    final Bundle bundle = subscriptionApi.createSubscriptionWithAddOns(subscriptions, null, null, null, null, null, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertNotNull(bundle);
    assertEquals(bundle.getExternalKey(), bundleExternalKey);
    assertEquals(bundle.getSubscriptions().size(), 3);
    int found = 0;
    for (int i = 0; i < 3; i++) {
        final Subscription cur = bundle.getSubscriptions().get(i);
        assertEquals(cur.getBundleExternalKey(), bundleExternalKey);
        if ("Shotgun".equals(cur.getProductName())) {
            assertEquals(cur.getExternalKey(), "Base");
            found++;
        } else if ("Telescopic-Scope".equals(cur.getProductName())) {
            assertEquals(cur.getExternalKey(), "addOn1");
            found++;
        } else if ("Laser-Scope".equals(cur.getProductName())) {
            assertEquals(cur.getExternalKey(), "addOn2");
            found++;
        }
    }
    assertEquals(found, 3);
    final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
    assertEquals(invoices.size(), 1);
    assertEquals(invoices.get(0).getBalance().compareTo(BigDecimal.ZERO), 1);
    assertEquals(invoiceApi.getInvoiceTags(invoices.get(0).getInvoiceId(), requestOptions).size(), 0);
    final Bundles accountBundles = accountApi.getAccountBundles(accountJson.getAccountId(), null, null, requestOptions);
    assertEquals(accountBundles.size(), 1);
    for (final Subscription subscription : accountBundles.get(0).getSubscriptions()) {
        assertEquals(subscription.getState(), EntitlementState.ACTIVE);
    }
    accountApi.closeAccount(accountJson.getAccountId(), true, true, false, true, requestOptions);
    final Bundles accountBundlesAfterClose = accountApi.getAccountBundles(accountJson.getAccountId(), null, null, requestOptions);
    assertEquals(accountBundlesAfterClose.size(), 1);
    for (final Subscription subscription : accountBundlesAfterClose.get(0).getSubscriptions()) {
        assertEquals(subscription.getState(), EntitlementState.CANCELLED);
    }
    final List<Invoice> invoicesAfterClose = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
    assertEquals(invoicesAfterClose.size(), 1);
    assertEquals(invoicesAfterClose.get(0).getBalance().compareTo(BigDecimal.ZERO), 0);
    assertEquals(invoiceApi.getInvoiceTags(invoicesAfterClose.get(0).getInvoiceId(), requestOptions).size(), 1);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Invoice(org.killbill.billing.client.model.gen.Invoice) Subscriptions(org.killbill.billing.client.model.Subscriptions) BulkSubscriptionsBundle(org.killbill.billing.client.model.gen.BulkSubscriptionsBundle) Bundle(org.killbill.billing.client.model.gen.Bundle) Subscription(org.killbill.billing.client.model.gen.Subscription) DateTime(org.joda.time.DateTime) BulkSubscriptionsBundles(org.killbill.billing.client.model.BulkSubscriptionsBundles) Bundles(org.killbill.billing.client.model.Bundles) Test(org.testng.annotations.Test)

Example 9 with Bundles

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

the class TestEntitlement method testCreateSubscriptionsWithoutBase.

@Test(groups = "slow", description = "Create a bulk of base entitlements and addOns under the same transaction", expectedExceptions = KillBillClientException.class, expectedExceptionsMessageRegExp = "SubscriptionJson productName needs to be set when no planName is specified")
public void testCreateSubscriptionsWithoutBase() 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 bp1 = new Subscription();
    bp1.setAccountId(accountJson.getAccountId());
    bp1.setProductCategory(ProductCategory.BASE);
    bp1.setBundleExternalKey("12345");
    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 List<Subscription> subscriptions1 = new ArrayList<Subscription>();
    subscriptions1.add(bp1);
    subscriptions1.add(addOn1);
    final Subscription bp2 = new Subscription();
    bp2.setAccountId(accountJson.getAccountId());
    bp2.setProductCategory(ProductCategory.BASE);
    bp2.setBundleExternalKey("54321");
    final Subscription addOn2 = new Subscription();
    addOn2.setAccountId(accountJson.getAccountId());
    addOn2.setProductName("Telescopic-Scope");
    addOn2.setProductCategory(ProductCategory.ADD_ON);
    addOn2.setBillingPeriod(BillingPeriod.MONTHLY);
    addOn2.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final List<Subscription> subscriptions2 = new ArrayList<Subscription>();
    subscriptions2.add(bp1);
    subscriptions2.add(addOn1);
    final BulkSubscriptionsBundle bulkList1 = new BulkSubscriptionsBundle();
    bulkList1.setBaseEntitlementAndAddOns(subscriptions1);
    final BulkSubscriptionsBundle bulkList2 = new BulkSubscriptionsBundle();
    bulkList2.setBaseEntitlementAndAddOns(subscriptions2);
    final BulkSubscriptionsBundles input = new BulkSubscriptionsBundles();
    input.add(bulkList1);
    input.add(bulkList2);
    final Bundles res = subscriptionApi.createSubscriptionsWithAddOns(input, null, null, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(res.size(), 2);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) ArrayList(java.util.ArrayList) BulkSubscriptionsBundle(org.killbill.billing.client.model.gen.BulkSubscriptionsBundle) BulkSubscriptionsBundles(org.killbill.billing.client.model.BulkSubscriptionsBundles) Subscription(org.killbill.billing.client.model.gen.Subscription) DateTime(org.joda.time.DateTime) BulkSubscriptionsBundles(org.killbill.billing.client.model.BulkSubscriptionsBundles) Bundles(org.killbill.billing.client.model.Bundles) Test(org.testng.annotations.Test)

Aggregations

Bundles (org.killbill.billing.client.model.Bundles)9 Test (org.testng.annotations.Test)9 DateTime (org.joda.time.DateTime)8 Account (org.killbill.billing.client.model.gen.Account)8 Subscription (org.killbill.billing.client.model.gen.Subscription)7 BulkSubscriptionsBundles (org.killbill.billing.client.model.BulkSubscriptionsBundles)5 Bundle (org.killbill.billing.client.model.gen.Bundle)5 ArrayList (java.util.ArrayList)4 BulkSubscriptionsBundle (org.killbill.billing.client.model.gen.BulkSubscriptionsBundle)4 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)3 Invoice (org.killbill.billing.client.model.gen.Invoice)3 BigDecimal (java.math.BigDecimal)1 LocalDate (org.joda.time.LocalDate)1 Account (org.killbill.billing.client.model.Account)1 BlockingStates (org.killbill.billing.client.model.BlockingStates)1 BulkBaseSubscriptionAndAddOns (org.killbill.billing.client.model.BulkBaseSubscriptionAndAddOns)1 Invoice (org.killbill.billing.client.model.Invoice)1 Subscription (org.killbill.billing.client.model.Subscription)1 Subscriptions (org.killbill.billing.client.model.Subscriptions)1 BlockingState (org.killbill.billing.client.model.gen.BlockingState)1