Search in sources :

Example 1 with OperationResult

use of org.killbill.automaton.OperationResult in project killbill by killbill.

the class OperationControlCallback method getOperationResultOnException.

private OperationResult getOperationResultOnException(final PaymentStateContext paymentStateContext) {
    final PaymentStateControlContext paymentStateControlContext = (PaymentStateControlContext) paymentStateContext;
    final OperationResult operationResult = paymentStateControlContext.getRetryDate() != null ? OperationResult.FAILURE : OperationResult.EXCEPTION;
    return operationResult;
}
Also used : OperationResult(org.killbill.automaton.OperationResult)

Example 2 with OperationResult

use of org.killbill.automaton.OperationResult in project killbill by killbill.

the class TestPluginOperation method getPluginOperation.

private PaymentOperation getPluginOperation(final boolean shouldLockAccount, final int timeoutSeconds) throws PaymentApiException {
    final PluginDispatcher<OperationResult> paymentPluginDispatcher = new PluginDispatcher<OperationResult>(timeoutSeconds, paymentExecutors);
    final PaymentStateContext paymentStateContext = new PaymentStateContext(true, UUID.randomUUID(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), TransactionType.CAPTURE, account, UUID.randomUUID(), new BigDecimal("192.3920111"), Currency.BRL, null, null, shouldLockAccount, null, ImmutableList.<PluginProperty>of(), internalCallContext, callContext);
    final PaymentAutomatonDAOHelper daoHelper = Mockito.mock(PaymentAutomatonDAOHelper.class);
    Mockito.when(daoHelper.getPaymentPluginApi()).thenReturn(null);
    return new PluginOperationTest(daoHelper, locker, paymentPluginDispatcher, paymentConfig, paymentStateContext);
}
Also used : PluginDispatcher(org.killbill.billing.payment.dispatcher.PluginDispatcher) OperationResult(org.killbill.automaton.OperationResult) BigDecimal(java.math.BigDecimal)

Example 3 with OperationResult

use of org.killbill.automaton.OperationResult in project killbill by killbill.

the class OperationCallbackBase method dispatchWithAccountLockAndTimeout.

//
// Dispatch the Callable to the executor by first wrapping it into a CallableWithAccountLock
// The dispatcher may throw a TimeoutException, ExecutionException, or InterruptedException; those will be handled in specific
// callback to eventually throw a OperationException, that will be used to drive the state machine in the right direction.
//
protected <ExceptionType extends Exception> OperationResult dispatchWithAccountLockAndTimeout(final String pluginNames, final DispatcherCallback<PluginDispatcherReturnType<OperationResult>, ExceptionType> callback) throws OperationException {
    final Account account = paymentStateContext.getAccount();
    logger.debug("Dispatching plugin call for account {}", account.getExternalKey());
    try {
        final Callable<PluginDispatcherReturnType<OperationResult>> task = new CallableWithAccountLock<OperationResult, ExceptionType>(locker, account.getId(), paymentConfig, callback);
        final OperationResult operationResult = PaymentPluginDispatcher.dispatchWithExceptionHandling(account, pluginNames, task, paymentPluginDispatcher);
        return operationResult;
    } catch (final PaymentApiException e) {
        throw unwrapExceptionFromDispatchedTask(e);
    }
}
Also used : Account(org.killbill.billing.account.api.Account) PluginDispatcherReturnType(org.killbill.billing.payment.dispatcher.PluginDispatcher.PluginDispatcherReturnType) CallableWithAccountLock(org.killbill.billing.payment.core.ProcessorBase.CallableWithAccountLock) OperationResult(org.killbill.automaton.OperationResult) PaymentApiException(org.killbill.billing.payment.api.PaymentApiException)

Example 4 with OperationResult

use of org.killbill.automaton.OperationResult in project killbill by killbill.

the class PaymentProcessor method notifyPendingPaymentOfStateChanged.

public Payment notifyPendingPaymentOfStateChanged(final Account account, final UUID transactionId, final boolean isSuccess, final CallContext callContext, final InternalCallContext internalCallContext) throws PaymentApiException {
    final PaymentTransactionModelDao transactionModelDao = paymentDao.getPaymentTransaction(transactionId, internalCallContext);
    if (transactionModelDao.getTransactionStatus() != TransactionStatus.PENDING) {
        throw new PaymentApiException(ErrorCode.PAYMENT_NO_SUCH_SUCCESS_PAYMENT, transactionModelDao.getPaymentId());
    }
    final OperationResult overridePluginResult = isSuccess ? OperationResult.SUCCESS : OperationResult.FAILURE;
    final boolean runJanitor = false;
    return performOperation(true, runJanitor, null, transactionModelDao.getTransactionType(), account, null, transactionModelDao.getPaymentId(), transactionModelDao.getId(), transactionModelDao.getAmount(), transactionModelDao.getCurrency(), null, transactionModelDao.getTransactionExternalKey(), null, null, true, overridePluginResult, PLUGIN_PROPERTIES, callContext, internalCallContext);
}
Also used : PaymentTransactionModelDao(org.killbill.billing.payment.dao.PaymentTransactionModelDao) PaymentApiException(org.killbill.billing.payment.api.PaymentApiException) OperationResult(org.killbill.automaton.OperationResult)

