Search in sources :

Example 1 with Bundles

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

the class TestBundle method testBundlesPagination.

@Test(groups = "slow", description = "Can paginate and search through all bundles")
public void testBundlesPagination() throws Exception {
    final Account accountJson = createAccount();
    for (int i = 0; i < 5; i++) {
        createSubscription(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
    }
    final Bundles allBundles = bundleApi.getBundles(requestOptions);
    Assert.assertEquals(allBundles.size(), 5);
    for (final Bundle bundle : allBundles) {
        Assert.assertEquals(bundleApi.searchBundles(bundle.getBundleId().toString(), requestOptions).size(), 1);
        Assert.assertEquals(bundleApi.searchBundles(bundle.getAccountId().toString(), requestOptions).size(), 5);
        Assert.assertEquals(bundleApi.searchBundles(bundle.getExternalKey(), requestOptions).size(), 1);
    }
    Bundles page = bundleApi.getBundles(0L, 1L, AuditLevel.NONE, requestOptions);
    for (int i = 0; i < 5; i++) {
        Assert.assertNotNull(page);
        Assert.assertEquals(page.size(), 1);
        Assert.assertEquals(page.get(0), allBundles.get(i));
        page = page.getNext();
    }
    Assert.assertNull(page);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Bundle(org.killbill.billing.client.model.gen.Bundle) Bundles(org.killbill.billing.client.model.Bundles) Test(org.testng.annotations.Test)

Example 2 with Bundles

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

the class TestBundle method testBlockBundle.

@Test(groups = "slow", description = "Block a bundle")
public void testBlockBundle() 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 String productName = "Shotgun";
    final BillingPeriod term = BillingPeriod.MONTHLY;
    final String bundleExternalKey = "93199";
    final Subscription entitlement = createSubscription(accountJson.getAccountId(), bundleExternalKey, productName, ProductCategory.BASE, term);
    Bundles existingBundles = bundleApi.getBundleByKey(bundleExternalKey, requestOptions);
    assertEquals(existingBundles.size(), 1);
    final Bundle bundle = existingBundles.get(0);
    assertEquals(bundle.getAccountId(), accountJson.getAccountId());
    assertEquals(bundle.getExternalKey(), bundleExternalKey);
    final BlockingState blockingState = new BlockingState(bundle.getBundleId(), "block", "service", false, true, true, null, BlockingStateType.SUBSCRIPTION_BUNDLE, null);
    bundleApi.addBundleBlockingState(bundle.getBundleId(), blockingState, clock.getToday(DateTimeZone.forID(accountJson.getTimeZone())), ImmutableMap.<String, String>of(), requestOptions);
    final Subscription subscription = subscriptionApi.getSubscription(entitlement.getSubscriptionId(), requestOptions);
    assertEquals(subscription.getState(), EntitlementState.BLOCKED);
    clock.addDays(1);
    final BlockingState unblockingState = new BlockingState(bundle.getBundleId(), "unblock", "service", false, false, false, null, BlockingStateType.SUBSCRIPTION_BUNDLE, null);
    bundleApi.addBundleBlockingState(bundle.getBundleId(), unblockingState, clock.getToday(DateTimeZone.forID(accountJson.getTimeZone())), ImmutableMap.<String, String>of(), requestOptions);
    final Subscription subscription2 = subscriptionApi.getSubscription(entitlement.getSubscriptionId(), requestOptions);
    assertEquals(subscription2.getState(), EntitlementState.ACTIVE);
    final BlockingStates blockingStates = accountApi.getBlockingStates(accountJson.getAccountId(), null, ImmutableList.<String>of("service"), AuditLevel.FULL, requestOptions);
    Assert.assertEquals(blockingStates.size(), 2);
    final BlockingStates blockingStates2 = accountApi.getBlockingStates(accountJson.getAccountId(), ImmutableList.<BlockingStateType>of(BlockingStateType.SUBSCRIPTION_BUNDLE), null, AuditLevel.FULL, requestOptions);
    Assert.assertEquals(blockingStates2.size(), 2);
    final BlockingStates blockingStates3 = accountApi.getBlockingStates(accountJson.getAccountId(), null, null, AuditLevel.FULL, requestOptions);
    Assert.assertEquals(blockingStates3.size(), 3);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) BlockingStates(org.killbill.billing.client.model.BlockingStates) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) Bundle(org.killbill.billing.client.model.gen.Bundle) BlockingState(org.killbill.billing.client.model.gen.BlockingState) Subscription(org.killbill.billing.client.model.gen.Subscription) DateTime(org.joda.time.DateTime) Bundles(org.killbill.billing.client.model.Bundles) Test(org.testng.annotations.Test)

