Search in sources :

Example 1 with PriceList

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

the class TestCatalogUpdater method testAddPlanOnExistingCatalog.

@Test(groups = "fast")
public void testAddPlanOnExistingCatalog() throws Exception {
    final StandaloneCatalog originalCatalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarBasic.xml").toExternalForm(), StandaloneCatalog.class);
    assertEquals(originalCatalog.getPriceLists().getAllPriceLists().size(), 1);
    assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getName(), new PriceListDefault().getName());
    assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getPlans().size(), 3);
    final CatalogUpdater catalogUpdater = new CatalogUpdater(originalCatalog);
    final SimplePlanDescriptor desc = new DefaultSimplePlanDescriptor("standard-annual", "Standard", ProductCategory.BASE, Currency.USD, BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of());
    catalogUpdater.addSimplePlanDescriptor(desc);
    final StandaloneCatalog catalog = catalogUpdater.getCatalog();
    final Plan plan = catalog.findCurrentPlan("standard-annual");
    assertEquals(plan.getName(), "standard-annual");
    assertEquals(plan.getInitialPhases().length, 0);
    assertEquals(plan.getFinalPhase().getPhaseType(), PhaseType.EVERGREEN);
    assertNull(plan.getFinalPhase().getFixed());
    assertEquals(plan.getFinalPhase().getName(), "standard-annual-evergreen");
    assertEquals(plan.getFinalPhase().getRecurring().getBillingPeriod(), BillingPeriod.MONTHLY);
    assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices().length, 1);
    assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices()[0].getValue(), BigDecimal.TEN);
    assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices()[0].getCurrency(), Currency.USD);
    assertEquals(catalog.getPriceLists().getAllPriceLists().size(), 1);
    final PriceList priceList = catalog.getPriceLists().getAllPriceLists().get(0);
    assertEquals(priceList.getName(), new PriceListDefault().getName());
    assertEquals(priceList.getPlans().size(), 4);
}
Also used : Plan(org.killbill.billing.catalog.api.Plan) PriceList(org.killbill.billing.catalog.api.PriceList) SimplePlanDescriptor(org.killbill.billing.catalog.api.SimplePlanDescriptor) DefaultSimplePlanDescriptor(org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor) DefaultSimplePlanDescriptor(org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor) Test(org.testng.annotations.Test)

Example 2 with PriceList

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

the class TestCatalogUpdater method testAddNoTrialPlanOnFirstCatalog.

@Test(groups = "fast")
public void testAddNoTrialPlanOnFirstCatalog() throws CatalogApiException {
    final DateTime now = clock.getUTCNow();
    final SimplePlanDescriptor desc = new DefaultSimplePlanDescriptor("foo-monthly", "Foo", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of());
    final CatalogUpdater catalogUpdater = new CatalogUpdater(BillingMode.IN_ADVANCE, now, desc.getCurrency());
    catalogUpdater.addSimplePlanDescriptor(desc);
    final StandaloneCatalog catalog = catalogUpdater.getCatalog();
    assertEquals(catalog.getCurrentProducts().size(), 1);
    final Product product = catalog.getCurrentProducts().iterator().next();
    assertEquals(product.getName(), "Foo");
    assertEquals(product.getCategory(), ProductCategory.BASE);
    assertEquals(catalog.getCurrentPlans().size(), 1);
    final Plan plan = catalog.findCurrentPlan("foo-monthly");
    assertEquals(plan.getName(), "foo-monthly");
    assertEquals(plan.getInitialPhases().length, 0);
    assertEquals(plan.getFinalPhase().getPhaseType(), PhaseType.EVERGREEN);
    assertNull(plan.getFinalPhase().getFixed());
    assertEquals(plan.getFinalPhase().getName(), "foo-monthly-evergreen");
    assertEquals(plan.getFinalPhase().getRecurring().getBillingPeriod(), BillingPeriod.MONTHLY);
    assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices().length, 1);
    assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices()[0].getValue(), BigDecimal.TEN);
    assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices()[0].getCurrency(), Currency.EUR);
    assertEquals(catalog.getPriceLists().getAllPriceLists().size(), 1);
    final PriceList priceList = catalog.getPriceLists().getAllPriceLists().get(0);
    assertEquals(priceList.getName(), new PriceListDefault().getName());
    assertEquals(priceList.getPlans().size(), 1);
    assertEquals(priceList.getPlans().iterator().next().getName(), "foo-monthly");
}
Also used : Product(org.killbill.billing.catalog.api.Product) Plan(org.killbill.billing.catalog.api.Plan) PriceList(org.killbill.billing.catalog.api.PriceList) DateTime(org.joda.time.DateTime) SimplePlanDescriptor(org.killbill.billing.catalog.api.SimplePlanDescriptor) DefaultSimplePlanDescriptor(org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor) DefaultSimplePlanDescriptor(org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor) Test(org.testng.annotations.Test)

