Search in sources :

Example 16 with EntitlementApiException

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

the class TestIntegrationBase method createBaseEntitlementWithPriceOverrideAndCheckForCompletion.

protected DefaultEntitlement createBaseEntitlementWithPriceOverrideAndCheckForCompletion(final UUID accountId, final String bundleExternalKey, final String productName, final ProductCategory productCategory, final BillingPeriod billingPeriod, final List<PlanPhasePriceOverride> overrides, final NextEvent... events) {
    if (productCategory == ProductCategory.ADD_ON) {
        throw new RuntimeException("Unxepected Call for creating ADD_ON");
    }
    return (DefaultEntitlement) doCallAndCheckForCompletion(new Function<Void, Entitlement>() {

        @Override
        public Entitlement apply(@Nullable final Void dontcare) {
            try {
                final PlanPhaseSpecifier spec = new PlanPhaseSpecifier(productName, billingPeriod, PriceListSet.DEFAULT_PRICELIST_NAME, null);
                final Entitlement entitlement = entitlementApi.createBaseEntitlement(accountId, spec, bundleExternalKey, overrides, null, null, false, ImmutableList.<PluginProperty>of(), callContext);
                assertNotNull(entitlement);
                return entitlement;
            } catch (final EntitlementApiException e) {
                fail("Unable to create entitlement", e);
                return null;
            }
        }
    }, events);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Function(com.google.common.base.Function) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) EntitlementApiException(org.killbill.billing.entitlement.api.EntitlementApiException) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) Entitlement(org.killbill.billing.entitlement.api.Entitlement) Nullable(javax.annotation.Nullable)

Example 17 with EntitlementApiException

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

the class TestIntegrationBase method addAOEntitlementAndCheckForCompletion.

protected DefaultEntitlement addAOEntitlementAndCheckForCompletion(final UUID bundleId, final String productName, final ProductCategory productCategory, final BillingPeriod billingPeriod, final NextEvent... events) {
    if (productCategory != ProductCategory.ADD_ON) {
        throw new RuntimeException("Unexpected Call for creating a productCategory " + productCategory);
    }
    return (DefaultEntitlement) doCallAndCheckForCompletion(new Function<Void, Entitlement>() {

        @Override
        public Entitlement apply(@Nullable final Void dontcare) {
            try {
                final PlanPhaseSpecifier spec = new PlanPhaseSpecifier(productName, billingPeriod, PriceListSet.DEFAULT_PRICELIST_NAME, null);
                final Entitlement entitlement = entitlementApi.addEntitlement(bundleId, spec, null, null, null, false, ImmutableList.<PluginProperty>of(), callContext);
                assertNotNull(entitlement);
                return entitlement;
            } catch (final EntitlementApiException e) {
                fail(e.getMessage());
                return null;
            }
        }
    }, events);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Function(com.google.common.base.Function) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) EntitlementApiException(org.killbill.billing.entitlement.api.EntitlementApiException) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) Entitlement(org.killbill.billing.entitlement.api.Entitlement) Nullable(javax.annotation.Nullable)

Example 18 with EntitlementApiException

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

the class TestCatalogRetireElements method testRetireProduct.

@Test(groups = "slow")
public void testRetireProduct() throws Exception {
    // Catalog v1 starts in 2011-01-01
    // Catalog v3 starts in 2016-01-01
    final LocalDate today = new LocalDate(2015, 11, 5);
    // Set clock to the initial start date - we implicitly assume here that the account timezone is UTC
    clock.setDay(today);
    final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(1));
    //accountUserApi.createAccount(getAccountData(1), callContext);
    final String productName = "Pistol";
    final BillingPeriod term = BillingPeriod.MONTHLY;
    final DefaultEntitlement bpEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "externalKey", productName, ProductCategory.BASE, term, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
    assertNotNull(bpEntitlement);
    assertEquals(invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext).size(), 1);
    assertEquals(bpEntitlement.getSubscriptionBase().getCurrentPlan().getRecurringBillingPeriod(), BillingPeriod.MONTHLY);
    // Move out a month.
    busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    clock.addMonths(1);
    assertListenerStatus();
    // Move out a month.
    busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    clock.addMonths(1);
    assertListenerStatus();
    // Catalog v3 should start now.
    final PlanPhaseSpecifier spec = new PlanPhaseSpecifier(productName, term, PriceListSet.DEFAULT_PRICELIST_NAME, null);
    try {
        entitlementApi.createBaseEntitlement(account.getId(), spec, "externalKey2", null, null, null, false, ImmutableList.<PluginProperty>of(), callContext);
        // force to fail is there is not an exception
        fail();
    } catch (final EntitlementApiException e) {
        assertTrue(e.getLocalizedMessage().startsWith("Could not find any product named 'Pistol'"));
    }
    // Move out a month and verify 'Pistol' plan continue working as expected.
    busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    clock.addMonths(1);
    assertListenerStatus();
    final List<Invoice> invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext);
    assertEquals(invoices.size(), 4);
    for (final Invoice invoice : invoices) {
        assertEquals(invoice.getInvoiceItems().get(0).getPlanName(), "pistol-monthly");
    }
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Account(org.killbill.billing.account.api.Account) Invoice(org.killbill.billing.invoice.api.Invoice) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) EntitlementApiException(org.killbill.billing.entitlement.api.EntitlementApiException) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

Example 19 with EntitlementApiException

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

the class TestCatalogRetireElements method testRetirePlan.

@Test(groups = "slow")
public void testRetirePlan() throws Exception {
    // Catalog v1 starts in 2011-01-01
    // Catalog v2 starts in 2015-12-01
    final LocalDate today = new LocalDate(2015, 11, 5);
    // Set clock to the initial start date - we implicitly assume here that the account timezone is UTC
    clock.setDay(today);
    final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(1));
    //accountUserApi.createAccount(getAccountData(1), callContext);
    final String productName = "Pistol";
    final BillingPeriod term = BillingPeriod.MONTHLY;
    final DefaultEntitlement bpEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "externalKey", productName, ProductCategory.BASE, term, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
    assertNotNull(bpEntitlement);
    assertEquals(invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext).size(), 1);
    assertEquals(bpEntitlement.getSubscriptionBase().getCurrentPlan().getRecurringBillingPeriod(), BillingPeriod.MONTHLY);
    // Move out a month.
    busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    clock.addMonths(1);
    assertListenerStatus();
    // Catalog v2 should start now.
    final PlanPhaseSpecifier spec = new PlanPhaseSpecifier(productName, term, PriceListSet.DEFAULT_PRICELIST_NAME, null);
    try {
        entitlementApi.createBaseEntitlement(account.getId(), spec, "externalKey2", null, null, null, false, ImmutableList.<PluginProperty>of(), callContext);
        // force to fail is there is not an exception
        fail();
    } catch (final EntitlementApiException e) {
        assertEquals(e.getCode(), ErrorCode.CAT_PLAN_NOT_FOUND.getCode());
    }
    // Move out a month and verify 'Pistol' plan continue working as expected.
    busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    clock.addMonths(1);
    assertListenerStatus();
    final List<Invoice> invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext);
    assertEquals(invoices.size(), 3);
    for (final Invoice invoice : invoices) {
        assertEquals(invoice.getInvoiceItems().get(0).getPlanName(), "pistol-monthly");
    }
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) Account(org.killbill.billing.account.api.Account) Invoice(org.killbill.billing.invoice.api.Invoice) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) EntitlementApiException(org.killbill.billing.entitlement.api.EntitlementApiException) LocalDate(org.joda.time.LocalDate) Test(org.testng.annotations.Test)

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