Search in sources :

Example 1 with DefaultSimplePlanDescriptor

use of org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor in project killbill by killbill.

the class TestCatalogUpdater method testInvalidPlanDescriptors.

@Test(groups = "fast")
public void testInvalidPlanDescriptors() throws Exception {
    final StandaloneCatalog originalCatalog = enhanceOriginalCatalogForInvalidTestCases("SpyCarBasic.xml");
    assertEquals(originalCatalog.getPriceLists().getAllPriceLists().size(), 1);
    assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getName(), new PriceListDefault().getName());
    assertEquals(originalCatalog.getPriceLists().getAllPriceLists().get(0).getPlans().size(), 5);
    CatalogUpdater catalogUpdater = new CatalogUpdater(originalCatalog);
    // Existing Plan has a 30 days trial => try with no TRIAL
    SimplePlanDescriptor desc = new DefaultSimplePlanDescriptor("standard-monthly", "Standard", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.DAYS, ImmutableList.<String>of());
    addBadSimplePlanDescriptor(catalogUpdater, desc);
    // Existing Plan has a 30 days trial => try different trial length
    desc = new DefaultSimplePlanDescriptor("standard-monthly", "Standard", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 14, TimeUnit.DAYS, ImmutableList.<String>of());
    addBadSimplePlanDescriptor(catalogUpdater, desc);
    // Existing Plan has a 30 days trial => try different trial unit
    desc = new DefaultSimplePlanDescriptor("standard-monthly", "Standard", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 30, TimeUnit.MONTHS, ImmutableList.<String>of());
    addBadSimplePlanDescriptor(catalogUpdater, desc);
    // Existing Plan has a MONTHLY recurring => try with ANNUAL BillingPeriod
    desc = new DefaultSimplePlanDescriptor("standard-monthly", "Standard", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.ANNUAL, 30, TimeUnit.DAYS, ImmutableList.<String>of());
    addBadSimplePlanDescriptor(catalogUpdater, desc);
    // Existing Plan has a discount phase
    desc = new DefaultSimplePlanDescriptor("dynamic-monthly", "Dynamic", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 30, TimeUnit.MONTHS, ImmutableList.<String>of());
    addBadSimplePlanDescriptor(catalogUpdater, desc);
    // Existing Plan has final fixedterm phase
    desc = new DefaultSimplePlanDescriptor("superdynamic-fixedterm", "SuperDynamic", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 30, TimeUnit.DAYS, ImmutableList.<String>of());
    addBadSimplePlanDescriptor(catalogUpdater, desc);
    // Existing Plan a different recurring price ($100)
    desc = new DefaultSimplePlanDescriptor("standard-monthly", "Standard", ProductCategory.BASE, Currency.USD, BigDecimal.TEN, BillingPeriod.MONTHLY, 30, TimeUnit.DAYS, ImmutableList.<String>of());
    addBadSimplePlanDescriptor(catalogUpdater, desc);
}
Also used : 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 DefaultSimplePlanDescriptor

use of org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor 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 3 with DefaultSimplePlanDescriptor

use of org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor in project killbill by killbill.

the class TestCatalogUpdater method testAddExistingPlanWithNewCurrency.

@Test(groups = "fast")
public void testAddExistingPlanWithNewCurrency() 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-monthly", "Standard", ProductCategory.BASE, Currency.EUR, BigDecimal.TEN, BillingPeriod.MONTHLY, 30, TimeUnit.DAYS, ImmutableList.<String>of());
    catalogUpdater.addSimplePlanDescriptor(desc);
    final StandaloneCatalog catalog = catalogUpdater.getCatalog();
    final Plan plan = catalog.findCurrentPlan("standard-monthly");
    assertEquals(plan.getName(), "standard-monthly");
    assertEquals(plan.getInitialPhases().length, 1);
    assertEquals(plan.getInitialPhases()[0].getPhaseType(), PhaseType.TRIAL);
    assertEquals(plan.getInitialPhases()[0].getFixed().getPrice().getPrices().length, 0);
    assertEquals(plan.getInitialPhases()[0].getFixed().getPrice().getPrice(Currency.EUR), BigDecimal.ZERO);
    assertEquals(plan.getInitialPhases()[0].getName(), "standard-monthly-trial");
    assertEquals(plan.getFinalPhase().getPhaseType(), PhaseType.EVERGREEN);
    assertNull(plan.getFinalPhase().getFixed());
    assertEquals(plan.getFinalPhase().getName(), "standard-monthly-evergreen");
    assertEquals(plan.getFinalPhase().getRecurring().getBillingPeriod(), BillingPeriod.MONTHLY);
    assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices().length, 3);
    assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrice(Currency.EUR), BigDecimal.TEN);
}
Also used : Plan(org.killbill.billing.catalog.api.Plan) 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 4 with DefaultSimplePlanDescriptor

