public OverdueWrapper createOverdueWrapperFor(final UUID id, final InternalTenantContext context) throws OverdueException { try { final Account account = accountApi.getAccountById(id, context); return new OverdueWrapper(account, api, getOverdueStateSet(context), locker, clock, billingStateCalculator, overdueStateApplicator, internalCallContextFactory); } catch (final AccountApiException e) { throw new OverdueException(e); } }
@Override public boolean cancelWithPolicyNoValidationAndCatalog(final Iterable<DefaultSubscriptionBase> subscriptions, final BillingActionPolicy policy, final Catalog catalog, final InternalCallContext context) throws SubscriptionBaseApiException { final Map<DefaultSubscriptionBase, DateTime> subscriptionsWithEffectiveDate = new HashMap<DefaultSubscriptionBase, DateTime>(); try { for (final DefaultSubscriptionBase subscription : subscriptions) { final BillingAlignment billingAlignment = (subscription.getState() == EntitlementState.PENDING ? null : catalog.billingAlignment(new PlanPhaseSpecifier(subscription.getLastActivePlan().getName(), subscription.getLastActivePhase().getPhaseType()), clock.getUTCNow(), subscription.getStartDate())); final Integer accountBillCycleDayLocal = accountInternalApi.getBCD(context); final DateTime effectiveDate = subscription.getPlanChangeEffectiveDate(policy, billingAlignment, accountBillCycleDayLocal, context); subscriptionsWithEffectiveDate.put(subscription, effectiveDate); } return doCancelPlan(subscriptionsWithEffectiveDate, catalog, context); } catch (final CatalogApiException e) { throw new SubscriptionBaseApiException(e); } catch (final AccountApiException e) { throw new SubscriptionBaseApiException(e); } }
private boolean isAccountTaggedWith_OVERDUE_ENFORCEMENT_OFF(final InternalCallContext context) throws OverdueException { try { final UUID accountId = accountApi.getByRecordId(context.getAccountRecordId(), context); final List<Tag> accountTags = tagApi.getTags(accountId, ObjectType.ACCOUNT, context); for (final Tag cur : accountTags) { if (cur.getTagDefinitionId().equals(ControlTagType.OVERDUE_ENFORCEMENT_OFF.getId())) { return true; } } return false; } catch (final AccountApiException e) { throw new OverdueException(e); } } }
public static Account createMockAccount(final AccountData accountData, final AccountUserApi accountUserApi, final AccountInternalApi accountInternalApi, final ImmutableAccountInternalApi immutableAccountInternalApi, final NonEntityDao nonEntityDao, final Clock clock, final InternalCallContextFactory internalCallContextFactory, final MutableCallContext callContext, final MutableInternalCallContext internalCallContext) throws AccountApiException { final Account account = accountUserApi.createAccount(accountData, callContext); Mockito.when(accountInternalApi.getAccountById(Mockito.<UUID>eq(account.getId()), Mockito.<InternalTenantContext>any())).thenReturn(account); Mockito.when(accountInternalApi.getAccountByRecordId(Mockito.<Long>eq(internalCallContext.getAccountRecordId()), Mockito.<InternalTenantContext>any())).thenReturn(account); Mockito.when(accountInternalApi.getAccountByKey(Mockito.<String>eq(account.getExternalKey()), Mockito.<InternalTenantContext>any())).thenReturn(account); Mockito.when(immutableAccountInternalApi.getImmutableAccountDataByRecordId(Mockito.<Long>eq(internalCallContext.getAccountRecordId()), Mockito.<InternalTenantContext>any())).thenReturn(account); ((MockNonEntityDao) nonEntityDao).addTenantRecordIdMapping(account.getId(), internalCallContext); ((MockNonEntityDao) nonEntityDao).addAccountRecordIdMapping(account.getId(), internalCallContext); refreshCallContext(account.getId(), clock, internalCallContextFactory, callContext, internalCallContext); return account; } }
final Account account = accountApi.getAccountById(accountId, callContext); if (account.getParentAccountId() != null && account.isPaymentDelegatedToParent()) { final InternalTenantContext parentAccountInternalTenantContext = internalCallContextFactory.createInternalTenantContext(account.getParentAccountId(), callContext); final List<Account> childrenAccounts = accountApi.getChildrenAccounts(accountId, callContext); if (childrenAccounts != null) { for (final Account childAccount : childrenAccounts) {
private void processSubscriptionStartRequestedDateWithLock(final UUID accountId, final RequestedSubscriptionInternalEvent transition, final InternalCallContext context) { try { final BillingEventSet billingEvents = billingApi.getBillingEventsForAccountAndUpdateAccountBCD(accountId, null, context); if (billingEvents.isEmpty()) { return; } final FutureAccountNotificationsBuilder notificationsBuilder = new FutureAccountNotificationsBuilder(); populateNextFutureDryRunNotificationDate(billingEvents, notificationsBuilder, context); final ImmutableAccountData account = accountApi.getImmutableAccountDataById(accountId, context); commitInvoiceAndSetFutureNotifications(account, notificationsBuilder.build(), context); } catch (final SubscriptionBaseApiException e) { log.warn("Failed handling SubscriptionBase change.", new InvoiceApiException(ErrorCode.INVOICE_NO_ACCOUNT_ID_FOR_SUBSCRIPTION_ID, transition.getSubscriptionId().toString())); } catch (final AccountApiException e) { log.warn("Failed to retrieve BillingEvents for accountId='{}'", accountId, e); } catch (final CatalogApiException e) { log.warn("Failed to retrieve BillingEvents for accountId='{}'", accountId, e); } }
public static Account createMockAccount(final AccountData accountData, final AccountUserApi accountUserApi, final AccountInternalApi accountInternalApi, final ImmutableAccountInternalApi immutableAccountInternalApi, final NonEntityDao nonEntityDao, final Clock clock, final InternalCallContextFactory internalCallContextFactory, final MutableCallContext callContext, final MutableInternalCallContext internalCallContext) throws AccountApiException { final Account account = accountUserApi.createAccount(accountData, callContext); Mockito.when(accountInternalApi.getAccountById(Mockito.<UUID>eq(account.getId()), Mockito.<InternalTenantContext>any())).thenReturn(account); Mockito.when(accountInternalApi.getAccountByRecordId(Mockito.<Long>eq(internalCallContext.getAccountRecordId()), Mockito.<InternalTenantContext>any())).thenReturn(account); Mockito.when(accountInternalApi.getAccountByKey(Mockito.<String>eq(account.getExternalKey()), Mockito.<InternalTenantContext>any())).thenReturn(account); Mockito.when(immutableAccountInternalApi.getImmutableAccountDataByRecordId(Mockito.<Long>eq(internalCallContext.getAccountRecordId()), Mockito.<InternalTenantContext>any())).thenReturn(account); ((MockNonEntityDao) nonEntityDao).addTenantRecordIdMapping(account.getId(), internalCallContext); ((MockNonEntityDao) nonEntityDao).addAccountRecordIdMapping(account.getId(), internalCallContext); refreshCallContext(account.getId(), clock, internalCallContextFactory, callContext, internalCallContext); return account; } }
final Account account = accountApi.getAccountById(accountId, callContext); if (account.getParentAccountId() != null && account.isPaymentDelegatedToParent()) { final InternalTenantContext parentAccountInternalTenantContext = internalCallContextFactory.createInternalTenantContext(account.getParentAccountId(), callContext); final List<Account> childrenAccounts = accountApi.getChildrenAccounts(accountId, callContext); if (childrenAccounts != null) { for (final Account childAccount : childrenAccounts) {
final List<SubscriptionBaseBundle> bundles = subscriptionApi.getBundlesForAccount(accountId, context); final ImmutableAccountData account = accountApi.getImmutableAccountDataById(accountId, context); result = new DefaultBillingEventSet(false, found_INVOICING_DRAFT, found_INVOICING_REUSE_DRAFT); addBillingEventsForBundles(bundles, account, dryRunArguments, context, result, skippedSubscriptions, fullCatalog, tagsForAccount);
@Override @BeforeMethod(groups = "fast") public void beforeMethod() throws Exception { super.beforeMethod(); final Account account = Mockito.mock(Account.class); Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.UTC); Mockito.when(accountApi.getAccountById(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(account); }
ImmutableAccountData accountData; try { accountData = accountUserApi.getImmutableAccountDataById(accountId, internalTenantContext); } catch (AccountApiException e) { throw new InvoiceApiException(e);
private boolean isAccountTaggedWith_OVERDUE_ENFORCEMENT_OFF(final InternalCallContext context) throws OverdueException { try { final UUID accountId = accountApi.getByRecordId(context.getAccountRecordId(), context); final List<Tag> accountTags = tagApi.getTags(accountId, ObjectType.ACCOUNT, context); for (final Tag cur : accountTags) { if (cur.getTagDefinitionId().equals(ControlTagType.OVERDUE_ENFORCEMENT_OFF.getId())) { return true; } } return false; } catch (final AccountApiException e) { throw new OverdueException(e); } } }
private void addBillingEventsForBundles(final List<SubscriptionBaseBundle> bundles, final ImmutableAccountData account, final DryRunArguments dryRunArguments, final InternalCallContext context, final DefaultBillingEventSet result, final Set<UUID> skipSubscriptionsSet, final Catalog catalog, final List<Tag> tagsForAccount) throws AccountApiException, CatalogApiException, SubscriptionBaseApiException { final int currentAccountBCD = accountApi.getBCD(context); addBillingEventsForBundles(bundles, account, dryRunArguments, context, result, skipSubscriptionsSet, catalog, tagsForAccount, currentAccountBCD); }
public Account createAccount(final LocalDate dateOfLastUnPaidInvoice) throws SubscriptionBaseApiException, AccountApiException { final UUID accountId = UUID.randomUUID(); final Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(accountId); Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.UTC); Mockito.when(accountInternalApi.getAccountById(Mockito.eq(account.getId()), Mockito.<InternalTenantContext>any())).thenReturn(account); final Invoice invoice = Mockito.mock(Invoice.class); Mockito.when(invoice.getInvoiceDate()).thenReturn(dateOfLastUnPaidInvoice); Mockito.when(invoice.getBalance()).thenReturn(BigDecimal.TEN); Mockito.when(invoice.getStatus()).thenReturn(InvoiceStatus.COMMITTED); Mockito.when(invoice.getId()).thenReturn(UUID.randomUUID()); final InvoiceItem item = Mockito.mock(InvoiceItem.class); final List<InvoiceItem> items = new ArrayList<InvoiceItem>(); items.add(item); Mockito.when(invoice.getInvoiceItems()).thenReturn(items); final List<Invoice> invoices = new ArrayList<Invoice>(); invoices.add(invoice); Mockito.when(invoiceInternalApi.getUnpaidInvoicesByAccountId(Mockito.<UUID>any(), Mockito.<LocalDate>any(), Mockito.<InternalTenantContext>any())).thenReturn(invoices); final Tag tag = Mockito.mock(Tag.class); Mockito.when(tag.getObjectId()).thenReturn(accountId); Mockito.when(tag.getObjectType()).thenReturn(ObjectType.ACCOUNT); Mockito.when(tag.getTagDefinitionId()).thenReturn(ControlTagType.TEST.getId()); final List<Tag> tags = new ArrayList<Tag>(); tags.add(tag); Mockito.when(tagInternalApi.getTags(Mockito.eq(account.getId()), Mockito.eq(ObjectType.ACCOUNT), Mockito.<InternalTenantContext>any())) .thenReturn(tags); return account; }
account = accountApi.getImmutableAccountDataById(accountId, internalCallContext); } catch (final AccountApiException e) { log.error("Unable to generate invoice for accountId='{}', a future notification has NOT been recorded", accountId, e);
@Override public void run(final BlockingTransitionInternalEvent event) { // We are only interested in blockBilling or unblockBilling transitions. if (!event.isTransitionedToUnblockedBilling() && !event.isTransitionedToBlockedBilling()) { return; } try { final InternalCallContext context = internalCallContextFactory.createInternalCallContext(event.getSearchKey2(), event.getSearchKey1(), "SubscriptionBaseTransition", CallOrigin.INTERNAL, UserType.SYSTEM, event.getUserToken()); final UUID accountId = accountApi.getByRecordId(event.getSearchKey1(), context); dispatcher.processAccountFromNotificationOrBusEvent(accountId, null, null, false, context); } catch (final InvoiceApiException e) { log.warn("Unable to process event {}", event, e); } catch (final AccountApiException e) { log.warn("Unable to process event {}", event, e); } } });
@Override public boolean cancelWithPolicyNoValidationAndCatalog(final Iterable<DefaultSubscriptionBase> subscriptions, final BillingActionPolicy policy, final Catalog catalog, final InternalCallContext context) throws SubscriptionBaseApiException { final Map<DefaultSubscriptionBase, DateTime> subscriptionsWithEffectiveDate = new HashMap<DefaultSubscriptionBase, DateTime>(); try { for (final DefaultSubscriptionBase subscription : subscriptions) { final BillingAlignment billingAlignment = (subscription.getState() == EntitlementState.PENDING ? null : catalog.billingAlignment(new PlanPhaseSpecifier(subscription.getLastActivePlan().getName(), subscription.getLastActivePhase().getPhaseType()), clock.getUTCNow(), subscription.getStartDate())); final Integer accountBillCycleDayLocal = accountInternalApi.getBCD(context); final DateTime effectiveDate = subscription.getPlanChangeEffectiveDate(policy, billingAlignment, accountBillCycleDayLocal, context); subscriptionsWithEffectiveDate.put(subscription, effectiveDate); } return doCancelPlan(subscriptionsWithEffectiveDate, catalog, context); } catch (final CatalogApiException e) { throw new SubscriptionBaseApiException(e); } catch (final AccountApiException e) { throw new SubscriptionBaseApiException(e); } }
public OverdueWrapper createOverdueWrapperFor(final UUID id, final InternalTenantContext context) throws OverdueException { try { final Account account = accountApi.getAccountById(id, context); return new OverdueWrapper(account, api, getOverdueStateSet(context), locker, clock, billingStateCalculator, overdueStateApplicator, internalCallContextFactory); } catch (final AccountApiException e) { throw new OverdueException(e); } }
@Override public void run(final InvoiceCreationInternalEvent event) { try { final InternalCallContext context = internalCallContextFactory.createInternalCallContext(event.getSearchKey2(), event.getSearchKey1(), "CreateParentInvoice", CallOrigin.INTERNAL, UserType.SYSTEM, event.getUserToken()); final Account account = accountApi.getAccountById(event.getAccountId(), context); // catch children invoices and populate the parent summary invoice if (isChildrenAccountAndPaymentDelegated(account)) { dispatcher.processParentInvoiceForInvoiceGeneration(account, event.getInvoiceId(), context); } } catch (final InvoiceApiException e) { log.warn("Unable to process event {}", event, e); } catch (final AccountApiException e) { log.warn("Unable to process event {}", event, e); } } });
@Override public void run(final DefaultInvoiceAdjustmentEvent event) { try { final InternalCallContext context = internalCallContextFactory.createInternalCallContext(event.getSearchKey2(), event.getSearchKey1(), "AdjustParentInvoice", CallOrigin.INTERNAL, UserType.SYSTEM, event.getUserToken()); final Account account = accountApi.getAccountById(event.getAccountId(), context); // catch children invoices and populate the parent summary invoice if (isChildrenAccountAndPaymentDelegated(account)) { dispatcher.processParentInvoiceForAdjustments(account, event.getInvoiceId(), context); } } catch (final InvoiceApiException e) { log.warn("Unable to process event {}", event, e); } catch (final AccountApiException e) { log.warn("Unable to process event {}", event, e); } } });