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);
}
}
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);
}
}
}
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);
}
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);
}
}
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);
}
Aggregations