Search in sources :

Example 51 with BillingPeriod

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);
}
Also used : BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) SubscriptionBaseTransitionType(org.killbill.billing.subscription.api.SubscriptionBaseTransitionType) Plan(org.killbill.billing.catalog.api.Plan) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) DateTimeZone(org.joda.time.DateTimeZone) SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) Currency(org.killbill.billing.catalog.api.Currency) AtomicLong(java.util.concurrent.atomic.AtomicLong) PlanPhase(org.killbill.billing.catalog.api.PlanPhase)

Example 52 with BillingPeriod

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();
}
Also used : BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) InternationalPrice(org.killbill.billing.catalog.api.InternationalPrice) MockPlan(org.killbill.billing.catalog.MockPlan) Plan(org.killbill.billing.catalog.api.Plan) DateTimeZone(org.joda.time.DateTimeZone) BigDecimal(java.math.BigDecimal) Recurring(org.killbill.billing.catalog.api.Recurring) MockPlan(org.killbill.billing.catalog.MockPlan) Currency(org.killbill.billing.catalog.api.Currency) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) PlanPhase(org.killbill.billing.catalog.api.PlanPhase)

Example 53 with BillingPeriod

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);
}
Also used : BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) Test(org.testng.annotations.Test)

Example 54 with BillingPeriod

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());
    }
}
Also used : BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) Interval(org.joda.time.Interval) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 55 with BillingPeriod

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();
}
Also used : BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) Test(org.testng.annotations.Test)

Aggregations

BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)80 Test (org.testng.annotations.Test)69 DateTime (org.joda.time.DateTime)53 LocalDate (org.joda.time.LocalDate)30 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)29 BigDecimal (java.math.BigDecimal)28 Account (org.killbill.billing.account.api.Account)27 Invoice (org.killbill.billing.invoice.api.Invoice)26 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)20 Interval (org.joda.time.Interval)18 Plan (org.killbill.billing.catalog.api.Plan)16 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)16 ArrayList (java.util.ArrayList)11 Duration (org.killbill.billing.catalog.api.Duration)9 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)9 DefaultSubscriptionBase (org.killbill.billing.subscription.api.user.DefaultSubscriptionBase)9 Account (org.killbill.billing.client.model.Account)7 Subscription (org.killbill.billing.client.model.Subscription)7 SubscriptionBaseBundle (org.killbill.billing.subscription.api.user.SubscriptionBaseBundle)7 UUID (java.util.UUID)6