Example 5 with OperationResult

use of org.killbill.automaton.OperationResult in project killbill by killbill.

the class TestPaymentOperation method setUp.

private void setUp(final PaymentPluginStatus paymentPluginStatus) throws Exception {
    final GlobalLocker locker = new MemoryGlobalLocker();
    final PluginDispatcher<OperationResult> paymentPluginDispatcher = new PluginDispatcher<OperationResult>(1, paymentExecutors);
    paymentStateContext = new PaymentStateContext(true, UUID.randomUUID(), null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), TransactionType.CAPTURE, Mockito.mock(Account.class), UUID.randomUUID(), new BigDecimal("192.3920111"), Currency.BRL, null, null, false, null, ImmutableList.<PluginProperty>of(), internalCallContext, callContext);
    final PaymentMethodModelDao paymentMethodModelDao = new PaymentMethodModelDao(paymentStateContext.getPaymentMethodId(), UUID.randomUUID().toString(), clock.getUTCNow(), clock.getUTCNow(), paymentStateContext.getAccount().getId(), MockPaymentProviderPlugin.PLUGIN_NAME, true);
    final PaymentDao paymentDao = Mockito.mock(PaymentDao.class);
    Mockito.when(paymentDao.getPaymentMethod(paymentStateContext.getPaymentMethodId(), internalCallContext)).thenReturn(paymentMethodModelDao);
    final PaymentPluginServiceRegistration paymentPluginServiceRegistration = new PaymentPluginServiceRegistration(paymentDao, registry);
    final PaymentAutomatonDAOHelper daoHelper = new PaymentAutomatonDAOHelper(paymentStateContext, clock.getUTCNow(), paymentDao, paymentPluginServiceRegistration, internalCallContext, eventBus, paymentSMHelper);
    paymentOperation = new PaymentOperationTest(paymentPluginStatus, daoHelper, locker, paymentPluginDispatcher, paymentConfig, paymentStateContext);
}
Also used : GlobalLocker(org.killbill.commons.locker.GlobalLocker) MemoryGlobalLocker(org.killbill.commons.locker.memory.MemoryGlobalLocker) PaymentMethodModelDao(org.killbill.billing.payment.dao.PaymentMethodModelDao) OperationResult(org.killbill.automaton.OperationResult) BigDecimal(java.math.BigDecimal) PluginProperty(org.killbill.billing.payment.api.PluginProperty) MemoryGlobalLocker(org.killbill.commons.locker.memory.MemoryGlobalLocker) PluginDispatcher(org.killbill.billing.payment.dispatcher.PluginDispatcher) PaymentPluginServiceRegistration(org.killbill.billing.payment.core.PaymentPluginServiceRegistration) PaymentDao(org.killbill.billing.payment.dao.PaymentDao)

Aggregations

OperationResult (org.killbill.automaton.OperationResult)5 BigDecimal (java.math.BigDecimal)2 PaymentApiException (org.killbill.billing.payment.api.PaymentApiException)2 PluginDispatcher (org.killbill.billing.payment.dispatcher.PluginDispatcher)2 Account (org.killbill.billing.account.api.Account)1 PluginProperty (org.killbill.billing.payment.api.PluginProperty)1 PaymentPluginServiceRegistration (org.killbill.billing.payment.core.PaymentPluginServiceRegistration)1 CallableWithAccountLock (org.killbill.billing.payment.core.ProcessorBase.CallableWithAccountLock)1 PaymentDao (org.killbill.billing.payment.dao.PaymentDao)1 PaymentMethodModelDao (org.killbill.billing.payment.dao.PaymentMethodModelDao)1 PaymentTransactionModelDao (org.killbill.billing.payment.dao.PaymentTransactionModelDao)1 PluginDispatcherReturnType (org.killbill.billing.payment.dispatcher.PluginDispatcher.PluginDispatcherReturnType)1 GlobalLocker (org.killbill.commons.locker.GlobalLocker)1 MemoryGlobalLocker (org.killbill.commons.locker.memory.MemoryGlobalLocker)1