Example 3 with Bundles

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

the class TestBundle method testBundleTransfer.

@Test(groups = "slow", description = "Can transfer bundle")
public void testBundleTransfer() 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 String productName = "Shotgun";
    final BillingPeriod term = BillingPeriod.MONTHLY;
    final String bundleExternalKey = "93199";
    final Subscription entitlementJsonNoEvents = createSubscription(accountJson.getAccountId(), bundleExternalKey, productName, ProductCategory.BASE, term);
    Bundles existingBundles = bundleApi.getBundleByKey(bundleExternalKey, requestOptions);
    assertEquals(existingBundles.size(), 1);
    Bundle originalBundle = existingBundles.get(0);
    existingBundles = bundleApi.getBundleByKey(bundleExternalKey, requestOptions);
    assertEquals(existingBundles.size(), 1);
    originalBundle = existingBundles.get(0);
    assertEquals(originalBundle.getAccountId(), accountJson.getAccountId());
    assertEquals(originalBundle.getAccountId(), accountJson.getAccountId());
    assertEquals(originalBundle.getExternalKey(), bundleExternalKey);
    final Account newAccount = createAccountWithDefaultPaymentMethod();
    final Bundle bundle = new Bundle();
    bundle.setAccountId(newAccount.getAccountId());
    bundle.setBundleId(entitlementJsonNoEvents.getBundleId());
    bundleApi.transferBundle(entitlementJsonNoEvents.getBundleId(), bundle, null, NULL_PLUGIN_PROPERTIES, requestOptions);
    existingBundles = bundleApi.getBundleByKey(bundleExternalKey, requestOptions);
    assertEquals(existingBundles.size(), 1);
    final Bundle newBundle = existingBundles.get(0);
    assertNotEquals(newBundle.getBundleId(), originalBundle.getBundleId());
    assertEquals(newBundle.getExternalKey(), originalBundle.getExternalKey());
    assertEquals(newBundle.getAccountId(), newAccount.getAccountId());
    final Bundles bundles = bundleApi.getBundleByKey(bundleExternalKey, true, AuditLevel.NONE, requestOptions);
    assertEquals(bundles.size(), 2);
    assertSubscriptionState(bundles, originalBundle.getBundleId(), EntitlementState.CANCELLED);
    assertSubscriptionState(bundles, newBundle.getBundleId(), EntitlementState.ACTIVE);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) Bundle(org.killbill.billing.client.model.gen.Bundle) Subscription(org.killbill.billing.client.model.gen.Subscription) DateTime(org.joda.time.DateTime) Bundles(org.killbill.billing.client.model.Bundles) Test(org.testng.annotations.Test)

Example 4 with Bundles

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

the class TestEntitlement method testEntitlementInTrialOk.

