Search in sources :

Example 11 with ImmutableAccountData

use of org.killbill.billing.account.api.ImmutableAccountData in project killbill by killbill.

the class EventsStreamBuilder method buildForEntitlement.

public EventsStream buildForEntitlement(final UUID entitlementId, final InternalTenantContext internalTenantContext) throws EntitlementApiException {
    final SubscriptionBaseBundle bundle;
    final SubscriptionBase subscription;
    final List<SubscriptionBase> allSubscriptionsForBundle;
    final SubscriptionBase baseSubscription;
    try {
        subscription = subscriptionInternalApi.getSubscriptionFromId(entitlementId, internalTenantContext);
        bundle = subscriptionInternalApi.getBundleFromId(subscription.getBundleId(), internalTenantContext);
        allSubscriptionsForBundle = subscriptionInternalApi.getSubscriptionsForBundle(subscription.getBundleId(), null, internalTenantContext);
        baseSubscription = findBaseSubscription(allSubscriptionsForBundle);
    } catch (SubscriptionBaseApiException e) {
        throw new EntitlementApiException(e);
    }
    final ImmutableAccountData account;
    try {
        account = accountInternalApi.getImmutableAccountDataById(bundle.getAccountId(), internalTenantContext);
    } catch (AccountApiException e) {
        throw new EntitlementApiException(e);
    }
    // Retrieve the blocking states
    final List<BlockingState> blockingStatesForAccount = defaultBlockingStateDao.getBlockingAllForAccountRecordId(internalTenantContext);
    final Map<UUID, Integer> bcdCache = new HashMap<UUID, Integer>();
    return buildForEntitlement(blockingStatesForAccount, account, bundle, baseSubscription, subscription, allSubscriptionsForBundle, bcdCache, internalTenantContext);
}
Also used : ImmutableAccountData(org.killbill.billing.account.api.ImmutableAccountData) HashMap(java.util.HashMap) EntitlementApiException(org.killbill.billing.entitlement.api.EntitlementApiException) BlockingState(org.killbill.billing.entitlement.api.BlockingState) SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) AccountApiException(org.killbill.billing.account.api.AccountApiException) SubscriptionBaseBundle(org.killbill.billing.subscription.api.user.SubscriptionBaseBundle) UUID(java.util.UUID) SubscriptionBaseApiException(org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)

Example 12 with ImmutableAccountData

use of org.killbill.billing.account.api.ImmutableAccountData in project killbill by killbill.

the class MockAccountModule method installInternalApi.

@Override
public void installInternalApi() {
    final ImmutableAccountData immutableAccountData = Mockito.mock(ImmutableAccountData.class);
    Mockito.when(immutableAccountData.getTimeZone()).thenReturn(DateTimeZone.UTC);
    Mockito.when(immutableAccountData.getFixedOffsetTimeZone()).thenReturn(DateTimeZone.UTC);
    final AccountInternalApi accountInternalApi = Mockito.mock(AccountInternalApi.class);
    final ImmutableAccountInternalApi immutableAccountInternalApi = Mockito.mock(ImmutableAccountInternalApi.class);
    bind(AccountInternalApi.class).toInstance(accountInternalApi);
    bind(ImmutableAccountInternalApi.class).toInstance(immutableAccountInternalApi);
}
Also used : ImmutableAccountInternalApi(org.killbill.billing.account.api.ImmutableAccountInternalApi) ImmutableAccountData(org.killbill.billing.account.api.ImmutableAccountData) ImmutableAccountInternalApi(org.killbill.billing.account.api.ImmutableAccountInternalApi) AccountInternalApi(org.killbill.billing.account.api.AccountInternalApi)

Example 13 with ImmutableAccountData

use of org.killbill.billing.account.api.ImmutableAccountData in project killbill by killbill.

the class TestBillCycleDayCalculator method verifyBCDCalculation.

