Search in sources :

Example 6 with AllowConcurrentEvents

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);
    }
}
Also used : Account(org.killbill.billing.account.api.Account) ArrayList(java.util.ArrayList) PaymentApiException(org.killbill.billing.payment.api.PaymentApiException) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) CallContext(org.killbill.billing.util.callcontext.CallContext) BigDecimal(java.math.BigDecimal) PaymentTransaction(org.killbill.billing.payment.api.PaymentTransaction) PluginProperty(org.killbill.billing.payment.api.PluginProperty) Payment(org.killbill.billing.payment.api.Payment) AccountApiException(org.killbill.billing.account.api.AccountApiException) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) Subscribe(com.google.common.eventbus.Subscribe)

Example 7 with AllowConcurrentEvents

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);
    }
}
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 8 with AllowConcurrentEvents

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());
    }
}
Also used : Account(org.killbill.billing.account.api.Account) InvoiceApiException(org.killbill.billing.invoice.api.InvoiceApiException) AccountApiException(org.killbill.billing.account.api.AccountApiException) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) Subscribe(com.google.common.eventbus.Subscribe)

Example 9 with AllowConcurrentEvents

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);
    }
}
Also used : InvoiceApiException(org.killbill.billing.invoice.api.InvoiceApiException) AccountApiException(org.killbill.billing.account.api.AccountApiException) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) UUID(java.util.UUID) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) Subscribe(com.google.common.eventbus.Subscribe)

Example 10 with AllowConcurrentEvents

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);
    }
}
Also used : InvoiceApiException(org.killbill.billing.invoice.api.InvoiceApiException) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

AllowConcurrentEvents (com.google.common.eventbus.AllowConcurrentEvents)13 Subscribe (com.google.common.eventbus.Subscribe)13 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)7 UUID (java.util.UUID)4 AccountApiException (org.killbill.billing.account.api.AccountApiException)4 InvoiceApiException (org.killbill.billing.invoice.api.InvoiceApiException)4 Account (org.killbill.billing.account.api.Account)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ArrayList (java.util.ArrayList)2 AbstractShardingDataBasesOnlyDBUnitTest (com.dangdang.ddframe.rdb.integrate.db.AbstractShardingDataBasesOnlyDBUnitTest)1 DMLExecutionEvent (com.dangdang.ddframe.rdb.sharding.executor.event.DMLExecutionEvent)1 DMLExecutionEventListener (com.dangdang.ddframe.rdb.sharding.executor.event.DMLExecutionEventListener)1 SoftTransactionConfiguration (com.dangdang.ddframe.rdb.transaction.soft.api.config.SoftTransactionConfiguration)1 BEDSoftTransaction (com.dangdang.ddframe.rdb.transaction.soft.bed.BEDSoftTransaction)1 TransactionLog (com.dangdang.ddframe.rdb.transaction.soft.storage.TransactionLog)1 TransactionLogStorage (com.dangdang.ddframe.rdb.transaction.soft.storage.TransactionLogStorage)1 ActionOwner (com.google.devtools.build.lib.actions.ActionOwner)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)1