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")));
}
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;
}
};
}
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;
}
};
}
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;
}
Aggregations