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