Search in sources :

Example 1 with EventBusException

use of org.killbill.bus.api.PersistentBus.EventBusException in project killbill by killbill.

the class DefaultSubscriptionBaseService method processEventReady.

@Override
public void processEventReady(final SubscriptionBaseEvent event, final int seqId, final InternalCallContext context) {
    if (!event.isActive()) {
        return;
    }
    try {
        final DefaultSubscriptionBase subscription = (DefaultSubscriptionBase) dao.getSubscriptionFromId(event.getSubscriptionId(), context);
        if (subscription == null) {
            log.warn("Error retrieving subscriptionId='{}'", event.getSubscriptionId());
            return;
        }
        final SubscriptionBaseTransitionData transition = subscription.getTransitionFromEvent(event, seqId);
        if (transition == null) {
            log.warn("Skipping event ='{}', no matching transition was built", event.getType());
            return;
        }
        boolean eventSent = false;
        if (event.getType() == EventType.PHASE) {
            eventSent = onPhaseEvent(subscription, event, context);
        } else if (event.getType() == EventType.API_USER && subscription.getCategory() == ProductCategory.BASE) {
            final CallContext callContext = internalCallContextFactory.createCallContext(context);
            eventSent = onBasePlanEvent(subscription, event, callContext);
        } else if (event.getType() == EventType.BCD_UPDATE) {
            eventSent = false;
        }
        if (!eventSent) {
            // Methods above invoking the DAO will send this event directly from the transaction
            final BusEvent busEvent = new DefaultEffectiveSubscriptionEvent(transition, subscription.getAlignStartDate(), context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId());
            eventBus.post(busEvent);
        }
    } catch (final EventBusException e) {
        log.warn("Failed to post event {}", event, e);
    } catch (final CatalogApiException e) {
        log.warn("Failed to post event {}", event, e);
    }
}
Also used : SubscriptionBaseTransitionData(org.killbill.billing.subscription.api.user.SubscriptionBaseTransitionData) DefaultEffectiveSubscriptionEvent(org.killbill.billing.subscription.api.user.DefaultEffectiveSubscriptionEvent) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) EventBusException(org.killbill.bus.api.PersistentBus.EventBusException) DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) CallContext(org.killbill.billing.util.callcontext.CallContext) BusEvent(org.killbill.bus.api.BusEvent)

Example 2 with EventBusException

use of org.killbill.bus.api.PersistentBus.EventBusException in project killbill by killbill.

the class PaymentEnteringStateCallback method enteringState.

@Override
public void enteringState(final State newState, final Operation.OperationCallback operationCallback, final OperationResult operationResult, final LeavingStateCallback leavingStateCallback) {
    logger.debug("Entering state {} with result {}", newState.getName(), operationResult);
    // If the transaction was not created -- for instance we had an exception in leavingState callback then we bail; if not, then update state:
    if (paymentStateContext.getPaymentTransactionModelDao() != null && paymentStateContext.getPaymentTransactionModelDao().getId() != null) {
        final PaymentTransactionInfoPlugin paymentInfoPlugin = paymentStateContext.getPaymentTransactionInfoPlugin();
        final TransactionStatus transactionStatus = PaymentTransactionInfoPluginConverter.toTransactionStatus(paymentInfoPlugin);
        // The bus event will be posted from the transaction
        daoHelper.processPaymentInfoPlugin(transactionStatus, paymentInfoPlugin, newState.getName());
    } else if (!paymentStateContext.isApiPayment()) {
        //
        // If there is NO transaction to update (because payment transaction did not occur), then there is something wrong happening (maybe a missing defaultPaymentMethodId, ...)
        // so, if the call does NOT originates from api then we still want to send a bus event so the system can react to it if needed.
        //
        final BusInternalEvent event = new DefaultPaymentErrorEvent(paymentStateContext.getAccount().getId(), null, null, paymentStateContext.getAmount(), paymentStateContext.getCurrency(), null, paymentStateContext.getTransactionType(), null, "Early abortion of payment transaction", paymentStateContext.getInternalCallContext().getAccountRecordId(), paymentStateContext.getInternalCallContext().getTenantRecordId(), paymentStateContext.getInternalCallContext().getUserToken());
        try {
            daoHelper.getEventBus().post(event);
        } catch (EventBusException e) {
            logger.warn("Failed to post event {}", event, e);
        }
    }
}
Also used : PaymentTransactionInfoPlugin(org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin) TransactionStatus(org.killbill.billing.payment.api.TransactionStatus) EventBusException(org.killbill.bus.api.PersistentBus.EventBusException) DefaultPaymentErrorEvent(org.killbill.billing.payment.api.DefaultPaymentErrorEvent) BusInternalEvent(org.killbill.billing.events.BusInternalEvent)

Example 3 with EventBusException

use of org.killbill.bus.api.PersistentBus.EventBusException in project killbill by killbill.

the class MockAccountDao method update.