use of org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor 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 5 with DefaultSimplePlanDescriptor

use of org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor in project killbill by killbill.

the class TestIntegrationWithCatalogUpdate method testWithPriceOverride.

@Test(groups = "slow")
public void testWithPriceOverride() throws Exception {
    // Create a per-tenant catalog with one plan
    final SimplePlanDescriptor desc1 = new DefaultSimplePlanDescriptor("bar-monthly", "Bar", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of());
    catalogUserApi.addSimplePlan(desc1, init, testCallContext);
    StaticCatalog catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext);
    assertEquals(catalog.getCurrentPlans().size(), 1);
    final Plan plan = catalog.getCurrentPlans().iterator().next();
    final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("bar-monthly", null);
    final List<PlanPhasePriceOverride> overrides = new ArrayList<PlanPhasePriceOverride>();
    overrides.add(new DefaultPlanPhasePriceOverride(plan.getFinalPhase().getName(), account.getCurrency(), null, BigDecimal.ONE));
    final Entitlement baseEntitlement = createEntitlement(spec, overrides, true);
    List<Invoice> invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, testCallContext);
    assertEquals(invoices.size(), 1);
    assertEquals(invoices.get(0).getChargedAmount().compareTo(BigDecimal.ONE), 0);
    busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
    clock.addMonths(1);
    assertListenerStatus();
    invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, testCallContext);
    assertEquals(invoices.size(), 2);
    assertEquals(invoices.get(1).getChargedAmount().compareTo(BigDecimal.ONE), 0);
    // Change plan to original (non overridden plan)
    busHandler.pushExpectedEvents(NextEvent.CHANGE, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
    baseEntitlement.changePlan(spec, null, ImmutableList.<PluginProperty>of(), testCallContext);
    assertListenerStatus();
    invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, testCallContext);
    assertEquals(invoices.size(), 3);
    // 10 (recurring) - 1 (repair)
    assertEquals(invoices.get(2).getChargedAmount().compareTo(new BigDecimal("9.00")), 0);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride) Invoice(org.killbill.billing.invoice.api.Invoice) ArrayList(java.util.ArrayList) Plan(org.killbill.billing.catalog.api.Plan) StaticCatalog(org.killbill.billing.catalog.api.StaticCatalog) SimplePlanDescriptor(org.killbill.billing.catalog.api.SimplePlanDescriptor) DefaultSimplePlanDescriptor(org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor) DefaultSimplePlanDescriptor(org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor) BigDecimal(java.math.BigDecimal) Entitlement(org.killbill.billing.entitlement.api.Entitlement) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride) DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride) Test(org.testng.annotations.Test)

Aggregations

SimplePlanDescriptor (org.killbill.billing.catalog.api.SimplePlanDescriptor)14 DefaultSimplePlanDescriptor (org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor)14 Test (org.testng.annotations.Test)13 StaticCatalog (org.killbill.billing.catalog.api.StaticCatalog)7 Plan (org.killbill.billing.catalog.api.Plan)5 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)5 Entitlement (org.killbill.billing.entitlement.api.Entitlement)5 LocalDate (org.joda.time.LocalDate)4 BigDecimal (java.math.BigDecimal)3 PriceList (org.killbill.billing.catalog.api.PriceList)3 ArrayList (java.util.ArrayList)2 DateTime (org.joda.time.DateTime)2 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)2 Product (org.killbill.billing.catalog.api.Product)2 Subscription (org.killbill.billing.entitlement.api.Subscription)2 Invoice (org.killbill.billing.invoice.api.Invoice)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1