Search in sources :

Example 26 with PlanSpecifier

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

the class TestUserApiChangePlan method testInvalidChangesAcrossProductTypes.

@Test(groups = "slow")
public void testInvalidChangesAcrossProductTypes() throws SubscriptionBaseApiException {
    final String baseProduct = "Shotgun";
    final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
    final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
    // CREATE BP
    final DefaultSubscriptionBase baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList);
    // MOVE CLOCK 14 DAYS LATER
    Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(14));
    clock.addDeltaFromReality(it.toDurationMillis());
    // Create AO
    final String aoProduct = "Laser-Scope";
    final BillingPeriod aoTerm = BillingPeriod.MONTHLY;
    final String aoPriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
    DefaultSubscriptionBase aoSubscription = testUtil.createSubscription(bundle, aoProduct, aoTerm, aoPriceList);
    try {
        aoSubscription.changePlanWithDate(new PlanSpecifier(baseProduct, baseTerm, basePriceList), null, clock.getUTCNow(), callContext);
        Assert.fail("Should not allow plan change across product type");
    } catch (final SubscriptionBaseApiException e) {
        Assert.assertEquals(e.getCode(), ErrorCode.SUB_CHANGE_INVALID.getCode());
    }
}
Also used : BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) Interval(org.joda.time.Interval) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 27 with PlanSpecifier

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

the class TestUserApiError method testChangeSubscriptionNonActive.

@Test(groups = "fast")
public void testChangeSubscriptionNonActive() throws SubscriptionBaseApiException {
    final SubscriptionBase subscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME);
    testListener.pushExpectedEvent(NextEvent.CANCEL);
    subscription.cancelWithDate(clock.getUTCNow(), callContext);
    try {
        subscription.changePlanWithDate(new PlanSpecifier("Pistol", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME), null, clock.getUTCNow(), callContext);
    } catch (final SubscriptionBaseApiException e) {
        assertEquals(e.getCode(), ErrorCode.SUB_CHANGE_NON_ACTIVE.getCode());
    }
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 28 with PlanSpecifier

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

the class TestUserApiError method testChangeSubscriptionFutureCancelled.

@Test(groups = "fast")
public void testChangeSubscriptionFutureCancelled() throws SubscriptionBaseApiException {
    SubscriptionBase subscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
    final PlanPhase trialPhase = subscription.getCurrentPhase();
    // MOVE TO NEXT PHASE
    final PlanPhase currentPhase = subscription.getCurrentPhase();
    testListener.pushExpectedEvent(NextEvent.PHASE);
    final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31));
    clock.addDeltaFromReality(it.toDurationMillis());
    assertListenerStatus();
    // SET CTD TO CANCEL IN FUTURE
    final DateTime expectedPhaseTrialChange = TestSubscriptionHelper.addDuration(subscription.getStartDate(), trialPhase.getDuration());
    final Duration ctd = testUtil.getDurationMonth(1);
    final DateTime newChargedThroughDate = TestSubscriptionHelper.addDuration(expectedPhaseTrialChange, ctd);
    subscriptionInternalApi.setChargedThroughDate(subscription.getId(), newChargedThroughDate, internalCallContext);
    subscription = subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
    subscription.cancelWithPolicy(BillingActionPolicy.END_OF_TERM, null, -1, callContext);
    try {
        subscription.changePlanWithDate(new PlanSpecifier("Pistol", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME), null, clock.getUTCNow(), callContext);
    } catch (final SubscriptionBaseApiException e) {
        assertEquals(e.getCode(), ErrorCode.SUB_CHANGE_FUTURE_CANCELLED.getCode());
    }
    assertListenerStatus();
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) Duration(org.killbill.billing.catalog.api.Duration) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 29 with PlanSpecifier

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

the class TestIntegrationWithCatalogUpdate method testBasic.

