use of org.killbill.billing.catalog.api.SimplePlanDescriptor in project killbill by killbill.
the class TestIntegrationWithCatalogUpdate method testError_CAT_MULTIPLE_MATCHING_PLANS_FOR_PRICELIST.
@Test(groups = "slow")
public void testError_CAT_MULTIPLE_MATCHING_PLANS_FOR_PRICELIST() throws Exception {
// Create a per-tenant catalog with one plan
final SimplePlanDescriptor desc1 = new DefaultSimplePlanDescriptor("zoe-monthly", "Zoe", 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 SimplePlanDescriptor desc2 = new DefaultSimplePlanDescriptor("zoe-14-monthly", "Zoe", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.MONTHLY, 14, TimeUnit.DAYS, ImmutableList.<String>of());
catalogUserApi.addSimplePlan(desc2, init, testCallContext);
catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext);
assertEquals(catalog.getCurrentPlans().size(), 2);
try {
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Zoe", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
entitlementApi.createBaseEntitlement(account.getId(), spec, UUID.randomUUID().toString(), null, null, null, false, ImmutableList.<PluginProperty>of(), testCallContext);
fail("Creating entitlement should fail");
} catch (final EntitlementApiException e) {
assertEquals(e.getCode(), ErrorCode.CAT_MULTIPLE_MATCHING_PLANS_FOR_PRICELIST.getCode());
}
}
use of org.killbill.billing.catalog.api.SimplePlanDescriptor in project killbill by killbill.
the class TestIntegrationWithCatalogUpdate method testWithThirtyDaysPlan.
// Use custom plan definition to create a THIRTY_DAYS plan with no trial and test issue #598
@Test(groups = "slow")
public void testWithThirtyDaysPlan() throws Exception {
// Create a per-tenant catalog with one plan
final SimplePlanDescriptor desc1 = new DefaultSimplePlanDescriptor("thirty-monthly", "Thirty", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.THIRTY_DAYS, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of());
catalogUserApi.addSimplePlan(desc1, init, testCallContext);
StaticCatalog catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext);
assertEquals(catalog.getCurrentPlans().size(), 1);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("thirty-monthly", null);
createEntitlement(spec, null, true);
List<Invoice> invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, testCallContext);
assertEquals(invoices.size(), 1);
assertEquals(invoices.get(0).getChargedAmount().compareTo(BigDecimal.TEN), 0);
assertEquals(invoices.get(0).getInvoiceItems().size(), 1);
final List<ExpectedInvoiceItemCheck> expectedInvoices = new ArrayList<ExpectedInvoiceItemCheck>();
expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2016, 6, 1), new LocalDate(2016, 7, 1), InvoiceItemType.RECURRING, BigDecimal.TEN));
invoiceChecker.checkInvoiceNoAudits(invoices.get(0), callContext, expectedInvoices);
int invoiceSize = 2;
LocalDate startDate = new LocalDate(2016, 7, 1);
for (int i = 0; i < 14; i++) {
expectedInvoices.clear();
busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
clock.addDays(30);
assertListenerStatus();
LocalDate endDate = startDate.plusDays(30);
invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, testCallContext);
assertEquals(invoices.size(), invoiceSize);
expectedInvoices.add(new ExpectedInvoiceItemCheck(startDate, endDate, InvoiceItemType.RECURRING, BigDecimal.TEN));
invoiceChecker.checkInvoiceNoAudits(invoices.get(invoices.size() - 1), callContext, expectedInvoices);
startDate = endDate;
invoiceSize++;
}
}
use of org.killbill.billing.catalog.api.SimplePlanDescriptor 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.SimplePlanDescriptor 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.SimplePlanDescriptor 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