use of org.killbill.billing.catalog.api.PlanPhase in project killbill by killbill.
the class TestBillingApi method testBillingEventsSubscriptionAligned.
@Test(groups = "fast")
public void testBillingEventsSubscriptionAligned() throws CatalogApiException, AccountApiException, SubscriptionBaseApiException {
final Plan nextPlan = catalog.findPlan("3-PickupTrialEvergreen10USD", clock.getUTCNow());
final PlanPhase nextPhase = nextPlan.getAllPhases()[1];
final DateTime now = createSubscriptionCreationEvent(nextPlan, nextPhase);
final Account account = createAccount(1);
catalog.setBillingAlignment(BillingAlignment.SUBSCRIPTION);
final SortedSet<BillingEvent> events = billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), null, internalCallContext);
// The expected BCD is when the subscription started since we skip the trial phase
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 BlockingCalculator method createNewDisableEvent.
protected BillingEvent createNewDisableEvent(final DateTime odEventTime, final BillingEvent previousEvent, final Catalog catalog, final InternalTenantContext context) throws CatalogApiException {
final int billCycleDay = previousEvent.getBillCycleDayLocal();
final SubscriptionBase subscription = previousEvent.getSubscription();
final DateTime effectiveDate = odEventTime;
final PlanPhase planPhase = previousEvent.getPlanPhase();
final Plan plan = previousEvent.getPlan();
// Make sure to set the fixed price to null and the billing period to NO_BILLING_PERIOD,
// which makes invoice disregard this event
final BigDecimal fixedPrice = null;
final BillingPeriod billingPeriod = BillingPeriod.NO_BILLING_PERIOD;
final Currency currency = previousEvent.getCurrency();
final String description = "";
final SubscriptionBaseTransitionType type = SubscriptionBaseTransitionType.START_BILLING_DISABLED;
final Long totalOrdering = globaltotalOrder.getAndIncrement();
final DateTimeZone tz = previousEvent.getTimeZone();
return new DefaultBillingEvent(subscription, effectiveDate, true, plan, planPhase, fixedPrice, currency, billingPeriod, billCycleDay, description, totalOrdering, type, tz, catalog, true);
}
use of org.killbill.billing.catalog.api.PlanPhase in project killbill by killbill.
the class BlockingCalculator method createNewReenableEvent.
protected BillingEvent createNewReenableEvent(final DateTime odEventTime, final BillingEvent previousEvent, final Catalog catalog, final InternalTenantContext context) throws CatalogApiException {
// All fields are populated with the event state from before the blocking period, for invoice to resume invoicing
final int billCycleDay = previousEvent.getBillCycleDayLocal();
final SubscriptionBase subscription = previousEvent.getSubscription();
final DateTime effectiveDate = odEventTime;
final PlanPhase planPhase = previousEvent.getPlanPhase();
final BigDecimal fixedPrice = previousEvent.getFixedPrice();
final Plan plan = previousEvent.getPlan();
final Currency currency = previousEvent.getCurrency();
final String description = "";
final BillingPeriod billingPeriod = previousEvent.getBillingPeriod();
final SubscriptionBaseTransitionType type = SubscriptionBaseTransitionType.END_BILLING_DISABLED;
final Long totalOrdering = globaltotalOrder.getAndIncrement();
final DateTimeZone tz = previousEvent.getTimeZone();
return new DefaultBillingEvent(subscription, effectiveDate, true, plan, planPhase, fixedPrice, currency, billingPeriod, billCycleDay, description, totalOrdering, type, tz, catalog, false);
}
use of org.killbill.billing.catalog.api.PlanPhase in project killbill by killbill.
the class TestBillingApi method testBillingEventsAccountAligned.
@Test(groups = "fast")
public void testBillingEventsAccountAligned() throws CatalogApiException, AccountApiException, SubscriptionBaseApiException {
final Plan nextPlan = catalog.findPlan("3-PickupTrialEvergreen10USD", clock.getUTCNow());
final PlanPhase nextPhase = nextPlan.getAllPhases()[1];
final DateTime now = createSubscriptionCreationEvent(nextPlan, nextPhase);
final Account account = createAccount(32);
final SortedSet<BillingEvent> events = billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), null, internalCallContext);
// The expected BCD is the account BCD (account aligned by default)
checkFirstEvent(events, nextPlan, 32, subId, now, nextPhase, SubscriptionBaseTransitionType.CREATE.toString());
}
use of org.killbill.billing.catalog.api.PlanPhase in project killbill by killbill.
the class TestBlockingCalculator method createRealEvent.
protected BillingEvent createRealEvent(final DateTime effectiveDate, final SubscriptionBase subscription, final SubscriptionBaseTransitionType type) {
try {
final Integer billCycleDay = 1;
final Plan plan = new MockPlan();
final Currency currency = Currency.USD;
final String description = "";
final BillingPeriod billingPeriod = BillingPeriod.MONTHLY;
final Long totalOrdering = 0L;
final DateTimeZone tz = DateTimeZone.UTC;
final PlanPhase planPhase = Mockito.mock(PlanPhase.class);
final InternationalPrice recurringPrice = Mockito.mock(InternationalPrice.class);
Mockito.when(recurringPrice.getPrice(Mockito.<Currency>any())).thenReturn(BigDecimal.TEN);
final Recurring recurring = Mockito.mock(Recurring.class);
Mockito.when(recurring.getRecurringPrice()).thenReturn(recurringPrice);
Mockito.when(planPhase.getRecurring()).thenReturn(recurring);
Mockito.when(planPhase.getUsages()).thenReturn(new DefaultUsage[0]);
final BigDecimal fixedPrice = BigDecimal.TEN;
return new DefaultBillingEvent(subscription, effectiveDate, true, plan, planPhase, fixedPrice, currency, billingPeriod, billCycleDay, description, totalOrdering, type, tz, null, false);
} catch (final CatalogApiException e) {
Assert.fail("", e);
}
throw new IllegalStateException();
}
Aggregations