Search in sources :

Example 1 with OverdueAsyncBusNotificationKey

use of org.killbill.billing.overdue.notification.OverdueAsyncBusNotificationKey in project killbill by killbill.

the class OverdueListener method insertBusEventIntoNotificationQueue.

private void insertBusEventIntoNotificationQueue(final UUID accountId, final OverdueAsyncBusNotificationAction action, final InternalCallContext callContext) {
    final boolean shouldInsertNotification = shouldInsertNotification(callContext);
    if (shouldInsertNotification) {
        OverdueAsyncBusNotificationKey notificationKey = new OverdueAsyncBusNotificationKey(accountId, action);
        asyncPoster.insertOverdueNotification(accountId, clock.getUTCNow(), OverdueAsyncBusNotifier.OVERDUE_ASYNC_BUS_NOTIFIER_QUEUE, notificationKey, callContext);
        try {
            final List<Account> childrenAccounts = accountApi.getChildrenAccounts(accountId, callContext);
            if (childrenAccounts != null) {
                for (Account childAccount : childrenAccounts) {
                    if (childAccount.isPaymentDelegatedToParent()) {
                        final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(childAccount.getId(), callContext);
                        final InternalCallContext accountContext = internalCallContextFactory.createInternalCallContext(internalTenantContext.getAccountRecordId(), callContext);
                        notificationKey = new OverdueAsyncBusNotificationKey(childAccount.getId(), action);
                        asyncPoster.insertOverdueNotification(childAccount.getId(), clock.getUTCNow(), OverdueAsyncBusNotifier.OVERDUE_ASYNC_BUS_NOTIFIER_QUEUE, notificationKey, accountContext);
                    }
                }
            }
        } catch (Exception e) {
            log.error("Error loading child accounts from account " + accountId);
        }
    }
}
Also used : Account(org.killbill.billing.account.api.Account) OverdueAsyncBusNotificationKey(org.killbill.billing.overdue.notification.OverdueAsyncBusNotificationKey) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) OverdueApiException(org.killbill.billing.overdue.api.OverdueApiException)

Aggregations

Account (org.killbill.billing.account.api.Account)1 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)1 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)1 OverdueApiException (org.killbill.billing.overdue.api.OverdueApiException)1 OverdueAsyncBusNotificationKey (org.killbill.billing.overdue.notification.OverdueAsyncBusNotificationKey)1