Search in sources :

Example 1 with DefaultPaymentErrorEvent

use of org.killbill.billing.payment.api.DefaultPaymentErrorEvent 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)

Aggregations

BusInternalEvent (org.killbill.billing.events.BusInternalEvent)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 EventBusException (org.killbill.bus.api.PersistentBus.EventBusException)1