Search in sources :

Example 1 with Recurring

use of org.killbill.billing.catalog.api.Recurring 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);
    final Price[] mock = {};
    Mockito.when(price.getPrices()).thenReturn(mock);
    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);
}
Also used : Recurring(org.killbill.billing.catalog.api.Recurring) InternationalPrice(org.killbill.billing.catalog.api.InternationalPrice) Price(org.killbill.billing.catalog.api.Price) Listing(org.killbill.billing.catalog.api.Listing) Product(org.killbill.billing.catalog.api.Product) InternationalPrice(org.killbill.billing.catalog.api.InternationalPrice) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) Plan(org.killbill.billing.catalog.api.Plan) PriceList(org.killbill.billing.catalog.api.PriceList) Test(org.testng.annotations.Test)

Example 2 with Recurring

use of org.killbill.billing.catalog.api.Recurring in project killbill by killbill.

the class TestBlockingCalculator method createRealEvent.

private BillingEvent createRealEvent(final SubscriptionBase subscription, final DateTime effectiveDate, final SubscriptionBaseTransitionType type, final Long totalOrdering) {
    try {
        final Integer billCycleDay = 1;
        final Plan plan = new MockPlan();
        final Currency currency = Currency.USD;
        final String description = "";
        final BillingPeriod billingPeriod = BillingPeriod.MONTHLY;
        final PlanPhase planPhase = Mockito.mock(PlanPhase.class);
        final InternationalPrice internationalPrice = Mockito.mock(InternationalPrice.class);
        Mockito.when(internationalPrice.getPrice(Mockito.<Currency>any())).thenReturn(BigDecimal.TEN);
        final Recurring recurring = Mockito.mock(Recurring.class);
        Mockito.when(recurring.getRecurringPrice()).thenReturn(internationalPrice);
        Mockito.when(planPhase.getRecurring()).thenReturn(recurring);
        Mockito.when(planPhase.getUsages()).thenReturn(new DefaultUsage[0]);
        final BigDecimal fixedPrice = BigDecimal.TEN;
        final BigDecimal recurringPrice = BigDecimal.TEN;
        return new DefaultBillingEvent(subscription.getId(), subscription.getBundleId(), effectiveDate, plan, planPhase, fixedPrice, recurringPrice, ImmutableList.of(), currency, billingPeriod, billCycleDay, description, totalOrdering, type, 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) 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 3 with Recurring

use of org.killbill.billing.catalog.api.Recurring in project killbill by killbill.

the class DefaultPlan method dateOfFirstRecurringNonZeroCharge.

@Override
public DateTime dateOfFirstRecurringNonZeroCharge(final DateTime subscriptionStartDate, final PhaseType initialPhaseType) {
    DateTime result = subscriptionStartDate;
    boolean skipPhase = initialPhaseType != null;
    for (final PlanPhase phase : getAllPhases()) {
        if (skipPhase) {
            if (phase.getPhaseType() != initialPhaseType) {
                continue;
            } else {
                skipPhase = false;
            }
        }
        final Recurring recurring = phase.getRecurring();
        if (phase.getDuration().getUnit() != TimeUnit.UNLIMITED && (recurring == null || recurring.getRecurringPrice() == null || recurring.getRecurringPrice().isZero())) {
            try {
                result = phase.getDuration().addToDateTime(result);
            } catch (final CatalogApiException ignored) {
            }
        } else {
            break;
        }
    }
    return result;
}
Also used : Recurring(org.killbill.billing.catalog.api.Recurring) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) DateTime(org.joda.time.DateTime) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride)

Example 4 with Recurring

use of org.killbill.billing.catalog.api.Recurring 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)

Aggregations

PlanPhase (org.killbill.billing.catalog.api.PlanPhase)4 Recurring (org.killbill.billing.catalog.api.Recurring)4 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)3 InternationalPrice (org.killbill.billing.catalog.api.InternationalPrice)3 Plan (org.killbill.billing.catalog.api.Plan)3 BigDecimal (java.math.BigDecimal)2 MockPlan (org.killbill.billing.catalog.MockPlan)2 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)2 Currency (org.killbill.billing.catalog.api.Currency)2 DateTime (org.joda.time.DateTime)1 DateTimeZone (org.joda.time.DateTimeZone)1 Listing (org.killbill.billing.catalog.api.Listing)1 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)1 Price (org.killbill.billing.catalog.api.Price)1 PriceList (org.killbill.billing.catalog.api.PriceList)1 Product (org.killbill.billing.catalog.api.Product)1 Test (org.testng.annotations.Test)1