@Test(groups = "slow", description = "Can change plan and cancel a subscription")
public void testEntitlementInTrialOk() 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 String productName = "Shotgun";
    final BillingPeriod term = BillingPeriod.MONTHLY;
    final Subscription entitlementJson = createSubscription(accountJson.getAccountId(), "99999", productName, ProductCategory.BASE, term);
    // Retrieves with GET
    Subscription subscription = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
    Assert.assertEquals(subscription.getPrices().size(), 2);
    Assert.assertEquals(subscription.getPrices().get(0).getFixedPrice(), BigDecimal.ZERO);
    Assert.assertNull(subscription.getPrices().get(0).getRecurringPrice());
    Assert.assertNull(subscription.getPrices().get(1).getFixedPrice());
    Assert.assertEquals(subscription.getPrices().get(1).getRecurringPrice(), new BigDecimal("249.95"));
    Assert.assertEquals(subscription, entitlementJson);
    final Subscription subscription2 = subscriptionApi.getSubscriptionByKey(subscription.getExternalKey(), requestOptions);
    assertEquals(subscription2.getBundleExternalKey(), "99999");
    assertEquals(subscription2.getExternalKey(), subscription.getExternalKey());
    // Change the clock otherwise the CREATE event might be replaced (instead of having a CHANGE event)
    clock.addDays(1);
    callbackServlet.assertListenerStatus();
    // Change plan IMM
    final String newProductName = "Assault-Rifle";
    final Subscription newInput = new Subscription();
    newInput.setAccountId(entitlementJson.getAccountId());
    newInput.setSubscriptionId(entitlementJson.getSubscriptionId());
    newInput.setProductName(newProductName);
    newInput.setProductCategory(ProductCategory.BASE);
    newInput.setBillingPeriod(entitlementJson.getBillingPeriod());
    newInput.setPriceList(entitlementJson.getPriceList());
    callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_CHANGE, ExtBusEventType.SUBSCRIPTION_CHANGE, ExtBusEventType.INVOICE_CREATION);
    subscriptionApi.changeSubscriptionPlan(entitlementJson.getSubscriptionId(), newInput, null, null, NULL_PLUGIN_PROPERTIES, requestOptions);
    callbackServlet.assertListenerStatus();
    Assert.assertNotNull(subscription);
    // MOVE AFTER TRIAL
    callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_SUCCESS, ExtBusEventType.PAYMENT_SUCCESS);
    clock.addDays(30);
    callbackServlet.assertListenerStatus();
    // Cancel IMM (Billing EOT)
    subscriptionApi.cancelSubscriptionPlan(newInput.getSubscriptionId(), null, null, null, NULL_PLUGIN_PROPERTIES, requestOptions);
    // Retrieves to check EndDate
    subscription = subscriptionApi.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
    assertNotNull(subscription.getCancelledDate());
    assertTrue(subscription.getCancelledDate().compareTo(new LocalDate(clock.getUTCNow())) == 0);
    final Bundles accountBundles = accountApi.getAccountBundles(accountJson.getAccountId(), null, null, requestOptions);
    assertEquals(accountBundles.size(), 1);
    assertEquals(accountBundles.get(0).getSubscriptions().size(), 1);
    assertEquals(accountBundles.get(0).getSubscriptions().get(0).getState(), EntitlementState.CANCELLED);
    final Bundles bundlesByKey1 = bundleApi.getBundleByKey(entitlementJson.getBundleExternalKey(), true, AuditLevel.NONE, requestOptions);
    assertEquals(bundlesByKey1.size(), 1);
    assertEquals(bundlesByKey1.get(0).getSubscriptions().size(), 1);
    assertEquals(bundlesByKey1.get(0).getSubscriptions().get(0).getState(), EntitlementState.CANCELLED);
    final Bundles bundlesByKey2 = bundleApi.getBundleByKey(entitlementJson.getBundleExternalKey(), requestOptions);
    assertNotNull(bundlesByKey2);
    assertEquals(bundlesByKey2.size(), 0);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) Subscription(org.killbill.billing.client.model.gen.Subscription) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) BulkSubscriptionsBundles(org.killbill.billing.client.model.BulkSubscriptionsBundles) Bundles(org.killbill.billing.client.model.Bundles) Test(org.testng.annotations.Test)

Example 5 with Bundles

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

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