use of org.killbill.billing.catalog.api.PlanPhase in project killbill by killbill.
the class TestBillingApi method testBillingEventsNoBillingPeriod.
@Test(groups = "fast")
public void testBillingEventsNoBillingPeriod() throws CatalogApiException, AccountApiException, SubscriptionBaseApiException {
final Plan nextPlan = catalog.findPlan("3-PickupTrialEvergreen10USD", clock.getUTCNow());
// The trial has no billing period
final PlanPhase nextPhase = nextPlan.getAllPhases()[0];
final DateTime now = createSubscriptionCreationEvent(nextPlan, nextPhase);
final Account account = createAccount(10);
final SortedSet<BillingEvent> events = billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), null, internalCallContext);
checkFirstEvent(events, nextPlan, account.getBillCycleDayLocal(), subId, now, nextPhase, SubscriptionBaseTransitionType.CREATE.toString());
}
use of org.killbill.billing.catalog.api.PlanPhase in project killbill by killbill.
the class TestBillingApi method testBillingEventsBundleAligned.
@Test(groups = "fast")
public void testBillingEventsBundleAligned() throws CatalogApiException, AccountApiException, SubscriptionBaseApiException {
final Plan nextPlan = catalog.findPlan("7-Horn1USD", clock.getUTCNow());
final PlanPhase nextPhase = nextPlan.getAllPhases()[0];
final DateTime now = createSubscriptionCreationEvent(nextPlan, nextPhase);
final Account account = createAccount(1);
catalog.setBillingAlignment(BillingAlignment.BUNDLE);
((MockSubscription) subscription).setPlan(catalog.findPlan("3-PickupTrialEvergreen10USD", now));
final SortedSet<BillingEvent> events = billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), null, internalCallContext);
// The expected BCD is when the subscription started
checkFirstEvent(events, nextPlan, subscription.getStartDate().getDayOfMonth(), subId, now, nextPhase, SubscriptionBaseTransitionType.CREATE.toString());
}
use of org.killbill.billing.catalog.api.PlanPhase 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);
}
use of org.killbill.billing.catalog.api.PlanPhase in project killbill by killbill.
the class EhCacheOverriddenPlanCache method createOverrides.
private PlanPhasePriceOverride[] createOverrides(final Plan defaultPlan, final List<CatalogOverridePhaseDefinitionModelDao> phaseDefs) {
final PlanPhasePriceOverride[] result = new PlanPhasePriceOverride[defaultPlan.getAllPhases().length];
for (int i = 0; i < defaultPlan.getAllPhases().length; i++) {
final PlanPhase curPhase = defaultPlan.getAllPhases()[i];
final CatalogOverridePhaseDefinitionModelDao overriddenPhase = Iterables.tryFind(phaseDefs, new Predicate<CatalogOverridePhaseDefinitionModelDao>() {
@Override
public boolean apply(final CatalogOverridePhaseDefinitionModelDao input) {
return input.getParentPhaseName().equals(curPhase.getName());
}
}).orNull();
result[i] = (overriddenPhase != null) ? new DefaultPlanPhasePriceOverride(curPhase.getName(), Currency.valueOf(overriddenPhase.getCurrency()), overriddenPhase.getFixedPrice(), overriddenPhase.getRecurringPrice()) : null;
}
return result;
}
use of org.killbill.billing.catalog.api.PlanPhase in project killbill by killbill.
the class DefaultPriceOverride method getOrCreateOverriddenPlan.
@Override
public DefaultPlan getOrCreateOverriddenPlan(final StandaloneCatalog standaloneCatalog, final Plan parentPlan, final DateTime catalogEffectiveDate, final List<PlanPhasePriceOverride> overrides, @Nullable final InternalCallContext context) throws CatalogApiException {
final PlanPhasePriceOverride[] resolvedOverride = new PlanPhasePriceOverride[parentPlan.getAllPhases().length];
int index = 0;
for (final PlanPhase curPhase : parentPlan.getAllPhases()) {
final PlanPhasePriceOverride curOverride = Iterables.tryFind(overrides, new Predicate<PlanPhasePriceOverride>() {
@Override
public boolean apply(final PlanPhasePriceOverride input) {
if (input.getPhaseName() != null) {
return input.getPhaseName().equals(curPhase.getName());
}
// If the phaseName was not passed, we infer by matching the phaseType. This obviously would not work in a case where
// a plan is defined with multiple phases of the same type.
final PlanPhaseSpecifier curPlanPhaseSpecifier = input.getPlanPhaseSpecifier();
if (curPlanPhaseSpecifier.getPhaseType().equals(curPhase.getPhaseType())) {
return true;
}
return false;
}
}).orNull();
resolvedOverride[index++] = curOverride != null ? new DefaultPlanPhasePriceOverride(curPhase.getName(), curOverride.getCurrency(), curOverride.getFixedPrice(), curOverride.getRecurringPrice()) : null;
}
for (int i = 0; i < resolvedOverride.length; i++) {
final PlanPhasePriceOverride curOverride = resolvedOverride[i];
if (curOverride != null) {
final DefaultPlanPhase curPhase = (DefaultPlanPhase) parentPlan.getAllPhases()[i];
if (curPhase.getFixed() == null && curOverride.getFixedPrice() != null) {
final String error = String.format("There is no existing fixed price for the phase %s", curPhase.getName());
throw new CatalogApiException(ErrorCode.CAT_INVALID_INVALID_PRICE_OVERRIDE, parentPlan.getName(), error);
}
if (curPhase.getRecurring() == null && curOverride.getRecurringPrice() != null) {
final String error = String.format("There is no existing recurring price for the phase %s", curPhase.getName());
throw new CatalogApiException(ErrorCode.CAT_INVALID_INVALID_PRICE_OVERRIDE, parentPlan.getName(), error);
}
}
}
final String planName;
if (context != null) {
final CatalogOverridePlanDefinitionModelDao overriddenPlan = overrideDao.getOrCreateOverridePlanDefinition(parentPlan.getName(), catalogEffectiveDate, resolvedOverride, context);
planName = new StringBuffer(parentPlan.getName()).append("-").append(overriddenPlan.getRecordId()).toString();
} else {
planName = new StringBuffer(parentPlan.getName()).append("-dryrun-").append(DRY_RUN_PLAN_IDX.incrementAndGet()).toString();
}
final DefaultPlan result = new DefaultPlan(planName, (DefaultPlan) parentPlan, resolvedOverride);
result.initialize(standaloneCatalog, standaloneCatalog.getCatalogURI());
if (context == null) {
overriddenPlanCache.addDryRunPlan(planName, result);
}
return result;
}
Aggregations