Search in sources :

Example 6 with PriceList

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

the class TestPlanDetailJson method testFromListing.

@Test(groups = "fast")
public void testFromListing() throws Exception {
    final Product product = Mockito.mock(Product.class);
    Mockito.when(product.getName()).thenReturn(UUID.randomUUID().toString());
    final InternationalPrice price = Mockito.mock(InternationalPrice.class);
    Mockito.when(price.getPrices()).thenReturn(new DefaultPrice[0]);
    final PlanPhase planPhase = Mockito.mock(PlanPhase.class);
    final Recurring recurring = Mockito.mock(Recurring.class);
    Mockito.when(recurring.getRecurringPrice()).thenReturn(price);
    Mockito.when(planPhase.getRecurring()).thenReturn(recurring);
    final Plan plan = Mockito.mock(Plan.class);
    Mockito.when(plan.getProduct()).thenReturn(product);
    Mockito.when(plan.getName()).thenReturn(UUID.randomUUID().toString());
    Mockito.when(plan.getRecurringBillingPeriod()).thenReturn(BillingPeriod.QUARTERLY);
    Mockito.when(plan.getFinalPhase()).thenReturn(planPhase);
    final PriceList priceList = Mockito.mock(PriceList.class);
    Mockito.when(priceList.getName()).thenReturn(UUID.randomUUID().toString());
    final Listing listing = Mockito.mock(Listing.class);
    Mockito.when(listing.getPlan()).thenReturn(plan);
    Mockito.when(listing.getPriceList()).thenReturn(priceList);
    final PlanDetailJson planDetailJson = new PlanDetailJson(listing);
    Assert.assertEquals(planDetailJson.getProduct(), plan.getProduct().getName());
    Assert.assertEquals(planDetailJson.getPlan(), plan.getName());
    Assert.assertEquals(planDetailJson.getFinalPhaseBillingPeriod(), plan.getRecurringBillingPeriod());
    Assert.assertEquals(planDetailJson.getPriceList(), priceList.getName());
    Assert.assertEquals(planDetailJson.getFinalPhaseRecurringPrice().size(), 0);
}
Also used : Recurring(org.killbill.billing.catalog.api.Recurring) Listing(org.killbill.billing.catalog.api.Listing) Product(org.killbill.billing.catalog.api.Product) InternationalPrice(org.killbill.billing.catalog.api.InternationalPrice) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) Plan(org.killbill.billing.catalog.api.Plan) PriceList(org.killbill.billing.catalog.api.PriceList) Test(org.testng.annotations.Test)

Example 7 with PriceList

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

the class TestCatalogUpdater method testAddTrialPlanOnFirstCatalog.

