Search in sources :

Example 1 with Product

use of org.killbill.billing.catalog.api.Product in project killbill by killbill.

the class TestTransfer method testTransferWithAO.

@Test(groups = "slow")
public void testTransferWithAO() throws Exception {
    final String baseProduct = "Shotgun";
    final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
    final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
    // CREATE BP
    final SubscriptionBase baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
    // MOVE 3 DAYS AND CREATE AO1
    clock.addDays(3);
    final String aoProduct1 = "Telescopic-Scope";
    final BillingPeriod aoTerm1 = BillingPeriod.MONTHLY;
    final DefaultSubscriptionBase aoSubscription1 = testUtil.createSubscription(bundle, aoProduct1, aoTerm1, basePriceList);
    assertEquals(aoSubscription1.getState(), EntitlementState.ACTIVE);
    // MOVE ANOTHER 25 DAYS AND CREATE AO2 [ BP STILL IN TRIAL]
    // LASER-SCOPE IS SUBSCRIPTION ALIGN SO EVERGREN WILL ONLY START IN A MONTH
    clock.addDays(25);
    final String aoProduct2 = "Laser-Scope";
    final BillingPeriod aoTerm2 = BillingPeriod.MONTHLY;
    final DefaultSubscriptionBase aoSubscription2 = testUtil.createSubscription(bundle, aoProduct2, aoTerm2, basePriceList);
    assertEquals(aoSubscription2.getState(), EntitlementState.ACTIVE);
    // MOVE AFTER TRIAL AND AO DISCOUNT PHASE [LASER SCOPE STILL IN DISCOUNT]
    testListener.pushExpectedEvent(NextEvent.PHASE);
    testListener.pushExpectedEvent(NextEvent.PHASE);
    clock.addDays(5);
    assertListenerStatus();
    // SET CTD TO TRIGGER CANCELLATION EOT
    final DateTime ctd = baseSubscription.getStartDate().plusDays(30).plusMonths(1);
    subscriptionInternalApi.setChargedThroughDate(baseSubscription.getId(), ctd, internalCallContext);
    final DateTime transferRequestedDate = clock.getUTCNow();
    testListener.pushExpectedEvent(NextEvent.TRANSFER);
    testListener.pushExpectedEvent(NextEvent.TRANSFER);
    testListener.pushExpectedEvent(NextEvent.TRANSFER);
    transferApi.transferBundle(bundle.getAccountId(), newAccountId, bundle.getExternalKey(), transferRequestedDate, true, false, callContext);
    assertListenerStatus();
    // RETRIEVE NEW BUNDLE AND CHECK SUBSCRIPTIONS
    final List<SubscriptionBaseBundle> bundlesForAccountAndKey = subscriptionInternalApi.getBundlesForAccountAndKey(newAccountId, bundle.getExternalKey(), internalCallContext);
    assertEquals(bundlesForAccountAndKey.size(), 1);
    final SubscriptionBaseBundle newBundle = bundlesForAccountAndKey.get(0);
    final List<SubscriptionBase> subscriptions = subscriptionInternalApi.getSubscriptionsForBundle(newBundle.getId(), null, internalCallContext);
    assertEquals(subscriptions.size(), 3);
    boolean foundBP = false;
    boolean foundAO1 = false;
    boolean foundAO2 = false;
    for (final SubscriptionBase cur : subscriptions) {
        final Plan curPlan = cur.getCurrentPlan();
        final Product curProduct = curPlan.getProduct();
        if (curProduct.getName().equals(baseProduct)) {
            foundBP = true;
            assertTrue(((DefaultSubscriptionBase) cur).getAlignStartDate().compareTo(((DefaultSubscriptionBase) baseSubscription).getAlignStartDate()) == 0);
            assertNull(cur.getPendingTransition());
        } else if (curProduct.getName().equals(aoProduct1)) {
            foundAO1 = true;
            assertTrue(((DefaultSubscriptionBase) cur).getAlignStartDate().compareTo((aoSubscription1).getAlignStartDate()) == 0);
            assertNull(cur.getPendingTransition());
        } else if (curProduct.getName().equals(aoProduct2)) {
            foundAO2 = true;
            assertTrue(((DefaultSubscriptionBase) cur).getAlignStartDate().compareTo((aoSubscription2).getAlignStartDate()) == 0);
            assertNotNull(cur.getPendingTransition());
        } else {
            Assert.fail("Unexpected product " + curProduct.getName());
        }
    }
    assertTrue(foundBP);
    assertTrue(foundAO1);
    assertTrue(foundAO2);
    // MOVE AFTER CANCEL DATE TO TRIGGER OLD SUBSCRIPTIONS CANCELLATION + LASER_SCOPE PHASE EVENT
    testListener.pushExpectedEvents(NextEvent.PHASE, NextEvent.PHASE);
    testListener.pushExpectedEvent(NextEvent.CANCEL);
    testListener.pushExpectedEvent(NextEvent.CANCEL);
    testListener.pushExpectedEvent(NextEvent.CANCEL);
    clock.addMonths(1);
    assertListenerStatus();
    // ISSUE ANOTHER TRANSFER TO CHECK THAT WE CAN TRANSFER AGAIN-- NOTE WILL NOT WORK ON PREVIOUS ACCOUNT (LIMITATION)
    final DateTime newTransferRequestedDate = clock.getUTCNow();
    testListener.pushExpectedEvent(NextEvent.CANCEL);
    testListener.pushExpectedEvent(NextEvent.TRANSFER);
    testListener.pushExpectedEvent(NextEvent.TRANSFER);
    testListener.pushExpectedEvent(NextEvent.TRANSFER);
    transferApi.transferBundle(newBundle.getAccountId(), finalNewAccountId, newBundle.getExternalKey(), newTransferRequestedDate, true, false, callContext);
    assertListenerStatus();
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) SubscriptionBaseBundle(org.killbill.billing.subscription.api.user.SubscriptionBaseBundle) Product(org.killbill.billing.catalog.api.Product) DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) Plan(org.killbill.billing.catalog.api.Plan) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 2 with Product

