use of com.google.common.eventbus.AllowConcurrentEvents in project killbill by killbill.
the class PaymentBusEventHandler method processInvoiceEvent.
@AllowConcurrentEvents
@Subscribe
public void processInvoiceEvent(final InvoiceCreationInternalEvent event) {
log.info("Received invoice creation notification for accountId='{}', invoiceId='{}'", event.getAccountId(), event.getInvoiceId());
final Collection<PluginProperty> properties = new ArrayList<PluginProperty>();
final PluginProperty propertyInvoiceId = new PluginProperty(InvoicePaymentControlPluginApi.PROP_IPCD_INVOICE_ID, event.getInvoiceId().toString(), false);
properties.add(propertyInvoiceId);
final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContext(event.getSearchKey2(), event.getSearchKey1(), "PaymentRequestProcessor", CallOrigin.INTERNAL, UserType.SYSTEM, event.getUserToken());
final CallContext callContext = internalCallContextFactory.createCallContext(internalContext);
// We let the plugin compute how much should be paid
final BigDecimal amountToBePaid = null;
final List<String> paymentControlPluginNames = paymentConfig.getPaymentControlPluginNames(internalContext) != null ? new LinkedList<String>(paymentConfig.getPaymentControlPluginNames(internalContext)) : new LinkedList<String>();
paymentControlPluginNames.add(InvoicePaymentControlPluginApi.PLUGIN_NAME);
final String transactionType = TransactionType.PURCHASE.name();
Account account = null;
Payment payment = null;
PaymentTransaction paymentTransaction = null;
try {
account = accountApi.getAccountById(event.getAccountId(), internalContext);
logEnterAPICall(log, transactionType, account, account.getPaymentMethodId(), null, null, amountToBePaid, account.getCurrency(), null, null, null, paymentControlPluginNames);
payment = pluginControlPaymentProcessor.createPurchase(false, account, account.getPaymentMethodId(), null, amountToBePaid, account.getCurrency(), null, null, properties, paymentControlPluginNames, callContext, internalContext);
paymentTransaction = payment.getTransactions().get(payment.getTransactions().size() - 1);
} catch (final AccountApiException e) {
log.warn("Failed to process invoice payment", e);
} catch (final PaymentApiException e) {
// Log as warn unless nothing left to be paid
if (e.getCode() != ErrorCode.PAYMENT_PLUGIN_API_ABORTED.getCode()) {
log.warn("Failed to process invoice payment {}", e.toString());
}
} 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, null);
}
}
use of com.google.common.eventbus.AllowConcurrentEvents 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 com.google.common.eventbus.AllowConcurrentEvents in project killbill by killbill.
the class InvoiceListener method handleChildrenInvoiceCreationEvent.
@AllowConcurrentEvents
@Subscribe
public void handleChildrenInvoiceCreationEvent(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 (InvoiceApiException e) {
log.error(e.getMessage());
} catch (AccountApiException e) {
log.error(e.getMessage());
}
}
use of com.google.common.eventbus.AllowConcurrentEvents in project killbill by killbill.
the class InvoiceListener method handleBlockingStateTransition.
@AllowConcurrentEvents
@Subscribe
public void handleBlockingStateTransition(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, context);
} catch (InvoiceApiException e) {
log.warn("Unable to process event {}", event, e);
} catch (AccountApiException e) {
log.warn("Unable to process event {}", event, e);
}
}
use of com.google.common.eventbus.AllowConcurrentEvents in project killbill by killbill.
the class InvoiceListener method handleSubscriptionTransition.
@AllowConcurrentEvents
@Subscribe
public void handleSubscriptionTransition(final EffectiveSubscriptionInternalEvent event) {
try {
// Skip events which are marked as not being the last one
if (event.getTransitionType() == SubscriptionBaseTransitionType.UNCANCEL || event.getRemainingEventsForUserOperation() > 0) {
return;
}
final InternalCallContext context = internalCallContextFactory.createInternalCallContext(event.getSearchKey2(), event.getSearchKey1(), "SubscriptionBaseTransition", CallOrigin.INTERNAL, UserType.SYSTEM, event.getUserToken());
dispatcher.processSubscriptionForInvoiceGeneration(event, context);
} catch (InvoiceApiException e) {
log.warn("Unable to process event {}", event, e);
}
}
Aggregations