use of org.killbill.billing.entitlement.api.DefaultEntitlement in project killbill by killbill.
the class TestIntegration method testThirtyDaysPlanWithFixedTermMonthlyAddOn.
@Test(groups = "slow")
public void testThirtyDaysPlanWithFixedTermMonthlyAddOn() throws Exception {
// Set clock to the initial start date - we implicitly assume here that the account timezone is UTC
clock.setDay(new LocalDate(2015, 4, 1));
final AccountData accountData = getAccountData(1);
final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
accountChecker.checkAccount(account.getId(), accountData, callContext);
final List<ExpectedInvoiceItemCheck> expectedInvoices = new ArrayList<ExpectedInvoiceItemCheck>();
// First invoice
final DefaultEntitlement bpSubscription = createBaseEntitlementAndCheckForCompletion(account.getId(), "bundleKey", "Pistol", ProductCategory.BASE, BillingPeriod.THIRTY_DAYS, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2015, 4, 1), null, InvoiceItemType.FIXED, BigDecimal.ZERO));
invoiceChecker.checkInvoice(account.getId(), 1, callContext, expectedInvoices);
expectedInvoices.clear();
// Second invoice -> first recurring for Refurbish-Maintenance
addAOEntitlementAndCheckForCompletion(bpSubscription.getBundleId(), "Refurbish-Maintenance", ProductCategory.ADD_ON, BillingPeriod.MONTHLY, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2015, 4, 1), null, InvoiceItemType.FIXED, new BigDecimal("599.95")));
expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2015, 4, 1), new LocalDate(2015, 5, 1), InvoiceItemType.RECURRING, new BigDecimal("199.95")));
invoiceChecker.checkInvoice(account.getId(), 2, callContext, expectedInvoices);
expectedInvoices.clear();
// 2015-5-1
expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2015, 5, 1), new LocalDate(2015, 5, 31), InvoiceItemType.RECURRING, new BigDecimal("29.95")));
expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2015, 5, 1), new LocalDate(2015, 6, 1), InvoiceItemType.RECURRING, new BigDecimal("199.95")));
busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.NULL_INVOICE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
// Also = 1 month because or initial date 2015, 4, 1
clock.addDays(30);
assertListenerStatus();
invoiceChecker.checkInvoice(account.getId(), 3, callContext, expectedInvoices);
expectedInvoices.clear();
// Next 20 invoices, including last recurring for Refurbish-Maintenance
LocalDate startDateBase = new LocalDate(2015, 5, 31);
LocalDate startDateAddOn = new LocalDate(2015, 6, 1);
for (int i = 0; i < 10; i++) {
final LocalDate endDateBase = startDateBase.plusDays(30);
expectedInvoices.add(new ExpectedInvoiceItemCheck(startDateBase, endDateBase, InvoiceItemType.RECURRING, new BigDecimal("29.95")));
busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
clock.setDay(startDateBase);
assertListenerStatus();
invoiceChecker.checkInvoice(account.getId(), 4 + 2 * i, callContext, expectedInvoices);
expectedInvoices.clear();
final LocalDate endDateAddOn = startDateAddOn.plusMonths(1);
expectedInvoices.add(new ExpectedInvoiceItemCheck(startDateAddOn, endDateAddOn, InvoiceItemType.RECURRING, new BigDecimal("199.95")));
busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
clock.setDay(startDateAddOn);
assertListenerStatus();
invoiceChecker.checkInvoice(account.getId(), 5 + 2 * i, callContext, expectedInvoices);
expectedInvoices.clear();
startDateBase = endDateBase;
startDateAddOn = endDateAddOn;
}
// clock at 2016-03-01
expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2016, 3, 26), new LocalDate(2016, 4, 25), InvoiceItemType.RECURRING, new BigDecimal("29.95")));
busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
clock.setDay(new LocalDate(2016, 3, 26));
assertListenerStatus();
invoiceChecker.checkInvoice(account.getId(), 24, callContext, expectedInvoices);
expectedInvoices.clear();
// We check there is no more recurring for Refurbish-Maintenance
busHandler.pushExpectedEvents(NextEvent.NULL_INVOICE);
clock.setDay(new LocalDate(2016, 4, 1));
assertListenerStatus();
}
use of org.killbill.billing.entitlement.api.DefaultEntitlement in project killbill by killbill.
the class TestIntegration method testWithPauseResume.
@Test(groups = "slow")
public void testWithPauseResume() throws Exception {
final DateTime initialDate = new DateTime(2012, 2, 1, 0, 3, 42, 0, testTimeZone);
final int billingDay = 2;
// set clock to the initial start date
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(billingDay));
final UUID accountId = account.getId();
assertNotNull(account);
final String productName = "Shotgun";
final BillingPeriod term = BillingPeriod.MONTHLY;
final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME;
//
// CREATE SUBSCRIPTION AND EXPECT BOTH EVENTS: NextEvent.CREATE, NextEvent.BLOCK NextEvent.INVOICE
//
final DefaultEntitlement baseEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "bundleKey", productName, ProductCategory.BASE, term, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
assertNotNull(baseEntitlement);
//
// VERIFY CTD HAS BEEN SET
//
final DefaultSubscriptionBase subscription = (DefaultSubscriptionBase) baseEntitlement.getSubscriptionBase();
final DateTime startDate = subscription.getCurrentPhaseStart();
final BigDecimal rate = subscription.getCurrentPhase().getFixed().getPrice().getPrice(Currency.USD);
verifyTestResult(accountId, subscription.getId(), startDate, null, rate, clock.getUTCNow(), 1);
//
// MOVE TIME TO AFTER TRIAL AND EXPECT BOTH EVENTS : NextEvent.PHASE NextEvent.INVOICE
//
busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
clock.addDeltaFromReality(AT_LEAST_ONE_MONTH_MS);
assertListenerStatus();
invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 3, 2), new LocalDate(2012, 4, 2), InvoiceItemType.RECURRING, new BigDecimal("249.95")));
// PAUSE THE ENTITLEMENT
DefaultEntitlement entitlement = (DefaultEntitlement) entitlementApi.getEntitlementForId(baseEntitlement.getId(), callContext);
busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.INVOICE);
entitlementApi.pause(entitlement.getBundleId(), clock.getUTCNow().toLocalDate(), ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 3, 2), new LocalDate(2012, 4, 2), InvoiceItemType.RECURRING, new BigDecimal("249.95")));
invoiceChecker.checkInvoice(account.getId(), 3, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 3, 4), new LocalDate(2012, 4, 2), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-233.82")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 3, 4), new LocalDate(2012, 3, 4), InvoiceItemType.CBA_ADJ, new BigDecimal("233.82")));
entitlement = (DefaultEntitlement) entitlementApi.getEntitlementForId(baseEntitlement.getId(), callContext);
Assert.assertEquals(entitlement.getState(), EntitlementState.BLOCKED);
// MOVE CLOCK FORWARD ADN CHECK THERE IS NO NEW INVOICE
clock.addDeltaFromReality(AT_LEAST_ONE_MONTH_MS);
busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.NULL_INVOICE, NextEvent.INVOICE);
entitlementApi.resume(entitlement.getBundleId(), clock.getUTCNow().toLocalDate(), ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
invoiceChecker.checkInvoice(account.getId(), 4, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 4, 5), new LocalDate(2012, 5, 2), InvoiceItemType.RECURRING, new BigDecimal("224.96")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 4, 5), new LocalDate(2012, 4, 5), InvoiceItemType.CBA_ADJ, new BigDecimal("-224.96")));
checkNoMoreInvoiceToGenerate(account);
}
use of org.killbill.billing.entitlement.api.DefaultEntitlement in project killbill by killbill.
the class TestIntegration method testWithPauseResumeAfterENT_CANCELLEDBlockingState.
@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/715")
public void testWithPauseResumeAfterENT_CANCELLEDBlockingState() throws Exception {
final DateTime initialDate = new DateTime(2012, 2, 1, 0, 3, 42, 0, testTimeZone);
final int billingDay = 2;
// set clock to the initial start date
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(billingDay));
final UUID accountId = account.getId();
assertNotNull(account);
final String productName = "Shotgun";
final BillingPeriod term = BillingPeriod.MONTHLY;
//
// CREATE SUBSCRIPTION AND EXPECT BOTH EVENTS: NextEvent.CREATE, NextEvent.BLOCK NextEvent.INVOICE
//
final DefaultEntitlement baseEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "bundleKey", productName, ProductCategory.BASE, term, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
assertNotNull(baseEntitlement);
//
// VERIFY CTD HAS BEEN SET
//
final DefaultSubscriptionBase subscription = (DefaultSubscriptionBase) baseEntitlement.getSubscriptionBase();
final DateTime startDate = subscription.getCurrentPhaseStart();
final BigDecimal rate = subscription.getCurrentPhase().getFixed().getPrice().getPrice(Currency.USD);
verifyTestResult(accountId, subscription.getId(), startDate, null, rate, clock.getUTCNow(), 1);
//
// MOVE TIME TO AFTER TRIAL (2012-03-04)
//
busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
clock.addDeltaFromReality(AT_LEAST_ONE_MONTH_MS);
assertListenerStatus();
invoiceChecker.checkInvoice(accountId, 1, callContext, ImmutableList.<ExpectedInvoiceItemCheck>of(new ExpectedInvoiceItemCheck(new LocalDate(2012, 2, 1), null, InvoiceItemType.FIXED, BigDecimal.ZERO)));
invoiceChecker.checkInvoice(accountId, 2, callContext, ImmutableList.<ExpectedInvoiceItemCheck>of(new ExpectedInvoiceItemCheck(new LocalDate(2012, 3, 2), new LocalDate(2012, 4, 2), InvoiceItemType.RECURRING, new BigDecimal("249.95"))));
// Pause the entitlement between 2012-03-05 and 2012-03-15
DefaultEntitlement entitlement = (DefaultEntitlement) entitlementApi.getEntitlementForId(baseEntitlement.getId(), callContext);
entitlementApi.pause(entitlement.getBundleId(), new LocalDate(2012, 3, 5), ImmutableList.<PluginProperty>of(), callContext);
entitlementApi.resume(entitlement.getBundleId(), new LocalDate(2012, 3, 15), ImmutableList.<PluginProperty>of(), callContext);
// Advance clock to 2012-03-07
busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.INVOICE);
clock.addDays(3);
assertListenerStatus();
invoiceChecker.checkInvoice(accountId, 2, callContext, ImmutableList.<ExpectedInvoiceItemCheck>of(new ExpectedInvoiceItemCheck(new LocalDate(2012, 3, 2), new LocalDate(2012, 4, 2), InvoiceItemType.RECURRING, new BigDecimal("249.95"))));
invoiceChecker.checkInvoice(accountId, 3, callContext, ImmutableList.<ExpectedInvoiceItemCheck>of(new ExpectedInvoiceItemCheck(new LocalDate(2012, 3, 5), new LocalDate(2012, 4, 2), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-225.76")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 3, 7), new LocalDate(2012, 3, 7), InvoiceItemType.CBA_ADJ, new BigDecimal("225.76"))));
// Entitlement should be blocked
entitlement = (DefaultEntitlement) entitlementApi.getEntitlementForId(baseEntitlement.getId(), callContext);
Assert.assertEquals(entitlement.getState(), EntitlementState.BLOCKED);
// Advance clock to 2012-03-12, nothing should happen
clock.addDays(5);
assertListenerStatus();
// Entitlement is still blocked
entitlement = (DefaultEntitlement) entitlementApi.getEntitlementForId(baseEntitlement.getId(), callContext);
Assert.assertEquals(entitlement.getState(), EntitlementState.BLOCKED);
List<Invoice> invoices = invoiceUserApi.getInvoicesByAccount(accountId, false, callContext);
assertEquals(invoices.size(), 3);
// Cancel entitlement start of term but with billing policy immediate (ENT_BLOCKED must be after ENT_CANCELLED to trigger the bug)
busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.CANCEL, NextEvent.NULL_INVOICE);
baseEntitlement.cancelEntitlementWithDateOverrideBillingPolicy(new LocalDate(2012, 3, 2), BillingActionPolicy.IMMEDIATE, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
// 2012-03-16
busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.NULL_INVOICE);
clock.addDays(4);
assertListenerStatus();
busHandler.pushExpectedEvents(NextEvent.NULL_INVOICE);
clock.addMonths(3);
assertListenerStatus();
// No new invoices
invoices = invoiceUserApi.getInvoicesByAccount(accountId, false, callContext);
assertEquals(invoices.size(), 3);
}
use of org.killbill.billing.entitlement.api.DefaultEntitlement in project killbill by killbill.
the class TestIntegrationWithAutoInvoiceOffTag method testAutoInvoiceOffMultipleSubscriptions.
@Test(groups = "slow")
public void testAutoInvoiceOffMultipleSubscriptions() throws Exception {
clock.setTime(new DateTime(2012, 5, 1, 0, 3, 42, 0));
// set next invoice to fail and create network
final DefaultEntitlement bpEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "externalKey", productName, ProductCategory.BASE, term, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
assertNotNull(bpEntitlement);
final DefaultEntitlement bpEntitlement2 = createBaseEntitlementAndCheckForCompletion(account.getId(), "whatever", productName, ProductCategory.BASE, term, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
assertNotNull(bpEntitlement2);
Collection<Invoice> invoices = invoiceApi.getInvoicesByAccount(account.getId(), false, callContext);
// first invoice is generated immediately after creation can't reliably stop it
assertEquals(invoices.size(), 2);
add_AUTO_INVOICING_OFF_Tag(bpEntitlement.getSubscriptionBase().getBundleId(), ObjectType.BUNDLE);
busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.PHASE, NextEvent.NULL_INVOICE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
// DAY 40 out of trial
clock.addDays(40);
assertListenerStatus();
invoices = invoiceApi.getInvoicesByAccount(account.getId(), false, callContext);
// Only one additional invoice generated
assertEquals(invoices.size(), 3);
}
use of org.killbill.billing.entitlement.api.DefaultEntitlement in project killbill by killbill.
the class TestIntegrationWithAutoPayOff method testAutoPayOffWithPaymentFailure.
@Test(groups = "slow")
public void testAutoPayOffWithPaymentFailure() throws Exception {
clock.setTime(new DateTime(2012, 5, 1, 0, 3, 42, 0));
add_AUTO_PAY_OFF_Tag(account.getId(), ObjectType.ACCOUNT);
final DefaultEntitlement bpEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "externalKey", productName, ProductCategory.BASE, term, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
assertNotNull(bpEntitlement);
Collection<Invoice> invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext);
assertEquals(invoices.size(), 1);
busHandler.pushExpectedEvents(NextEvent.PHASE);
busHandler.pushExpectedEvents(NextEvent.INVOICE);
// After trial
clock.addDays(40);
assertListenerStatus();
invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext);
assertEquals(invoices.size(), 2);
for (Invoice cur : invoices) {
if (cur.getChargedAmount().compareTo(BigDecimal.ZERO) == 0) {
continue;
}
assertEquals(cur.getBalance(), cur.getChargedAmount());
}
paymentPlugin.makeNextPaymentFailWithError();
remove_AUTO_PAY_OFF_Tag(account.getId(), ObjectType.ACCOUNT, NextEvent.PAYMENT_ERROR, NextEvent.INVOICE_PAYMENT_ERROR);
addDelayBceauseOfLackOfCorrectSynchro();
invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext);
assertEquals(invoices.size(), 2);
for (Invoice cur : invoices) {
if (cur.getChargedAmount().compareTo(BigDecimal.ZERO) == 0) {
continue;
}
assertEquals(cur.getBalance(), cur.getChargedAmount());
}
assertListenerStatus();
int nbDaysBeforeRetry = paymentConfig.getPaymentFailureRetryDays(internalCallContext).get(0);
// MOVE TIME FOR RETRY TO HAPPEN
busHandler.pushExpectedEvents(NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
clock.addDays(nbDaysBeforeRetry + 1);
assertListenerStatus();
invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext);
for (Invoice cur : invoices) {
if (cur.getChargedAmount().compareTo(BigDecimal.ZERO) == 0) {
continue;
}
assertTrue(cur.getBalance().compareTo(BigDecimal.ZERO) == 0);
assertTrue(cur.getPaidAmount().compareTo(cur.getChargedAmount()) == 0);
}
assertListenerStatus();
}
Aggregations