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");
}
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);
}
use of org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor in project killbill by killbill.
the class TestCatalogUpdater method testVerifyXML.
@Test(groups = "fast")
public void testVerifyXML() 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("dynamic-annual", "Dynamic", ProductCategory.BASE, Currency.USD, BigDecimal.TEN, BillingPeriod.MONTHLY, 14, TimeUnit.DAYS, ImmutableList.<String>of());
catalogUpdater.addSimplePlanDescriptor(desc);
final String expectedXML = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<catalog>\n" + " <effectiveDate>2013-02-08T00:00:00Z</effectiveDate>\n" + " <catalogName>SpyCarBasic</catalogName>\n" + " <recurringBillingMode>IN_ADVANCE</recurringBillingMode>\n" + " <currencies>\n" + " <currency>USD</currency>\n" + " <currency>GBP</currency>\n" + " </currencies>\n" + " <units/>\n" + " <products>\n" + " <product name=\"Dynamic\">\n" + " <category>BASE</category>\n" + " <included/>\n" + " <available/>\n" + " <limits/>\n" + " </product>\n" + " <product name=\"Sports\">\n" + " <category>BASE</category>\n" + " <included/>\n" + " <available/>\n" + " <limits/>\n" + " </product>\n" + " <product name=\"Standard\">\n" + " <category>BASE</category>\n" + " <included/>\n" + " <available/>\n" + " <limits/>\n" + " </product>\n" + " <product name=\"Super\">\n" + " <category>BASE</category>\n" + " <included/>\n" + " <available/>\n" + " <limits/>\n" + " </product>\n" + " </products>\n" + " <rules>\n" + " <changePolicy>\n" + " <changePolicyCase>\n" + " <policy>IMMEDIATE</policy>\n" + " </changePolicyCase>\n" + " </changePolicy>\n" + " <changeAlignment>\n" + " <changeAlignmentCase>\n" + " <alignment>START_OF_BUNDLE</alignment>\n" + " </changeAlignmentCase>\n" + " </changeAlignment>\n" + " <cancelPolicy>\n" + " <cancelPolicyCase>\n" + " <policy>IMMEDIATE</policy>\n" + " </cancelPolicyCase>\n" + " </cancelPolicy>\n" + " <createAlignment>\n" + " <createAlignmentCase>\n" + " <alignment>START_OF_BUNDLE</alignment>\n" + " </createAlignmentCase>\n" + " </createAlignment>\n" + " <billingAlignment>\n" + " <billingAlignmentCase>\n" + " <alignment>ACCOUNT</alignment>\n" + " </billingAlignmentCase>\n" + " </billingAlignment>\n" + " <priceList>\n" + " <priceListCase>\n" + " <toPriceList>DEFAULT</toPriceList>\n" + " </priceListCase>\n" + " </priceList>\n" + " </rules>\n" + " <plans>\n" + " <plan name=\"dynamic-annual\">\n" + " <product>Dynamic</product>\n" + " <initialPhases>\n" + " <phase type=\"TRIAL\">\n" + " <duration>\n" + " <unit>DAYS</unit>\n" + " <number>14</number>\n" + " </duration>\n" + " <fixed type=\"ONE_TIME\">\n" + " <fixedPrice>\n" + " <price>\n" + "<currency>USD</currency>\n" + "<value>0</value>\n" + " </price>\n" + " </fixedPrice>\n" + " </fixed>\n" + " <usages/>\n" + " </phase>\n" + " </initialPhases>\n" + " <finalPhase type=\"EVERGREEN\">\n" + " <duration>\n" + " <unit>UNLIMITED</unit>\n" + " <number>-1</number>\n" + " </duration>\n" + " <recurring>\n" + " <billingPeriod>MONTHLY</billingPeriod>\n" + " <recurringPrice>\n" + " <price>\n" + " <currency>USD</currency>\n" + " <value>10</value>\n" + " </price>\n" + " </recurringPrice>\n" + " </recurring>\n" + " <usages/>\n" + " </finalPhase>\n" + " <plansAllowedInBundle>-1</plansAllowedInBundle>\n" + " </plan>\n" + " <plan name=\"sports-monthly\">\n" + " <product>Sports</product>\n" + " <initialPhases>\n" + " <phase type=\"TRIAL\">\n" + " <duration>\n" + " <unit>DAYS</unit>\n" + " <number>30</number>\n" + " </duration>\n" + " <fixed type=\"ONE_TIME\">\n" + " <fixedPrice/>\n" + " </fixed>\n" + " <usages/>\n" + " </phase>\n" + " </initialPhases>\n" + " <finalPhase type=\"EVERGREEN\">\n" + " <duration>\n" + " <unit>UNLIMITED</unit>\n" + " <number>-1</number>\n" + " </duration>\n" + " <recurring>\n" + " <billingPeriod>MONTHLY</billingPeriod>\n" + " <recurringPrice>\n" + " <price>\n" + " <currency>GBP</currency>\n" + " <value>375.00</value>\n" + " </price>\n" + " <price>\n" + " <currency>USD</currency>\n" + " <value>500.00</value>\n" + " </price>\n" + " </recurringPrice>\n" + " </recurring>\n" + " <usages/>\n" + " </finalPhase>\n" + " <plansAllowedInBundle>-1</plansAllowedInBundle>\n" + " </plan>\n" + " <plan name=\"standard-monthly\">\n" + " <product>Standard</product>\n" + " <initialPhases>\n" + " <phase type=\"TRIAL\">\n" + " <duration>\n" + " <unit>DAYS</unit>\n" + " <number>30</number>\n" + " </duration>\n" + " <fixed type=\"ONE_TIME\">\n" + " <fixedPrice/>\n" + " </fixed>\n" + " <usages/>\n" + " </phase>\n" + " </initialPhases>\n" + " <finalPhase type=\"EVERGREEN\">\n" + " <duration>\n" + " <unit>UNLIMITED</unit>\n" + " <number>-1</number>\n" + " </duration>\n" + " <recurring>\n" + " <billingPeriod>MONTHLY</billingPeriod>\n" + " <recurringPrice>\n" + " <price>\n" + " <currency>GBP</currency>\n" + " <value>75.00</value>\n" + " </price>\n" + " <price>\n" + " <currency>USD</currency>\n" + " <value>100.00</value>\n" + " </price>\n" + " </recurringPrice>\n" + " </recurring>\n" + " <usages/>\n" + " </finalPhase>\n" + " <plansAllowedInBundle>-1</plansAllowedInBundle>\n" + " </plan>\n" + " <plan name=\"super-monthly\">\n" + " <product>Super</product>\n" + " <initialPhases>\n" + " <phase type=\"TRIAL\">\n" + " <duration>\n" + " <unit>DAYS</unit>\n" + " <number>30</number>\n" + " </duration>\n" + " <fixed type=\"ONE_TIME\">\n" + " <fixedPrice/>\n" + " </fixed>\n" + " <usages/>\n" + " </phase>\n" + " </initialPhases>\n" + " <finalPhase type=\"EVERGREEN\">\n" + " <duration>\n" + " <unit>UNLIMITED</unit>\n" + " <number>-1</number>\n" + " </duration>\n" + " <recurring>\n" + " <billingPeriod>MONTHLY</billingPeriod>\n" + " <recurringPrice>\n" + " <price>\n" + " <currency>GBP</currency>\n" + " <value>750.00</value>\n" + " </price>\n" + " <price>\n" + " <currency>USD</currency>\n" + " <value>1000.00</value>\n" + " </price>\n" + " </recurringPrice>\n" + " </recurring>\n" + " <usages/>\n" + " </finalPhase>\n" + " <plansAllowedInBundle>-1</plansAllowedInBundle>\n" + " </plan>\n" + " </plans>\n" + " <priceLists>\n" + " <defaultPriceList name=\"DEFAULT\">\n" + " <plans>\n" + " <plan>dynamic-annual</plan>\n" + " <plan>sports-monthly</plan>\n" + " <plan>standard-monthly</plan>\n" + " <plan>super-monthly</plan>\n" + " </plans>\n" + " </defaultPriceList>\n" + " </priceLists>\n" + "</catalog>\n";
assertEquals(catalogUpdater.getCatalogXML(), expectedXML);
System.err.println(catalogUpdater.getCatalogXML());
}
use of org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor 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");
}
use of org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor in project killbill by killbill.
the class TestIntegrationWithCatalogUpdate method testBasic.
@Test(groups = "slow")
public void testBasic() throws Exception {
// Create a per-tenant catalog with one plan
final SimplePlanDescriptor desc1 = new DefaultSimplePlanDescriptor("foo-monthly", "Foo", 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 Entitlement baseEntitlement = createEntitlement("foo-monthly", true);
invoiceChecker.checkInvoice(account.getId(), 1, testCallContext, new ExpectedInvoiceItemCheck(new LocalDate(2016, 6, 1), new LocalDate(2016, 7, 1), InvoiceItemType.RECURRING, BigDecimal.TEN));
// Add another Plan in the catalog
final SimplePlanDescriptor desc2 = new DefaultSimplePlanDescriptor("superfoo-monthly", "SuperFoo", ProductCategory.BASE, account.getCurrency(), new BigDecimal("20.00"), BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of());
catalogUserApi.addSimplePlan(desc2, init, testCallContext);
catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext);
assertEquals(catalog.getCurrentPlans().size(), 2);
// Change Plan to the newly added Plan and verify correct default rules behavior (IMMEDIATE change)
busHandler.pushExpectedEvents(NextEvent.CHANGE, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
baseEntitlement.changePlan(new PlanSpecifier("SuperFoo", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME), null, ImmutableList.<PluginProperty>of(), testCallContext);
assertListenerStatus();
invoiceChecker.checkInvoice(account.getId(), 2, testCallContext, new ExpectedInvoiceItemCheck(new LocalDate(2016, 6, 1), new LocalDate(2016, 7, 1), InvoiceItemType.RECURRING, new BigDecimal("20.00")), new ExpectedInvoiceItemCheck(new LocalDate(2016, 6, 1), new LocalDate(2016, 7, 1), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-10.00")));
assertListenerStatus();
}
Aggregations