Search in sources :

Example 46 with PlanPhasePriceOverride

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

the class TestIntegrationInvoice method testIntegrationWithRecurringFreePlan.

@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/783")
public void testIntegrationWithRecurringFreePlan() throws Exception {
    final DateTime initialCreationDate = new DateTime(2017, 1, 1, 0, 0, 0, 0, testTimeZone);
    // set clock to the initial start date
    clock.setTime(initialCreationDate);
    final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(1));
    final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Blowdart", BillingPeriod.MONTHLY, "notrial", null);
    // Price override of $0
    final List<PlanPhasePriceOverride> overrides = new ArrayList<PlanPhasePriceOverride>();
    overrides.add(new DefaultPlanPhasePriceOverride("blowdart-monthly-notrial-evergreen", account.getCurrency(), null, BigDecimal.ZERO, ImmutableList.<UsagePriceOverride>of()));
    busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
    final UUID entitlementId = entitlementApi.createBaseEntitlement(account.getId(), new DefaultEntitlementSpecifier(spec, null, null, overrides), "bundleExternalKey", null, null, false, true, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementId, callContext);
    invoiceChecker.checkInvoice(account.getId(), 1, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2017, 1, 1), new LocalDate(2017, 2, 1), InvoiceItemType.RECURRING, BigDecimal.ZERO));
    // 2017-02-01
    busHandler.pushExpectedEvents(NextEvent.INVOICE);
    clock.addMonths(1);
    assertListenerStatus();
    invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2017, 2, 1), new LocalDate(2017, 3, 1), InvoiceItemType.RECURRING, BigDecimal.ZERO));
    // Do the change mid-month so the repair triggers the bug in https://github.com/killbill/killbill/issues/783
    entitlement.changePlanWithDate(new DefaultEntitlementSpecifier(spec), new LocalDate("2017-02-15"), ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    // 2017-02-15
    busHandler.pushExpectedEvents(NextEvent.CHANGE, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
    clock.addDays(15);
    assertListenerStatus();
    // Note: no repair
    invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2017, 2, 1), new LocalDate(2017, 3, 1), InvoiceItemType.RECURRING, BigDecimal.ZERO));
    invoiceChecker.checkInvoice(account.getId(), 3, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2017, 2, 1), new LocalDate(2017, 2, 15), InvoiceItemType.RECURRING, BigDecimal.ZERO), new ExpectedInvoiceItemCheck(new LocalDate(2017, 2, 15), new LocalDate(2017, 3, 1), InvoiceItemType.RECURRING, new BigDecimal("14.98")));
    // 2017-03-01
    busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
    clock.addDays(15);
    assertListenerStatus();
    invoiceChecker.checkInvoice(account.getId(), 4, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2017, 3, 1), new LocalDate(2017, 4, 1), InvoiceItemType.RECURRING, new BigDecimal("29.95")));
    // 2017-04-01
    busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
    clock.addMonths(1);
    assertListenerStatus();
    invoiceChecker.checkInvoice(account.getId(), 5, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2017, 4, 1), new LocalDate(2017, 5, 1), InvoiceItemType.RECURRING, new BigDecimal("29.95")));
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Account(org.killbill.billing.account.api.Account) DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride) ArrayList(java.util.ArrayList) UsagePriceOverride(org.killbill.billing.catalog.api.UsagePriceOverride) ExpectedInvoiceItemCheck(org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) DefaultEntitlementSpecifier(org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier) UUID(java.util.UUID) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) Entitlement(org.killbill.billing.entitlement.api.Entitlement) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride) DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride) Test(org.testng.annotations.Test)

Example 47 with PlanPhasePriceOverride

use of org.killbill.billing.catalog.api.PlanPhasePriceOverride 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 48 with PlanPhasePriceOverride

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

the class SubscriptionResourceHelpers method buildEntitlementSpecifier.

public static EntitlementSpecifier buildEntitlementSpecifier(final SubscriptionJson subscriptionJson, final Currency currency, final String externalKey) {
    final PlanPhaseSpecifier planPhaseSpecifier = subscriptionJson.getPlanName() != null ? new PlanPhaseSpecifier(subscriptionJson.getPlanName(), subscriptionJson.getPhaseType()) : new PlanPhaseSpecifier(subscriptionJson.getProductName(), subscriptionJson.getBillingPeriod(), subscriptionJson.getPriceList(), subscriptionJson.getPhaseType());
    final List<PlanPhasePriceOverride> overrides = buildPlanPhasePriceOverrides(subscriptionJson.getPriceOverrides(), currency, planPhaseSpecifier);
    return new EntitlementSpecifier() {

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

        @Override
        public Integer getBillCycleDay() {
            return subscriptionJson.getBillCycleDayLocal();
        }

        @Override
        public String getExternalKey() {
            return externalKey;
        }

        @Override
        public List<PlanPhasePriceOverride> getOverrides() {
            return overrides;
        }
    };
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) EntitlementSpecifier(org.killbill.billing.entitlement.api.EntitlementSpecifier) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride)

Example 49 with PlanPhasePriceOverride

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

PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)49 ArrayList (java.util.ArrayList)28 DateTime (org.joda.time.DateTime)26 DefaultPlanPhasePriceOverride (org.killbill.billing.catalog.DefaultPlanPhasePriceOverride)24 Test (org.testng.annotations.Test)24 BigDecimal (java.math.BigDecimal)22 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)16 Plan (org.killbill.billing.catalog.api.Plan)15 LocalDate (org.joda.time.LocalDate)14 Account (org.killbill.billing.account.api.Account)14 UsagePriceOverride (org.killbill.billing.catalog.api.UsagePriceOverride)13 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)12 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)11 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)10 DefaultEntitlementSpecifier (org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier)9 Predicate (com.google.common.base.Predicate)8 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)8 Entitlement (org.killbill.billing.entitlement.api.Entitlement)8 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)7 UUID (java.util.UUID)6