private void verifyBCDCalculation(final DateTimeZone accountTimeZone, final DateTime startDateUTC, final int bcdLocal) throws AccountApiException, CatalogApiException {
    final SubscriptionBase subscription = Mockito.mock(SubscriptionBase.class);
    Mockito.when(subscription.getStartDate()).thenReturn(startDateUTC);
    Mockito.when(subscription.getDateOfFirstRecurringNonZeroCharge()).thenReturn(startDateUTC);
    final ImmutableAccountData account = Mockito.mock(ImmutableAccountData.class);
    Mockito.when(account.getTimeZone()).thenReturn(accountTimeZone);
    final Integer bcd = BillCycleDayCalculator.calculateBcdForAlignment(new HashMap<UUID, Integer>(), subscription, subscription, BillingAlignment.SUBSCRIPTION, account.getTimeZone(), 0);
    Assert.assertEquals(bcd, (Integer) bcdLocal);
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) ImmutableAccountData(org.killbill.billing.account.api.ImmutableAccountData) UUID(java.util.UUID)

Example 14 with ImmutableAccountData

use of org.killbill.billing.account.api.ImmutableAccountData in project killbill by killbill.

the class TestBillCycleDayCalculator method testCalculateBCDForAOWithBPCancelledBundleAligned.

@Test(groups = "fast")
public void testCalculateBCDForAOWithBPCancelledBundleAligned() throws Exception {
    final DateTimeZone accountTimeZone = DateTimeZone.UTC;
    final DateTime bpStartDateUTC = new DateTime(2012, 7, 16, 21, 0, 0, DateTimeZone.UTC);
    final int expectedBCDUTC = 16;
    // Create a Bundle associated with a subscription
    final SubscriptionBaseBundle bundle = Mockito.mock(SubscriptionBaseBundle.class);
    final SubscriptionBase subscription = Mockito.mock(SubscriptionBase.class);
    Mockito.when(subscription.getStartDate()).thenReturn(bpStartDateUTC);
    // Create a the base plan associated with that subscription
    final Plan plan = Mockito.mock(Plan.class);
    final Catalog catalog = Mockito.mock(Catalog.class);
    Mockito.when(catalog.findPlan(Mockito.anyString(), Mockito.<DateTime>any(), Mockito.<DateTime>any())).thenReturn(plan);
    Mockito.when(subscription.getLastActivePlan()).thenReturn(plan);
    Mockito.when(subscription.getDateOfFirstRecurringNonZeroCharge()).thenReturn(bpStartDateUTC);
    final ImmutableAccountData account = Mockito.mock(ImmutableAccountData.class);
    Mockito.when(account.getTimeZone()).thenReturn(accountTimeZone);
    final Integer billCycleDayLocal = BillCycleDayCalculator.calculateBcdForAlignment(new HashMap<UUID, Integer>(), subscription, subscription, BillingAlignment.BUNDLE, account.getTimeZone(), 0);
    Assert.assertEquals(billCycleDayLocal, (Integer) expectedBCDUTC);
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) ImmutableAccountData(org.killbill.billing.account.api.ImmutableAccountData) SubscriptionBaseBundle(org.killbill.billing.subscription.api.user.SubscriptionBaseBundle) Plan(org.killbill.billing.catalog.api.Plan) UUID(java.util.UUID) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) Catalog(org.killbill.billing.catalog.api.Catalog) Test(org.testng.annotations.Test)

Aggregations

ImmutableAccountData (org.killbill.billing.account.api.ImmutableAccountData)14 UUID (java.util.UUID)7 AccountApiException (org.killbill.billing.account.api.AccountApiException)7 SubscriptionBaseBundle (org.killbill.billing.subscription.api.user.SubscriptionBaseBundle)6 ArrayList (java.util.ArrayList)4 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)4 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)4 LocalDate (org.joda.time.LocalDate)3 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)3 HashMap (java.util.HashMap)2 DateTime (org.joda.time.DateTime)2 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)2 BlockingState (org.killbill.billing.entitlement.api.BlockingState)2 EntitlementApiException (org.killbill.billing.entitlement.api.EntitlementApiException)2 WithEntitlementPlugin (org.killbill.billing.entitlement.api.EntitlementPluginExecution.WithEntitlementPlugin)2 EntitlementContext (org.killbill.billing.entitlement.plugin.api.EntitlementContext)2 Invoice (org.killbill.billing.invoice.api.Invoice)2 DefaultBlockingState (org.killbill.billing.junction.DefaultBlockingState)2 Test (org.testng.annotations.Test)2 Predicate (com.google.common.base.Predicate)1