Search in sources :

Example 6 with EntitlementApiException

use of org.killbill.billing.entitlement.api.EntitlementApiException in project killbill by killbill.

the class TestSubscription method testCreateBaseSubscriptionAndAddOnsWithLimitException.

@Test(groups = "slow")
public void testCreateBaseSubscriptionAndAddOnsWithLimitException() throws Exception {
    final LocalDate initialDate = new LocalDate(2015, 10, 1);
    clock.setDay(initialDate);
    final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(1));
    final PlanPhaseSpecifier addOnSpec1 = new PlanPhaseSpecifier("Laser-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
    final PlanPhaseSpecifier addOnSpec2 = new PlanPhaseSpecifier("Laser-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
    final PlanPhaseSpecifier addOnSpec3 = new PlanPhaseSpecifier("Laser-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
    // Create base subscription
    final Entitlement baseEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), account.getExternalKey(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
    assertNotNull(baseEntitlement);
    // Create first add_on subscription
    busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    entitlementApi.addEntitlement(baseEntitlement.getBundleId(), addOnSpec1, null, initialDate, initialDate, false, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    // Create second add_on subscription with the same plan
    busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    entitlementApi.addEntitlement(baseEntitlement.getBundleId(), addOnSpec2, null, initialDate, initialDate, false, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    // Trying to add the third add_on with the same plan should throw an exception (the limit is 2 for this plan)
    try {
        entitlementApi.addEntitlement(baseEntitlement.getBundleId(), addOnSpec3, null, initialDate, initialDate, false, ImmutableList.<PluginProperty>of(), callContext);
    } catch (final EntitlementApiException e) {
        assertEquals(e.getCode(), ErrorCode.SUB_CREATE_AO_MAX_PLAN_ALLOWED_BY_BUNDLE.getCode());
    }
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Account(org.killbill.billing.account.api.Account) EntitlementApiException(org.killbill.billing.entitlement.api.EntitlementApiException) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) Entitlement(org.killbill.billing.entitlement.api.Entitlement) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 7 with EntitlementApiException

use of org.killbill.billing.entitlement.api.EntitlementApiException in project killbill by killbill.

the class TestSubscription method testChangePlanWithLimitException.

@Test(groups = "slow")
public void testChangePlanWithLimitException() throws Exception {
    final LocalDate initialDate = new LocalDate(2015, 10, 1);
    clock.setDay(initialDate);
    final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(1));
    final PlanPhaseSpecifier addOnSpec1 = new PlanPhaseSpecifier("Laser-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
    final PlanPhaseSpecifier addOnSpec2 = new PlanPhaseSpecifier("Laser-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
    final PlanPhaseSpecifier addOnSpec3 = new PlanPhaseSpecifier("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
    // Create base subscription
    final Entitlement baseEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), account.getExternalKey(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
    assertNotNull(baseEntitlement);
    // Create first add_on subscription
    busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    entitlementApi.addEntitlement(baseEntitlement.getBundleId(), addOnSpec1, null, initialDate, initialDate, false, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    // Create second add_on subscription with the same plan
    busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    entitlementApi.addEntitlement(baseEntitlement.getBundleId(), addOnSpec2, null, initialDate, initialDate, false, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    // Create third add_on subscription with another plan
    busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    Entitlement addOn3 = entitlementApi.addEntitlement(baseEntitlement.getBundleId(), addOnSpec3, null, initialDate, initialDate, false, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    // Trying to change the plan of the third add_on to 'Laser-Scope' plan, should throw an exception (the limit is 2 for this plan)
    try {
        final PlanPhaseSpecifier addOnSpecChangedPlan = new PlanPhaseSpecifier("Laser-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
        addOn3.changePlan(addOnSpecChangedPlan, null, ImmutableList.<PluginProperty>of(), callContext);
    } catch (final EntitlementApiException e) {
        assertEquals(e.getCode(), ErrorCode.SUB_CHANGE_AO_MAX_PLAN_ALLOWED_BY_BUNDLE.getCode());
    }
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Account(org.killbill.billing.account.api.Account) EntitlementApiException(org.killbill.billing.entitlement.api.EntitlementApiException) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) Entitlement(org.killbill.billing.entitlement.api.Entitlement) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 8 with EntitlementApiException

use of org.killbill.billing.entitlement.api.EntitlementApiException in project killbill by killbill.

the class TestSubscription method testCancelFutureSubscriptionWithRequestedDate.

@Test(groups = "slow")
public void testCancelFutureSubscriptionWithRequestedDate() throws Exception {
    final LocalDate initialDate = new LocalDate(2015, 9, 1);
    clock.setDay(initialDate);
    final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(1));
    final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME, null);
    final LocalDate futureDate = new LocalDate(2015, 10, 1);
    // No CREATE event as this is set in the future
    final Entitlement createdEntitlement = entitlementApi.createBaseEntitlement(account.getId(), spec, account.getExternalKey(), null, futureDate, futureDate, false, ImmutableList.<PluginProperty>of(), callContext);
    assertEquals(createdEntitlement.getState(), EntitlementState.PENDING);
    assertEquals(createdEntitlement.getEffectiveStartDate().compareTo(futureDate), 0);
    assertEquals(createdEntitlement.getEffectiveEndDate(), null);
    assertListenerStatus();
    final LocalDate invalidCancelDate = initialDate.plusDays(1);
    try {
        createdEntitlement.cancelEntitlementWithDate(invalidCancelDate, true, null, callContext);
        Assert.fail("Should not succeed to cancel subscription prior startDate");
    } catch (final EntitlementApiException e) {
        assertEquals(e.getCode(), ErrorCode.SUB_INVALID_REQUESTED_DATE.getCode());
    }
    final Entitlement cancelledEntitlement = createdEntitlement.cancelEntitlementWithDate(futureDate, true, null, callContext);
    assertEquals(cancelledEntitlement.getEffectiveEndDate().compareTo(futureDate), 0);
    assertListenerStatus();
    // Move off trial and reach start/cancellation date
    busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.BLOCK, NextEvent.CANCEL, NextEvent.NULL_INVOICE, NextEvent.NULL_INVOICE);
    clock.addDays(30);
    assertListenerStatus();
    // Just to make sure we really don't invoice for anything move to next month
    clock.addMonths(1);
    assertListenerStatus();
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Account(org.killbill.billing.account.api.Account) EntitlementApiException(org.killbill.billing.entitlement.api.EntitlementApiException) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) Entitlement(org.killbill.billing.entitlement.api.Entitlement) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 9 with EntitlementApiException

use of org.killbill.billing.entitlement.api.EntitlementApiException in project killbill by killbill.

the class TestIntegrationWithCatalogUpdate method testError_CAT_MULTIPLE_MATCHING_PLANS_FOR_PRICELIST.

@Test(groups = "slow")
public void testError_CAT_MULTIPLE_MATCHING_PLANS_FOR_PRICELIST() throws Exception {
    // Create a per-tenant catalog with one plan
    final SimplePlanDescriptor desc1 = new DefaultSimplePlanDescriptor("zoe-monthly", "Zoe", 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 SimplePlanDescriptor desc2 = new DefaultSimplePlanDescriptor("zoe-14-monthly", "Zoe", ProductCategory.BASE, account.getCurrency(), BigDecimal.TEN, BillingPeriod.MONTHLY, 14, TimeUnit.DAYS, ImmutableList.<String>of());
    catalogUserApi.addSimplePlan(desc2, init, testCallContext);
    catalog = catalogUserApi.getCurrentCatalog("dummy", testCallContext);
    assertEquals(catalog.getCurrentPlans().size(), 2);
    try {
        final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Zoe", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
        entitlementApi.createBaseEntitlement(account.getId(), spec, UUID.randomUUID().toString(), null, null, null, false, ImmutableList.<PluginProperty>of(), testCallContext);
        fail("Creating entitlement should fail");
    } catch (final EntitlementApiException e) {
        assertEquals(e.getCode(), ErrorCode.CAT_MULTIPLE_MATCHING_PLANS_FOR_PRICELIST.getCode());
    }
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) EntitlementApiException(org.killbill.billing.entitlement.api.EntitlementApiException) StaticCatalog(org.killbill.billing.catalog.api.StaticCatalog) SimplePlanDescriptor(org.killbill.billing.catalog.api.SimplePlanDescriptor) DefaultSimplePlanDescriptor(org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor) DefaultSimplePlanDescriptor(org.killbill.billing.catalog.api.user.DefaultSimplePlanDescriptor) Test(org.testng.annotations.Test)

Example 10 with EntitlementApiException

use of org.killbill.billing.entitlement.api.EntitlementApiException in project killbill by killbill.

the class InvoiceChecker method checkChargedThroughDate.

public void checkChargedThroughDate(final UUID entitlementId, final LocalDate expectedLocalCTD, final CallContext context) {
    try {
        final DefaultEntitlement entitlement = (DefaultEntitlement) entitlementApi.getEntitlementForId(entitlementId, context);
        final SubscriptionBase subscription = entitlement.getSubscriptionBase();
        if (expectedLocalCTD == null) {
            assertNull(subscription.getChargedThroughDate());
        } else {
            final String msg = String.format("Checking CTD for entitlement %s : expectedLocalCTD = %s, got %s", entitlementId, expectedLocalCTD, subscription.getChargedThroughDate().toLocalDate());
            assertTrue(expectedLocalCTD.compareTo(subscription.getChargedThroughDate().toLocalDate()) == 0, msg);
        }
    } catch (final EntitlementApiException e) {
        fail("Failed to retrieve entitlement for " + entitlementId);
    }
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) EntitlementApiException(org.killbill.billing.entitlement.api.EntitlementApiException)

Aggregations

EntitlementApiException (org.killbill.billing.entitlement.api.EntitlementApiException)19 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)12 Entitlement (org.killbill.billing.entitlement.api.Entitlement)10 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)9 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)7 Test (org.testng.annotations.Test)7 LocalDate (org.joda.time.LocalDate)6 Account (org.killbill.billing.account.api.Account)6 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)4 Function (com.google.common.base.Function)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 UUID (java.util.UUID)3 Nullable (javax.annotation.Nullable)3 AccountApiException (org.killbill.billing.account.api.AccountApiException)3 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)3 BaseEntitlementWithAddOnsSpecifier (org.killbill.billing.entitlement.api.BaseEntitlementWithAddOnsSpecifier)3 BlockingState (org.killbill.billing.entitlement.api.BlockingState)3 DefaultBaseEntitlementWithAddOnsSpecifier (org.killbill.billing.entitlement.api.DefaultBaseEntitlementWithAddOnsSpecifier)3