Example 3 with PriceList

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

the class DefaultCaseChange method getResult.

public T getResult(final PlanPhaseSpecifier from, final PlanSpecifier to, final StaticCatalog catalog) throws CatalogApiException {
    final Product inFromProduct;
    final BillingPeriod inFromBillingPeriod;
    final ProductCategory inFromProductCategory;
    final PriceList inFromPriceList;
    if (from.getPlanName() != null) {
        final Plan plan = catalog.findCurrentPlan(from.getPlanName());
        inFromProduct = plan.getProduct();
        inFromBillingPeriod = plan.getRecurringBillingPeriod();
        inFromProductCategory = plan.getProduct().getCategory();
        inFromPriceList = catalog.findCurrentPricelist(plan.getPriceListName());
    } else {
        inFromProduct = catalog.findCurrentProduct(from.getProductName());
        inFromBillingPeriod = from.getBillingPeriod();
        inFromProductCategory = inFromProduct.getCategory();
        inFromPriceList = from.getPriceListName() != null ? catalog.findCurrentPricelist(from.getPriceListName()) : null;
    }
    final Product inToProduct;
    final BillingPeriod inToBillingPeriod;
    final ProductCategory inToProductCategory;
    final PriceList inToPriceList;
    if (to.getPlanName() != null) {
        final Plan plan = catalog.findCurrentPlan(to.getPlanName());
        inToProduct = plan.getProduct();
        inToBillingPeriod = plan.getRecurringBillingPeriod();
        inToProductCategory = plan.getProduct().getCategory();
        inToPriceList = catalog.findCurrentPricelist(plan.getPriceListName());
    } else {
        inToProduct = catalog.findCurrentProduct(to.getProductName());
        inToBillingPeriod = to.getBillingPeriod();
        inToProductCategory = inToProduct.getCategory();
        inToPriceList = to.getPriceListName() != null ? catalog.findCurrentPricelist(to.getPriceListName()) : null;
    }
    if ((phaseType == null || from.getPhaseType() == phaseType) && (fromProduct == null || fromProduct.equals(inFromProduct)) && (fromProductCategory == null || fromProductCategory.equals(inFromProductCategory)) && (fromBillingPeriod == null || fromBillingPeriod.equals(inFromBillingPeriod)) && (this.toProduct == null || this.toProduct.equals(inToProduct)) && (this.toProductCategory == null || this.toProductCategory.equals(inToProductCategory)) && (this.toBillingPeriod == null || this.toBillingPeriod.equals(inToBillingPeriod)) && (fromPriceList == null || fromPriceList.equals(inFromPriceList)) && (toPriceList == null || toPriceList.equals(inToPriceList))) {
        return getResult();
    }
    return null;
}
Also used : BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) ProductCategory(org.killbill.billing.catalog.api.ProductCategory) DefaultProduct(org.killbill.billing.catalog.DefaultProduct) Product(org.killbill.billing.catalog.api.Product) Plan(org.killbill.billing.catalog.api.Plan) PriceList(org.killbill.billing.catalog.api.PriceList) DefaultPriceList(org.killbill.billing.catalog.DefaultPriceList)

Example 4 with PriceList

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

the class DefaultPriceListSet method getAllPriceLists.

