use of org.killbill.billing.catalog.DefaultPrice in project killbill by killbill.
the class TestXMLWriter method testAddPlan.
@Test(groups = "fast")
public void testAddPlan() throws Exception {
final StandaloneCatalog catalog = getCatalog("SpyCarBasic.xml");
final MutableStaticCatalog mutableCatalog = new DefaultMutableStaticCatalog(catalog);
final DefaultProduct newProduct = new DefaultProduct();
newProduct.setName("Dynamic");
newProduct.setCatagory(ProductCategory.BASE);
newProduct.initialize((StandaloneCatalog) mutableCatalog);
mutableCatalog.addProduct(newProduct);
final DefaultPlanPhase trialPhase = new DefaultPlanPhase();
trialPhase.setPhaseType(PhaseType.TRIAL);
trialPhase.setDuration(new DefaultDuration().setUnit(TimeUnit.DAYS).setNumber(14));
trialPhase.setFixed(new DefaultFixed().setFixedPrice(new DefaultInternationalPrice().setPrices(new DefaultPrice[] { new DefaultPrice().setCurrency(Currency.USD).setValue(BigDecimal.ZERO) })));
final DefaultPlanPhase evergreenPhase = new DefaultPlanPhase();
evergreenPhase.setPhaseType(PhaseType.EVERGREEN);
evergreenPhase.setDuration(new DefaultDuration().setUnit(TimeUnit.UNLIMITED));
evergreenPhase.setRecurring(new DefaultRecurring().setBillingPeriod(BillingPeriod.MONTHLY).setRecurringPrice(new DefaultInternationalPrice().setPrices(new DefaultPrice[] { new DefaultPrice().setCurrency(Currency.USD).setValue(BigDecimal.TEN) })));
final DefaultPlan newPlan = new DefaultPlan();
newPlan.setName("dynamic-monthly");
newPlan.setPriceListName(DefaultPriceListSet.DEFAULT_PRICELIST_NAME);
newPlan.setProduct(newProduct);
newPlan.setInitialPhases(new DefaultPlanPhase[] { trialPhase });
newPlan.setFinalPhase(evergreenPhase);
newPlan.setRecurringBillingMode(BillingMode.IN_ADVANCE);
newPlan.initialize((StandaloneCatalog) mutableCatalog);
mutableCatalog.addPlan(newPlan);
final String newCatalogStr = XMLWriter.writeXML((StandaloneCatalog) mutableCatalog, StandaloneCatalog.class);
final StandaloneCatalog newCatalog = XMLLoader.getObjectFromStream(new ByteArrayInputStream(newCatalogStr.getBytes(Charset.forName("UTF-8"))), StandaloneCatalog.class);
assertEquals(newCatalog.getPlans().size(), catalog.getPlans().size() + 1);
final Plan plan = newCatalog.findPlan("dynamic-monthly");
assertEquals(plan.getName(), "dynamic-monthly");
assertEquals(plan.getPriceList().getName(), DefaultPriceListSet.DEFAULT_PRICELIST_NAME);
assertEquals(plan.getProduct().getName(), "Dynamic");
assertEquals(plan.getProduct().getCategory(), ProductCategory.BASE);
assertEquals(plan.getInitialPhases().length, 1);
assertEquals(plan.getInitialPhases()[0].getName(), "dynamic-monthly-trial");
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.USD);
assertEquals(plan.getInitialPhases()[0].getFixed().getPrice().getPrices()[0].getValue(), BigDecimal.ZERO);
assertEquals(plan.getFinalPhase().getName(), "dynamic-monthly-evergreen");
assertEquals(plan.getFinalPhase().getPhaseType(), PhaseType.EVERGREEN);
assertEquals(plan.getFinalPhase().getRecurring().getBillingPeriod(), BillingPeriod.MONTHLY);
assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices().length, 1);
assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices()[0].getCurrency(), Currency.USD);
assertEquals(plan.getFinalPhase().getRecurring().getRecurringPrice().getPrices()[0].getValue(), BigDecimal.TEN);
}
use of org.killbill.billing.catalog.DefaultPrice in project killbill by killbill.
the class TestFixedAndRecurringInvoiceItemGenerator method testOverlappingItemsWithTooManyRepairs.
// Also a case we REPAIR amount does not match the dates and the current logic is to assert on the dates
@Test(groups = "fast", description = "https://github.com/killbill/killbill/issues/664")
public void testOverlappingItemsWithTooManyRepairs() throws InvoiceApiException {
final LocalDate startDate = new LocalDate("2016-01-01");
final BillingEventSet events = new MockBillingEventSet();
final BigDecimal amount = BigDecimal.TEN;
final MockInternationalPrice price = new MockInternationalPrice(new DefaultPrice(amount, account.getCurrency()));
final Plan plan = new MockPlan("my-plan");
final PlanPhase planPhase = new MockPlanPhase(price, null, BillingPeriod.MONTHLY, PhaseType.EVERGREEN);
final BillingEvent event = invoiceUtil.createMockBillingEvent(account, subscription, startDate.toDateTimeAtStartOfDay(), plan, planPhase, null, amount, account.getCurrency(), BillingPeriod.MONTHLY, 1, BillingMode.IN_ADVANCE, "Billing Event Desc", 1L, SubscriptionBaseTransitionType.CREATE);
events.add(event);
// Simulate a previous mis-bill: existing item is for [2016-01-01,2016-01-30], proposed will be for [2016-01-01,2016-02-01]
final List<Invoice> existingInvoices = new LinkedList<Invoice>();
final Invoice invoice = new DefaultInvoice(account.getId(), clock.getUTCToday(), startDate, account.getCurrency());
invoice.addInvoiceItem(new RecurringInvoiceItem(UUID.randomUUID(), startDate.toDateTimeAtStartOfDay(), invoice.getId(), account.getId(), subscription.getBundleId(), subscription.getId(), null, event.getPlan().getName(), event.getPlanPhase().getName(), null, startDate, startDate.plusDays(29), amount, amount, account.getCurrency()));
// But the system has already repaired it
invoice.addInvoiceItem(new RepairAdjInvoiceItem(UUID.randomUUID(), startDate.toDateTimeAtStartOfDay(), invoice.getId(), account.getId(), startDate, startDate.plusDays(29), // Note! The amount will not matter
amount.negate(), account.getCurrency(), invoice.getInvoiceItems().get(0).getId()));
// Twice!
invoice.addInvoiceItem(new RepairAdjInvoiceItem(UUID.randomUUID(), startDate.toDateTimeAtStartOfDay(), invoice.getId(), account.getId(), startDate, startDate.plusDays(29), // Note! The amount will not matter
BigDecimal.ONE.negate(), account.getCurrency(), invoice.getInvoiceItems().get(0).getId()));
existingInvoices.add(invoice);
try {
fixedAndRecurringInvoiceItemGenerator.generateItems(account, UUID.randomUUID(), events, new AccountInvoices(null, null, existingInvoices), startDate, account.getCurrency(), new HashMap<UUID, SubscriptionFutureNotificationDates>(), null, internalCallContext).getItems();
fail();
} catch (final InvoiceApiException e) {
assertEquals(e.getCode(), ErrorCode.UNEXPECTED_ERROR.getCode());
assertTrue(e.getCause().getMessage().startsWith("Too many repairs"));
}
}
use of org.killbill.billing.catalog.DefaultPrice in project killbill by killbill.
the class TestUsageInArrearBase method createDefaultTieredBlock.
protected DefaultTieredBlock createDefaultTieredBlock(final String unit, final int size, final int max, final BigDecimal price) {
final DefaultTieredBlock block = new DefaultTieredBlock();
block.setUnit(new DefaultUnit().setName(unit));
block.setSize(new Double(size));
final DefaultPrice[] prices = new DefaultPrice[1];
prices[0] = new DefaultPrice();
prices[0].setCurrency(currency).setValue(price);
block.setPrice(new DefaultInternationalPrice().setPrices(prices));
block.setMax(new Double(max));
return block;
}
use of org.killbill.billing.catalog.DefaultPrice in project killbill by killbill.
the class TestUsageInArrearBase method createDefaultTierWithLimits.
protected DefaultTier createDefaultTierWithLimits(final BigDecimal recurringAmountInCurrency, final DefaultLimit... limits) {
final DefaultTier tier = new DefaultTier();
tier.setLimits(limits);
final DefaultPrice[] prices = new DefaultPrice[1];
prices[0] = new DefaultPrice().setCurrency(currency).setValue(recurringAmountInCurrency);
final DefaultInternationalPrice price = new DefaultInternationalPrice().setPrices(prices);
tier.setRecurringPrice(price);
return tier;
}
use of org.killbill.billing.catalog.DefaultPrice in project killbill by killbill.
the class TestDefaultInvoiceGenerator method createMockMonthlyPlanPhase.
private MockPlanPhase createMockMonthlyPlanPhase(@Nullable final BigDecimal recurringRate, @Nullable final BigDecimal fixedCost, final PhaseType phaseType) {
final MockInternationalPrice recurringPrice = (recurringRate == null) ? null : new MockInternationalPrice(new DefaultPrice(recurringRate, Currency.USD));
final MockInternationalPrice fixedPrice = (fixedCost == null) ? null : new MockInternationalPrice(new DefaultPrice(fixedCost, Currency.USD));
return new MockPlanPhase(recurringPrice, fixedPrice, BillingPeriod.MONTHLY, phaseType);
}
Aggregations