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);
}
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");
}
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;
}
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;
}
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);
}
Aggregations