@Override
public List<PriceList> getAllPriceLists() {
    final List<PriceList> result = new ArrayList<PriceList>(childPriceLists.length + 1);
    result.add(getDefaultPricelist());
    for (final PriceList list : getChildPriceLists()) {
        result.add(list);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) PriceList(org.killbill.billing.catalog.api.PriceList)

Example 5 with PriceList

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

the class TestDefaultSubscriptionBundleTimeline method createTransition.

private SubscriptionBaseTransition createTransition(final UUID entitlementId, final EventType eventType, final ApiEventType apiEventType, final DateTime effectiveDate, final DateTime createdDate, final String prevPhaseName, final String nextPhaseName) throws CatalogApiException {
    final PlanPhase prevPhase;
    final Plan prevPlan;
    final Product prevProduct;
    final PriceList prevPriceList;
    if (prevPhaseName == null) {
        prevPhase = null;
        prevPlan = null;
        prevProduct = null;
        prevPriceList = null;
    } else {
        prevPhase = Mockito.mock(PlanPhase.class);
        Mockito.when(prevPhase.getName()).thenReturn(prevPhaseName);
        prevProduct = Mockito.mock(Product.class);
        Mockito.when(prevProduct.getName()).thenReturn("product");
        prevPlan = Mockito.mock(Plan.class);
        Mockito.when(prevPlan.getName()).thenReturn("plan");
        Mockito.when(prevPlan.getProduct()).thenReturn(prevProduct);
        prevPriceList = Mockito.mock(PriceList.class);
        Mockito.when(prevPriceList.getName()).thenReturn("pricelist");
    }
    final PlanPhase nextPhase;
    final Plan nextPlan;
    final Product nextProduct;
    final PriceList nextPriceList;
    if (nextPhaseName == null) {
        nextPhase = null;
        nextPlan = null;
        nextProduct = null;
        nextPriceList = null;
    } else {
        nextPhase = Mockito.mock(PlanPhase.class);
        Mockito.when(nextPhase.getName()).thenReturn(nextPhaseName);
        nextProduct = Mockito.mock(Product.class);
        Mockito.when(nextProduct.getName()).thenReturn("product");
        nextPlan = Mockito.mock(Plan.class);
        Mockito.when(nextPlan.getName()).thenReturn("plan");
        Mockito.when(nextPlan.getProduct()).thenReturn(nextProduct);
        nextPriceList = Mockito.mock(PriceList.class);
        Mockito.when(nextPriceList.getName()).thenReturn("pricelist");
    }
    return new SubscriptionBaseTransitionData(UUID.randomUUID(), entitlementId, bundleId, bundleExternalKey, eventType, apiEventType, effectiveDate, null, null, null, prevPlan, prevPhase, prevPriceList, null, null, null, null, nextPlan, nextPhase, nextPriceList, null, 1L, createdDate, UUID.randomUUID(), true);
}
Also used : SubscriptionBaseTransitionData(org.killbill.billing.subscription.api.user.SubscriptionBaseTransitionData) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) Product(org.killbill.billing.catalog.api.Product) Plan(org.killbill.billing.catalog.api.Plan) PriceList(org.killbill.billing.catalog.api.PriceList)

Aggregations

PriceList (org.killbill.billing.catalog.api.PriceList)11 Plan (org.killbill.billing.catalog.api.Plan)9 Product (org.killbill.billing.catalog.api.Product)7 DateTime (org.joda.time.DateTime)4 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)4 Test (org.testng.annotations.Test)4 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)3 SimplePlanDescriptor (org.killbill.billing.catalog.api.SimplePlanDescriptor)3 DefaultSimplePlanDescriptor (org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor)3 DefaultPriceList (org.killbill.billing.catalog.DefaultPriceList)2 DefaultProduct (org.killbill.billing.catalog.DefaultProduct)2 ProductCategory (org.killbill.billing.catalog.api.ProductCategory)2 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 InternationalPrice (org.killbill.billing.catalog.api.InternationalPrice)1 Listing (org.killbill.billing.catalog.api.Listing)1 Recurring (org.killbill.billing.catalog.api.Recurring)1 EntitlementState (org.killbill.billing.entitlement.api.Entitlement.EntitlementState)1 EffectiveSubscriptionInternalEvent (org.killbill.billing.events.EffectiveSubscriptionInternalEvent)1 MockEffectiveSubscriptionEvent (org.killbill.billing.mock.MockEffectiveSubscriptionEvent)1