Search in sources :

Example 16 with UsagePriceOverride

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

the class SubscriptionResourceHelpers method buildPlanPhasePriceOverride.

private static PlanPhasePriceOverride buildPlanPhasePriceOverride(final PlanSpecifier spec, final Currency currency, final PhasePriceJson input, final List<UsagePriceOverride> usagePrices) {
    if (input.getPhaseName() != null) {
        return new PlanPhasePriceOverride() {

            @Override
            public String getPhaseName() {
                return input.getPhaseName();
            }

            @Override
            public PlanPhaseSpecifier getPlanPhaseSpecifier() {
                return null;
            }

            @Override
            public Currency getCurrency() {
                return currency;
            }

            @Override
            public BigDecimal getFixedPrice() {
                return input.getFixedPrice();
            }

            @Override
            public BigDecimal getRecurringPrice() {
                return input.getRecurringPrice();
            }

            @Override
            public List<UsagePriceOverride> getUsagePriceOverrides() {
                return usagePrices;
            }
        };
    }
    final PhaseType phaseType = input.getPhaseType() != null ? PhaseType.valueOf(input.getPhaseType()) : null;
    final PlanPhaseSpecifier planPhaseSpecifier = spec.getPlanName() != null ? new PlanPhaseSpecifier(spec.getPlanName(), phaseType) : new PlanPhaseSpecifier(spec.getProductName(), spec.getBillingPeriod(), spec.getPriceListName(), phaseType);
    final Currency resolvedCurrency = input.getFixedPrice() != null || input.getRecurringPrice() != null ? currency : null;
    return new PlanPhasePriceOverride() {

        @Override
        public String getPhaseName() {
            return null;
        }

        @Override
        public PlanPhaseSpecifier getPlanPhaseSpecifier() {
            return planPhaseSpecifier;
        }

        @Override
        public Currency getCurrency() {
            return resolvedCurrency;
        }

        @Override
        public BigDecimal getFixedPrice() {
            return input.getFixedPrice();
        }

        @Override
        public BigDecimal getRecurringPrice() {
            return input.getRecurringPrice();
        }

        @Override
        public List<UsagePriceOverride> getUsagePriceOverrides() {
            return usagePrices;
        }
    };
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Currency(org.killbill.billing.catalog.api.Currency) PhaseType(org.killbill.billing.catalog.api.PhaseType) UsagePriceOverride(org.killbill.billing.catalog.api.UsagePriceOverride) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride)

Example 17 with UsagePriceOverride

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

the class SubscriptionResourceHelpers method buildPlanPhasePriceOverrides.

public static List<PlanPhasePriceOverride> buildPlanPhasePriceOverrides(final Iterable<PhasePriceJson> priceOverrides, final Currency currency, final PlanPhaseSpecifier planPhaseSpecifier) {
    final List<PlanPhasePriceOverride> overrides = new LinkedList<PlanPhasePriceOverride>();
    if (priceOverrides != null) {
        for (final PhasePriceJson input : priceOverrides) {
            Preconditions.checkNotNull(input);
            final List<UsagePriceOverride> usagePrices = new LinkedList<UsagePriceOverride>();
            if (input.getUsagePrices() != null) {
                buildUsagePrices(currency, input, usagePrices);
            }
            overrides.add(buildPlanPhasePriceOverride(planPhaseSpecifier, currency, input, usagePrices));
        }
    }
    return overrides;
}
Also used : UsagePriceOverride(org.killbill.billing.catalog.api.UsagePriceOverride) LinkedList(java.util.LinkedList) PhasePriceJson(org.killbill.billing.jaxrs.json.PhasePriceJson) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride)

Aggregations

UsagePriceOverride (org.killbill.billing.catalog.api.UsagePriceOverride)17 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)14 ArrayList (java.util.ArrayList)11 BigDecimal (java.math.BigDecimal)9 DateTime (org.joda.time.DateTime)9 DefaultPlanPhasePriceOverride (org.killbill.billing.catalog.DefaultPlanPhasePriceOverride)9 TierPriceOverride (org.killbill.billing.catalog.api.TierPriceOverride)8 Test (org.testng.annotations.Test)8 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)7 Predicate (com.google.common.base.Predicate)6 DefaultUsagePriceOverride (org.killbill.billing.catalog.DefaultUsagePriceOverride)6 TieredBlockPriceOverride (org.killbill.billing.catalog.api.TieredBlockPriceOverride)6 LocalDate (org.joda.time.LocalDate)5 Account (org.killbill.billing.account.api.Account)5 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)5 DefaultTierPriceOverride (org.killbill.billing.catalog.DefaultTierPriceOverride)5 DefaultEntitlementSpecifier (org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier)5 UUID (java.util.UUID)4 Plan (org.killbill.billing.catalog.api.Plan)4 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)4