@Test(groups = "slow")
public void testBasic() throws Exception {
    // Create a per-tenant catalog with one plan
    final SimplePlanDescriptor desc1 = new DefaultSimplePlanDescriptor("foo-monthly", "Foo", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of());
    catalogUserApi.addSimplePlan(desc1, init, testCallContext);
    StaticCatalog catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext);
    assertEquals(catalog.getCurrentPlans().size(), 1);
    final Entitlement baseEntitlement = createEntitlement("foo-monthly", true);
    invoiceChecker.checkInvoice(account.getId(), 1, testCallContext, new ExpectedInvoiceItemCheck(new LocalDate(2016, 6, 1), new LocalDate(2016, 7, 1), InvoiceItemType.RECURRING, BigDecimal.TEN));
    // Add another Plan in the catalog
    final SimplePlanDescriptor desc2 = new DefaultSimplePlanDescriptor("superfoo-monthly", "SuperFoo", ProductCategory.BASE, account.getCurrency(), new BigDecimal("20.00"), BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of());
    catalogUserApi.addSimplePlan(desc2, init, testCallContext);
    catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext);
    assertEquals(catalog.getCurrentPlans().size(), 2);
    // Change Plan to the newly added Plan and verify correct default rules behavior (IMMEDIATE change)
    busHandler.pushExpectedEvents(NextEvent.CHANGE, NextEvent.INVOICE, NextEvent.INVOICE_PAYMENT, NextEvent.PAYMENT);
    baseEntitlement.changePlan(new PlanSpecifier("SuperFoo", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME), null, ImmutableList.<PluginProperty>of(), testCallContext);
    assertListenerStatus();
    invoiceChecker.checkInvoice(account.getId(), 2, testCallContext, new ExpectedInvoiceItemCheck(new LocalDate(2016, 6, 1), new LocalDate(2016, 7, 1), InvoiceItemType.RECURRING, new BigDecimal("20.00")), new ExpectedInvoiceItemCheck(new LocalDate(2016, 6, 1), new LocalDate(2016, 7, 1), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-10.00")));
    assertListenerStatus();
}
Also used : Entitlement(org.killbill.billing.entitlement.api.Entitlement) StaticCatalog(org.killbill.billing.catalog.api.StaticCatalog) ExpectedInvoiceItemCheck(org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck) LocalDate(org.joda.time.LocalDate) SimplePlanDescriptor(org.killbill.billing.catalog.api.SimplePlanDescriptor) DefaultSimplePlanDescriptor(org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor) DefaultSimplePlanDescriptor(org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor) BigDecimal(java.math.BigDecimal) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 30 with PlanSpecifier

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

the class TestIntegrationParentInvoice method testParentInvoiceGenerationMultipleActionsSameDay.

@Test(groups = "slow")
public void testParentInvoiceGenerationMultipleActionsSameDay() throws Exception {
    final int billingDay = 14;
    final DateTime initialCreationDate = new DateTime(2015, 5, 15, 0, 0, 0, 0, testTimeZone);
    // set clock to the initial start date
    clock.setTime(initialCreationDate);
    final Account parentAccount = createAccountWithNonOsgiPaymentMethod(getAccountData(billingDay));
    final Account childAccount = createAccountWithNonOsgiPaymentMethod(getChildAccountData(billingDay, parentAccount.getId(), true));
    // CREATE SUBSCRIPTION AND EXPECT BOTH EVENTS: NextEvent.CREATE NextEvent.INVOICE
    DefaultEntitlement baseEntitlementChild = createBaseEntitlementAndCheckForCompletion(childAccount.getId(), "bundleKey1", "Pistol", ProductCategory.BASE, BillingPeriod.MONTHLY, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
    // Moving a day the NotificationQ calls the commitInvoice. No payment is expected.
    busHandler.pushExpectedEvents(NextEvent.INVOICE);
    clock.addDays(1);
    assertListenerStatus();
    // Move through time and verify new parent Invoice. No payments are expected yet.
    busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE);
    clock.addDays(29);
    assertListenerStatus();
    // check parent Invoice with child plan amount
    List<Invoice> parentInvoices = invoiceUserApi.getInvoicesByAccount(parentAccount.getId(), false, callContext);
    assertEquals(parentInvoices.size(), 2);
    Invoice parentInvoice = parentInvoices.get(1);
    assertEquals(parentInvoice.getNumberOfItems(), 1);
    assertEquals(parentInvoice.getStatus(), InvoiceStatus.DRAFT);
    assertTrue(parentInvoice.isParentInvoice());
    // balance is 0 because parent invoice status is DRAFT
    assertEquals(parentInvoice.getBalance().compareTo(BigDecimal.ZERO), 0);
    assertEquals(parentInvoice.getInvoiceItems().get(0).getAmount().compareTo(BigDecimal.valueOf(29.95)), 0);
    // upgrade plan
    busHandler.pushExpectedEvents(NextEvent.CHANGE, NextEvent.INVOICE);
    baseEntitlementChild.changePlanOverrideBillingPolicy(new PlanSpecifier("Shotgun", BillingPeriod.MONTHLY, baseEntitlementChild.getLastActivePriceList().getName()), null, clock.getToday(childAccount.getTimeZone()), BillingActionPolicy.IMMEDIATE, null, callContext);
    assertListenerStatus();
    // check parent invoice. Expected to have the same invoice item with the amount updated
    final List<Invoice> childInvoices = invoiceUserApi.getInvoicesByAccount(childAccount.getId(), false, callContext);
    parentInvoices = invoiceUserApi.getInvoicesByAccount(parentAccount.getId(), false, callContext);
    assertEquals(parentInvoices.size(), 2);
    parentInvoice = parentInvoices.get(1);
    assertEquals(parentInvoice.getNumberOfItems(), 1);
    assertEquals(parentInvoice.getStatus(), InvoiceStatus.DRAFT);
    assertTrue(parentInvoice.isParentInvoice());
    // balance is 0 because parent invoice status is DRAFT
    assertEquals(parentInvoice.getBalance().compareTo(BigDecimal.ZERO), 0);
    // Moving a day the NotificationQ calls the commitInvoice. Now payment is expected
    busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    clock.addDays(1);
    assertListenerStatus();
    parentInvoice = invoiceUserApi.getInvoice(parentInvoice.getId(), callContext);
    assertEquals(parentInvoice.getStatus(), InvoiceStatus.COMMITTED);
    assertEquals(parentInvoice.getBalance().compareTo(BigDecimal.ZERO), 0);
}
Also used : DefaultAccount(org.killbill.billing.account.api.DefaultAccount) Account(org.killbill.billing.account.api.Account) Invoice(org.killbill.billing.invoice.api.Invoice) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) DateTime(org.joda.time.DateTime) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Aggregations

PlanSpecifier (org.killbill.billing.catalog.api.PlanSpecifier)39 Test (org.testng.annotations.Test)28 DateTime (org.joda.time.DateTime)16 Interval (org.joda.time.Interval)11 LocalDate (org.joda.time.LocalDate)9 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)8 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)8 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)7 Duration (org.killbill.billing.catalog.api.Duration)7 Account (org.killbill.billing.account.api.Account)6 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)6 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)6 DefaultPriceList (org.killbill.billing.catalog.DefaultPriceList)5 Plan (org.killbill.billing.catalog.api.Plan)5 ArrayList (java.util.ArrayList)4 DefaultProduct (org.killbill.billing.catalog.DefaultProduct)4 PlanAlignmentCreate (org.killbill.billing.catalog.api.PlanAlignmentCreate)4 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)4 BigDecimal (java.math.BigDecimal)3 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)3