@Override
public void update(final AccountModelDao account, final InternalCallContext context) {
    super.update(account, context);
    final AccountModelDao currentAccount = getById(account.getId(), context);
    final Long accountRecordId = getRecordId(account.getId(), context);
    final long tenantRecordId = context == null ? InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID : context.getTenantRecordId();
    final AccountChangeInternalEvent changeEvent = new DefaultAccountChangeEvent(account.getId(), currentAccount, account, accountRecordId, tenantRecordId, UUID.randomUUID(), clock.getUTCNow());
    if (changeEvent.hasChanges()) {
        try {
            eventBus.post(changeEvent);
        } catch (final EventBusException ex) {
            Assert.fail(ex.toString());
        }
    }
}
Also used : AccountChangeInternalEvent(org.killbill.billing.events.AccountChangeInternalEvent) EventBusException(org.killbill.bus.api.PersistentBus.EventBusException) DefaultAccountChangeEvent(org.killbill.billing.account.api.user.DefaultAccountChangeEvent)

Example 4 with EventBusException

use of org.killbill.bus.api.PersistentBus.EventBusException in project killbill by killbill.

the class DefaultInvoiceDao method notifyBusOfInvoiceCreation.

private void notifyBusOfInvoiceCreation(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory, final InvoiceModelDao invoice, final InternalCallContext context) {
    try {
        final BigDecimal balance = InvoiceModelDaoHelper.getBalance(invoice);
        final DefaultInvoiceCreationEvent event = new DefaultInvoiceCreationEvent(invoice.getId(), invoice.getAccountId(), balance, invoice.getCurrency(), context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken());
        eventBus.postFromTransaction(event, entitySqlDaoWrapperFactory.getHandle().getConnection());
    } catch (final EventBusException e) {
        log.error(String.format("Failed to post invoice creation event %s for account %s", invoice.getAccountId()), e);
    }
}
Also used : EventBusException(org.killbill.bus.api.PersistentBus.EventBusException) BigDecimal(java.math.BigDecimal) DefaultInvoiceCreationEvent(org.killbill.billing.invoice.api.user.DefaultInvoiceCreationEvent)

Example 5 with EventBusException

use of org.killbill.bus.api.PersistentBus.EventBusException in project killbill by killbill.

the class MockSubscriptionDaoMemory method notifyBusOfEffectiveImmediateChange.

private void notifyBusOfEffectiveImmediateChange(final DefaultSubscriptionBase subscription, final SubscriptionBaseEvent immediateEvent, final int seqId, final InternalCallContext context) {
    try {
        final SubscriptionBaseTransitionData transition = subscription.getTransitionFromEvent(immediateEvent, seqId);
        final BusEvent busEvent = new DefaultEffectiveSubscriptionEvent(transition, subscription.getAlignStartDate(), context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId());
        eventBus.post(busEvent);
    } catch (final EventBusException e) {
        log.warn("Failed to post effective event for subscription " + subscription.getId(), e);
    }
}
Also used : SubscriptionBaseTransitionData(org.killbill.billing.subscription.api.user.SubscriptionBaseTransitionData) DefaultEffectiveSubscriptionEvent(org.killbill.billing.subscription.api.user.DefaultEffectiveSubscriptionEvent) EventBusException(org.killbill.bus.api.PersistentBus.EventBusException) BusEvent(org.killbill.bus.api.BusEvent)

Aggregations

EventBusException (org.killbill.bus.api.PersistentBus.EventBusException)9 DefaultEffectiveSubscriptionEvent (org.killbill.billing.subscription.api.user.DefaultEffectiveSubscriptionEvent)3 SubscriptionBaseTransitionData (org.killbill.billing.subscription.api.user.SubscriptionBaseTransitionData)3 BusEvent (org.killbill.bus.api.BusEvent)3 DefaultAccountCreationEvent (org.killbill.billing.account.api.user.DefaultAccountCreationEvent)2 DefaultAccountData (org.killbill.billing.account.api.user.DefaultAccountCreationEvent.DefaultAccountData)2 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)2 BigDecimal (java.math.BigDecimal)1 DefaultAccountChangeEvent (org.killbill.billing.account.api.user.DefaultAccountChangeEvent)1 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)1 AccountChangeInternalEvent (org.killbill.billing.events.AccountChangeInternalEvent)1 AccountCreationInternalEvent (org.killbill.billing.events.AccountCreationInternalEvent)1 BroadcastInternalEvent (org.killbill.billing.events.BroadcastInternalEvent)1 BusInternalEvent (org.killbill.billing.events.BusInternalEvent)1 DefaultInvoiceCreationEvent (org.killbill.billing.invoice.api.user.DefaultInvoiceCreationEvent)1 DefaultPaymentErrorEvent (org.killbill.billing.payment.api.DefaultPaymentErrorEvent)1 TransactionStatus (org.killbill.billing.payment.api.TransactionStatus)1 PaymentTransactionInfoPlugin (org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin)1 DefaultSubscriptionBase (org.killbill.billing.subscription.api.user.DefaultSubscriptionBase)1 BroadcastModelDao (org.killbill.billing.util.broadcast.dao.BroadcastModelDao)1