use of org.killbill.billing.subscription.events.user.ApiEventTransfer in project killbill by killbill.
the class DefaultSubscriptionBaseTransferApi method createEvent.
private SubscriptionBaseEvent createEvent(final boolean firstEvent, final ExistingEvent existingEvent, final DefaultSubscriptionBase subscription, final DateTime transferDate, final InternalTenantContext context) throws CatalogApiException {
SubscriptionBaseEvent newEvent = null;
final Catalog catalog = catalogService.getFullCatalog(true, true, context);
final DateTime effectiveDate = existingEvent.getEffectiveDate().isBefore(transferDate) ? transferDate : existingEvent.getEffectiveDate();
final PlanPhaseSpecifier spec = existingEvent.getPlanPhaseSpecifier();
final PlanPhase currentPhase = existingEvent.getPlanPhaseName() != null ? catalog.findPhase(existingEvent.getPlanPhaseName(), effectiveDate, subscription.getAlignStartDate()) : null;
if (spec == null || currentPhase == null) {
// Ignore cancellations - we assume that transferred subscriptions should always be active
return null;
}
final ApiEventBuilder apiBuilder = new ApiEventBuilder().setSubscriptionId(subscription.getId()).setEventPlan(existingEvent.getPlanName()).setEventPlanPhase(currentPhase.getName()).setEventPriceList(spec.getPriceListName()).setEffectiveDate(effectiveDate).setFromDisk(true);
switch(existingEvent.getSubscriptionTransitionType()) {
case TRANSFER:
case CREATE:
newEvent = new ApiEventTransfer(apiBuilder);
break;
// Should we even keep future change events; product question really
case CHANGE:
newEvent = firstEvent ? new ApiEventTransfer(apiBuilder) : new ApiEventChange(apiBuilder);
break;
case PHASE:
newEvent = firstEvent ? new ApiEventTransfer(apiBuilder) : PhaseEventData.createNextPhaseEvent(subscription.getId(), currentPhase.getName(), effectiveDate);
break;
case CANCEL:
break;
default:
throw new SubscriptionBaseError(String.format("Unexpected transitionType %s", existingEvent.getSubscriptionTransitionType()));
}
return newEvent;
}
Aggregations