use of org.killbill.billing.catalog.api.Product in project killbill by killbill.

the class AddonUtils method isAddonIncludedFromPlanName.

public boolean isAddonIncludedFromPlanName(final String basePlanName, final Plan targetAddOnPlan, final DateTime requestedDate, final InternalTenantContext context) {
    try {
        final Plan plan = catalogService.getFullCatalog(true, true, context).findPlan(basePlanName, requestedDate);
        final Product product = plan.getProduct();
        return isAddonIncluded(product, targetAddOnPlan);
    } catch (CatalogApiException e) {
        throw new SubscriptionBaseError(e);
    }
}
Also used : SubscriptionBaseError(org.killbill.billing.subscription.exceptions.SubscriptionBaseError) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) Product(org.killbill.billing.catalog.api.Product) Plan(org.killbill.billing.catalog.api.Plan)

Example 3 with Product

use of org.killbill.billing.catalog.api.Product in project killbill by killbill.

the class AddonUtils method isAddonIncluded.

private boolean isAddonIncluded(final Product baseProduct, final Plan targetAddOnPlan) {
    final Product targetAddonProduct = targetAddOnPlan.getProduct();
    final Collection<Product> includedAddOns = baseProduct.getIncluded();
    for (final Product curAv : includedAddOns) {
        if (curAv.getName().equals(targetAddonProduct.getName())) {
            return true;
        }
    }
    return false;
}
Also used : Product(org.killbill.billing.catalog.api.Product)

Example 4 with Product

use of org.killbill.billing.catalog.api.Product in project killbill by killbill.

the class StandaloneCatalogMapper method toStandaloneCatalog.

public StandaloneCatalog toStandaloneCatalog(final StandalonePluginCatalog pluginCatalog, @Nullable URI catalogURI) {
    final StandaloneCatalog result = new StandaloneCatalog();
    result.setCatalogName(catalogName);
    result.setEffectiveDate(pluginCatalog.getEffectiveDate().toDate());
    result.setProducts(toDefaultProducts(pluginCatalog.getProducts()));
    result.setPlans(toDefaultPlans(pluginCatalog.getPlans()));
    result.setPriceLists(toDefaultPriceListSet(pluginCatalog.getDefaultPriceList(), pluginCatalog.getChildrenPriceList()));
    result.setRecurringBillingMode(recurringBillingMode);
    result.setSupportedCurrencies(toArray(pluginCatalog.getCurrencies()));
    result.setUnits(toDefaultUnits(pluginCatalog.getUnits()));
    result.setPlanRules(toDefaultPlanRules(pluginCatalog.getPlanRules()));
    for (final Product cur : pluginCatalog.getProducts()) {
        final Product target = result.getCatalogEntityCollectionProduct().findByName(cur.getName());
        if (target != null) {
            ((DefaultProduct) target).setAvailable(toFilteredDefaultProduct(cur.getAvailable()));
            ((DefaultProduct) target).setIncluded(toFilteredDefaultProduct(cur.getIncluded()));
        }
    }
    result.initialize(result, catalogURI);
    return result;
}
Also used : DefaultProduct(org.killbill.billing.catalog.DefaultProduct) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) DefaultProduct(org.killbill.billing.catalog.DefaultProduct) Product(org.killbill.billing.catalog.api.Product)

Example 5 with Product

use of org.killbill.billing.catalog.api.Product in project killbill by killbill.

the class StandaloneCatalogMapper method toDefaultProducts.

private Iterable<Product> toDefaultProducts(final Iterable<Product> input) {
    if (tmpDefaultProducts == null) {
        final Map<String, Product> map = new HashMap<String, Product>();
        for (final Product product : input) map.put(product.getName(), toDefaultProduct(product));
        tmpDefaultProducts = map;
    }
    return tmpDefaultProducts.values();
}
Also used : HashMap(java.util.HashMap) DefaultProduct(org.killbill.billing.catalog.DefaultProduct) Product(org.killbill.billing.catalog.api.Product)

Aggregations

Product (org.killbill.billing.catalog.api.Product)29 Plan (org.killbill.billing.catalog.api.Plan)15 DefaultProduct (org.killbill.billing.catalog.DefaultProduct)8 PriceList (org.killbill.billing.catalog.api.PriceList)7 Test (org.testng.annotations.Test)6 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)5 DateTime (org.joda.time.DateTime)4 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)4 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)4 ArrayList (java.util.ArrayList)3 ProductCategory (org.killbill.billing.catalog.api.ProductCategory)3 SubscriptionBaseEvent (org.killbill.billing.subscription.events.SubscriptionBaseEvent)3 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)2 DefaultPriceList (org.killbill.billing.catalog.DefaultPriceList)2 StandaloneCatalog (org.killbill.billing.catalog.StandaloneCatalog)2 StandaloneCatalogWithPriceOverride (org.killbill.billing.catalog.StandaloneCatalogWithPriceOverride)2 VersionedCatalog (org.killbill.billing.catalog.VersionedCatalog)2 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)2 SimplePlanDescriptor (org.killbill.billing.catalog.api.SimplePlanDescriptor)2 DefaultSimplePlanDescriptor (org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor)2