Search in sources :

Example 1 with BulkSubscriptionsBundles

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

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

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

ArrayList (java.util.ArrayList)3 DateTime (org.joda.time.DateTime)3 BulkSubscriptionsBundles (org.killbill.billing.client.model.BulkSubscriptionsBundles)3 Bundles (org.killbill.billing.client.model.Bundles)3 Account (org.killbill.billing.client.model.gen.Account)3 BulkSubscriptionsBundle (org.killbill.billing.client.model.gen.BulkSubscriptionsBundle)3 Subscription (org.killbill.billing.client.model.gen.Subscription)3 Test (org.testng.annotations.Test)3 Invoice (org.killbill.billing.client.model.gen.Invoice)2 Bundle (org.killbill.billing.client.model.gen.Bundle)1