@Test(groups = "fast")
public void testAddTrialPlanOnFirstCatalog() throws CatalogApiException {
    final DateTime now = clock.getUTCNow();
    final SimplePlanDescriptor desc = new DefaultSimplePlanDescriptor("foo-monthly", "Foo", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 14, TimeUnit.DAYS, 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, 1);
    assertEquals(plan.getInitialPhases()[0].getPhaseType(), PhaseType.TRIAL);
    assertEquals(plan.getInitialPhases()[0].getFixed().getPrice().getPrices().length, 1);
    assertEquals(plan.getInitialPhases()[0].getFixed().getPrice().getPrices()[0].getCurrency(), Currency.EUR);
    assertEquals(plan.getInitialPhases()[0].getFixed().getPrice().getPrices()[0].getValue(), BigDecimal.ZERO);
    assertEquals(plan.getInitialPhases()[0].getName(), "foo-monthly-trial");
    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 8 with PriceList

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

the class DefaultCase method satisfiesCase.

protected boolean satisfiesCase(final PlanSpecifier planPhase, final StaticCatalog c) throws CatalogApiException {
    final Product product;
    final BillingPeriod billingPeriod;
    final ProductCategory productCategory;
    final PriceList priceList;
    if (planPhase.getPlanName() != null) {
        final Plan plan = c.findCurrentPlan(planPhase.getPlanName());
        product = plan.getProduct();
        billingPeriod = plan.getRecurringBillingPeriod();
        productCategory = plan.getProduct().getCategory();
        priceList = c.findCurrentPricelist(plan.getPriceListName());
    } else {
        product = c.findCurrentProduct(planPhase.getProductName());
        billingPeriod = planPhase.getBillingPeriod();
        productCategory = product.getCategory();
        priceList = getPriceList() != null ? c.findCurrentPricelist(planPhase.getPriceListName()) : null;
    }
    return (getProduct() == null || getProduct().equals(product)) && (getProductCategory() == null || getProductCategory().equals(productCategory)) && (getBillingPeriod() == null || getBillingPeriod().equals(billingPeriod)) && (getPriceList() == null || getPriceList().equals(priceList));
}
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 9 with PriceList

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

the class BlockingStateOrdering method toSubscriptionEvent.

private SubscriptionEvent toSubscriptionEvent(@Nullable final SubscriptionEvent prev, @Nullable final SubscriptionEvent next, final UUID entitlementId, final BlockingState in, final SubscriptionEventType eventType, final InternalTenantContext internalTenantContext) {
    final Product prevProduct;
    final Plan prevPlan;
    final PlanPhase prevPlanPhase;
    final PriceList prevPriceList;
    final BillingPeriod prevBillingPeriod;
    // Enforce prev = null for start events
    if (prev == null || SubscriptionEventType.START_ENTITLEMENT.equals(eventType) || SubscriptionEventType.START_BILLING.equals(eventType)) {
        prevProduct = null;
        prevPlan = null;
        prevPlanPhase = null;
        prevPriceList = null;
        prevBillingPeriod = null;
    } else {
        // We look for the next for the 'prev' meaning we we are headed to, but if this is null -- for example on cancellation we get the prev which gives the correct state.
        prevProduct = (prev.getNextProduct() != null ? prev.getNextProduct() : prev.getPrevProduct());
        prevPlan = (prev.getNextPlan() != null ? prev.getNextPlan() : prev.getPrevPlan());
        prevPlanPhase = (prev.getNextPhase() != null ? prev.getNextPhase() : prev.getPrevPhase());
        prevPriceList = (prev.getNextPriceList() != null ? prev.getNextPriceList() : prev.getPrevPriceList());
        prevBillingPeriod = (prev.getNextBillingPeriod() != null ? prev.getNextBillingPeriod() : prev.getPrevBillingPeriod());
    }
    final Product nextProduct;
    final Plan nextPlan;
    final PlanPhase nextPlanPhase;
    final PriceList nextPriceList;
    final BillingPeriod nextBillingPeriod;
    if (SubscriptionEventType.PAUSE_ENTITLEMENT.equals(eventType) || SubscriptionEventType.PAUSE_BILLING.equals(eventType) || SubscriptionEventType.RESUME_ENTITLEMENT.equals(eventType) || SubscriptionEventType.RESUME_BILLING.equals(eventType) || (SubscriptionEventType.SERVICE_STATE_CHANGE.equals(eventType) && (prev == null || (!SubscriptionEventType.STOP_ENTITLEMENT.equals(prev.getSubscriptionEventType()) && !SubscriptionEventType.STOP_BILLING.equals(prev.getSubscriptionEventType()))))) {
        // Enforce next = prev for pause/resume events as well as service changes
        nextProduct = prevProduct;
        nextPlan = prevPlan;
        nextPlanPhase = prevPlanPhase;
        nextPriceList = prevPriceList;
        nextBillingPeriod = prevBillingPeriod;
    } else if (next == null) {
        // Enforce next = null for stop events
        if (prev == null || SubscriptionEventType.STOP_ENTITLEMENT.equals(eventType) || SubscriptionEventType.STOP_BILLING.equals(eventType)) {
            nextProduct = null;
            nextPlan = null;
            nextPlanPhase = null;
            nextPriceList = null;
            nextBillingPeriod = null;
        } else {
            nextProduct = prev.getNextProduct();
            nextPlan = prev.getNextPlan();
            nextPlanPhase = prev.getNextPhase();
            nextPriceList = prev.getNextPriceList();
            nextBillingPeriod = prev.getNextBillingPeriod();
        }
    } else if (prev != null && (SubscriptionEventType.START_ENTITLEMENT.equals(eventType) || SubscriptionEventType.START_BILLING.equals(eventType))) {
        // For start events, next is actually the prev (e.g. the trial, not the phase)
        nextProduct = prev.getNextProduct();
        nextPlan = prev.getNextPlan();
        nextPlanPhase = prev.getNextPhase();
        nextPriceList = prev.getNextPriceList();
        nextBillingPeriod = prev.getNextBillingPeriod();
    } else {
        nextProduct = next.getNextProduct();
        nextPlan = next.getNextPlan();
        nextPlanPhase = next.getNextPhase();
        nextPriceList = next.getNextPriceList();
        nextBillingPeriod = next.getNextBillingPeriod();
    }
    // See https://github.com/killbill/killbill/issues/135
    final String serviceName = getRealServiceNameForEntitlementOrExternalServiceName(in.getService(), eventType);
    return new DefaultSubscriptionEvent(in.getId(), entitlementId, in.getEffectiveDate(), eventType, in.isBlockEntitlement(), in.isBlockBilling(), serviceName, in.getStateName(), prevProduct, prevPlan, prevPlanPhase, prevPriceList, prevBillingPeriod, nextProduct, nextPlan, nextPlanPhase, nextPriceList, nextBillingPeriod, in.getCreatedDate(), internalTenantContext);
}
Also used : BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) Product(org.killbill.billing.catalog.api.Product) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) Plan(org.killbill.billing.catalog.api.Plan) PriceList(org.killbill.billing.catalog.api.PriceList)

Example 10 with PriceList

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

the class TestBillingApi method createSubscriptionCreationEvent.

private DateTime createSubscriptionCreationEvent(final Plan nextPlan, final PlanPhase nextPhase) throws CatalogApiException {
    final DateTime now = clock.getUTCNow();
    final DateTime then = now.minusDays(1);
    final PriceList nextPriceList = catalog.findPriceList(PriceListSet.DEFAULT_PRICELIST_NAME, now);
    final EffectiveSubscriptionInternalEvent t = new MockEffectiveSubscriptionEvent(eventId, subId, bunId, bunKey, then, now, null, null, null, null, null, EntitlementState.ACTIVE, nextPlan.getName(), nextPhase.getName(), nextPriceList.getName(), null, 1L, SubscriptionBaseTransitionType.CREATE, 1, null, 1L, 2L, null);
    effectiveSubscriptionTransitions.add(t);
    return now;
}
Also used : EffectiveSubscriptionInternalEvent(org.killbill.billing.events.EffectiveSubscriptionInternalEvent) MockEffectiveSubscriptionEvent(org.killbill.billing.mock.MockEffectiveSubscriptionEvent) PriceList(org.killbill.billing.catalog.api.PriceList) DateTime(org.joda.time.DateTime)

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