Search in sources :

Example 61 with InternalCallContext

use of org.killbill.billing.callcontext.InternalCallContext in project killbill by killbill.

the class DefaultPaymentApi method createChargebackWithPaymentControl.

@Override
public Payment createChargebackWithPaymentControl(final Account account, final UUID paymentId, final BigDecimal amount, final Currency currency, final String paymentTransactionExternalKey, final PaymentOptions paymentOptions, final CallContext callContext) throws PaymentApiException {
    final List<String> paymentControlPluginNames = toPaymentControlPluginNames(paymentOptions, callContext);
    if (paymentControlPluginNames.isEmpty()) {
        return createChargeback(account, paymentId, amount, currency, paymentTransactionExternalKey, callContext);
    }
    checkNotNullParameter(account, "account");
    checkNotNullParameter(amount, "amount");
    checkNotNullParameter(currency, "currency");
    checkNotNullParameter(paymentId, "paymentId");
    final String transactionType = TransactionType.CHARGEBACK.name();
    Payment payment = null;
    PaymentTransaction paymentTransaction = null;
    PaymentApiException exception = null;
    try {
        logEnterAPICall(log, transactionType, account, null, paymentId, null, amount, currency, null, paymentTransactionExternalKey, null, paymentControlPluginNames);
        final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(account.getId(), callContext);
        payment = pluginControlPaymentProcessor.createChargeback(IS_API_PAYMENT, account, paymentId, paymentTransactionExternalKey, amount, currency, paymentControlPluginNames, callContext, internalCallContext);
        paymentTransaction = findPaymentTransaction(payment, paymentTransactionExternalKey);
        return payment;
    } catch (PaymentApiException e) {
        exception = e;
        throw e;
    } finally {
        logExitAPICall(log, transactionType, account, payment != null ? payment.getPaymentMethodId() : null, payment != null ? payment.getId() : null, paymentTransaction != null ? paymentTransaction.getId() : null, paymentTransaction != null ? paymentTransaction.getProcessedAmount() : null, paymentTransaction != null ? paymentTransaction.getProcessedCurrency() : null, payment != null ? payment.getExternalKey() : null, paymentTransaction != null ? paymentTransaction.getExternalKey() : null, paymentTransaction != null ? paymentTransaction.getTransactionStatus() : null, paymentControlPluginNames, exception);
    }
}
Also used : InternalCallContext(org.killbill.billing.callcontext.InternalCallContext)

Example 62 with InternalCallContext

use of org.killbill.billing.callcontext.InternalCallContext 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)

Example 63 with InternalCallContext

use of org.killbill.billing.callcontext.InternalCallContext in project killbill by killbill.

the class OverdueListener method insertBusEventIntoNotificationQueue.

private void insertBusEventIntoNotificationQueue(final UUID accountId, final BusEvent event) {
    final InternalCallContext internalCallContext = createCallContext(event.getUserToken(), event.getSearchKey1(), event.getSearchKey2());
    insertBusEventIntoNotificationQueue(accountId, OverdueAsyncBusNotificationAction.REFRESH, internalCallContext);
}
Also used : InternalCallContext(org.killbill.billing.callcontext.InternalCallContext)

Example 64 with InternalCallContext

use of org.killbill.billing.callcontext.InternalCallContext in project killbill by killbill.

the class OverdueListener method handleTagInsert.

@AllowConcurrentEvents
@Subscribe
public void handleTagInsert(final ControlTagCreationInternalEvent event) {
    if (event.getTagDefinition().getName().equals(ControlTagType.OVERDUE_ENFORCEMENT_OFF.toString()) && event.getObjectType() == ObjectType.ACCOUNT) {
        final InternalCallContext internalCallContext = createCallContext(event.getUserToken(), event.getSearchKey1(), event.getSearchKey2());
        insertBusEventIntoNotificationQueue(event.getObjectId(), OverdueAsyncBusNotificationAction.CLEAR, internalCallContext);
    } else if (event.getTagDefinition().getName().equals(ControlTagType.WRITTEN_OFF.toString()) && event.getObjectType() == ObjectType.INVOICE) {
        final UUID accountId = nonEntityDao.retrieveIdFromObject(event.getSearchKey1(), ObjectType.ACCOUNT, cacheControllerDispatcher.getCacheController(CacheType.OBJECT_ID));
        insertBusEventIntoNotificationQueue(accountId, event);
    }
}
Also used : InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) UUID(java.util.UUID) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) Subscribe(com.google.common.eventbus.Subscribe)

Example 65 with InternalCallContext

use of org.killbill.billing.callcontext.InternalCallContext in project killbill by killbill.

the class OverdueWrapper method billingState.

public BillingState billingState(final InternalCallContext context) throws OverdueException {
    if ((overdueable.getParentAccountId() != null) && (overdueable.isPaymentDelegatedToParent())) {
        // calculate billing state from parent account
        final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(overdueable.getParentAccountId(), context);
        final InternalCallContext parentAccountContext = internalCallContextFactory.createInternalCallContext(internalTenantContext.getAccountRecordId(), context);
        return billingStateCalcuator.calculateBillingState(overdueable, parentAccountContext);
    }
    return billingStateCalcuator.calculateBillingState(overdueable, context);
}
Also used : InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext)

Aggregations

InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)110 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)26 DateTime (org.joda.time.DateTime)25 UUID (java.util.UUID)24 ArrayList (java.util.ArrayList)21 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)17 InvoiceApiException (org.killbill.billing.invoice.api.InvoiceApiException)14 CallContext (org.killbill.billing.util.callcontext.CallContext)14 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)13 WithEntitlementPlugin (org.killbill.billing.entitlement.api.EntitlementPluginExecution.WithEntitlementPlugin)13 EntitlementContext (org.killbill.billing.entitlement.plugin.api.EntitlementContext)13 AccountApiException (org.killbill.billing.account.api.AccountApiException)12 DefaultBlockingState (org.killbill.billing.junction.DefaultBlockingState)12 NotificationEvent (org.killbill.notificationq.api.NotificationEvent)9 BigDecimal (java.math.BigDecimal)8 LinkedList (java.util.LinkedList)8 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)8 Invoice (org.killbill.billing.invoice.api.Invoice)8 AllowConcurrentEvents (com.google.common.eventbus.AllowConcurrentEvents)7 Subscribe (com.google.common.eventbus.Subscribe)7