use of org.killbill.billing.catalog.api.BillingPeriod 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.BillingPeriod 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();
}
use of org.killbill.billing.catalog.api.BillingPeriod in project killbill by killbill.
the class TestPlanDetailJson method testJson.
@Test(groups = "fast")
public void testJson() throws Exception {
final String productName = UUID.randomUUID().toString();
final String planName = UUID.randomUUID().toString();
final BillingPeriod billingPeriod = BillingPeriod.ANNUAL;
final String priceListName = UUID.randomUUID().toString();
final PlanDetailJson planDetailJason = new PlanDetailJson(productName, planName, billingPeriod, priceListName, null);
Assert.assertEquals(planDetailJason.getProduct(), productName);
Assert.assertEquals(planDetailJason.getPlan(), planName);
Assert.assertEquals(planDetailJason.getFinalPhaseBillingPeriod(), billingPeriod);
Assert.assertEquals(planDetailJason.getPriceList(), priceListName);
Assert.assertEquals(planDetailJason.getFinalPhaseRecurringPrice(), null);
final String asJson = mapper.writeValueAsString(planDetailJason);
Assert.assertEquals(asJson, "{\"product\":\"" + planDetailJason.getProduct() + "\"," + "\"plan\":\"" + planDetailJason.getPlan() + "\"," + "\"priceList\":\"" + planDetailJason.getPriceList() + "\"," + "\"finalPhaseBillingPeriod\":\"" + planDetailJason.getFinalPhaseBillingPeriod().toString() + "\"," + "\"finalPhaseRecurringPrice\":null}");
final PlanDetailJson fromJson = mapper.readValue(asJson, PlanDetailJson.class);
Assert.assertEquals(fromJson, planDetailJason);
}
use of org.killbill.billing.catalog.api.BillingPeriod in project killbill by killbill.
the class TestUserApiChangePlan method testInvalidChangesAcrossProductTypes.
@Test(groups = "slow")
public void testInvalidChangesAcrossProductTypes() throws SubscriptionBaseApiException {
final String baseProduct = "Shotgun";
final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
// CREATE BP
final DefaultSubscriptionBase baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
// MOVE CLOCK 14 DAYS LATER
Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(14));
clock.addDeltaFromReality(it.toDurationMillis());
// Create AO
final String aoProduct = "Laser-Scope";
final BillingPeriod aoTerm = BillingPeriod.MONTHLY;
final String aoPriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
DefaultSubscriptionBase aoSubscription = testUtil.createSubscription(bundle, aoProduct, aoTerm, aoPriceList);
try {
aoSubscription.changePlanWithDate(new PlanSpecifier(baseProduct, baseTerm, basePriceList), null, clock.getUTCNow(), callContext);
Assert.fail("Should not allow plan change across product type");
} catch (final SubscriptionBaseApiException e) {
Assert.assertEquals(e.getCode(), ErrorCode.SUB_CHANGE_INVALID.getCode());
}
}
use of org.killbill.billing.catalog.api.BillingPeriod in project killbill by killbill.
the class TestUserApiCreate method testSubscriptionWithAddOn.
@Test(groups = "slow")
public void testSubscriptionWithAddOn() throws SubscriptionBaseApiException {
final String productName = "Shotgun";
final BillingPeriod term = BillingPeriod.ANNUAL;
final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME;
testListener.pushExpectedEvent(NextEvent.CREATE);
final DefaultSubscriptionBase subscription = (DefaultSubscriptionBase) subscriptionInternalApi.createSubscription(bundle.getId(), testUtil.getProductSpecifier(productName, planSetName, term, null), null, clock.getUTCNow(), false, internalCallContext);
assertNotNull(subscription);
assertListenerStatus();
}
Aggregations