Search in sources :

Example 1 with CompletionControlOperation

use of org.killbill.billing.payment.core.sm.control.CompletionControlOperation in project killbill by killbill.

the class PluginControlPaymentAutomatonRunner method completeRun.

public Payment completeRun(final PaymentStateControlContext paymentStateContext) throws PaymentApiException {
    try {
        final OperationCallback callback = new CompletionControlOperation(locker, paymentPluginDispatcher, paymentConfig, paymentStateContext, paymentRefresher, paymentProcessor, controlPluginRunner);
        final LeavingStateCallback leavingStateCallback = new NoopControlInitiated();
        final EnteringStateCallback enteringStateCallback = new DefaultControlCompleted(this, paymentStateContext, paymentControlStateMachineHelper.getRetriedState(), retryServiceScheduler);
        paymentControlStateMachineHelper.getInitialState().runOperation(paymentControlStateMachineHelper.getOperation(), callback, enteringStateCallback, leavingStateCallback);
    } catch (final MissingEntryException e) {
        throw new PaymentApiException(e.getCause(), ErrorCode.PAYMENT_INTERNAL_ERROR, MoreObjects.firstNonNull(e.getMessage(), ""));
    } catch (final OperationException e) {
        if (e.getCause() instanceof PaymentApiException) {
            throw (PaymentApiException) e.getCause();
        // If the control plugin tries to pass us back a PaymentApiException we throw it
        } else if (e.getCause() instanceof PaymentControlApiException && e.getCause().getCause() instanceof PaymentApiException) {
            throw (PaymentApiException) e.getCause().getCause();
        } else if (e.getCause() != null || paymentStateContext.getResult() == null) {
            throw new PaymentApiException(e.getCause(), ErrorCode.PAYMENT_INTERNAL_ERROR, MoreObjects.firstNonNull(e.getMessage(), ""));
        }
    }
    // we don't throw, and return the failed Payment instead to be consistent with what happens when we don't go through control api.
    return paymentStateContext.getResult();
}
Also used : OperationCallback(org.killbill.automaton.Operation.OperationCallback) CompletionControlOperation(org.killbill.billing.payment.core.sm.control.CompletionControlOperation) NoopControlInitiated(org.killbill.billing.payment.core.sm.control.NoopControlInitiated) DefaultControlCompleted(org.killbill.billing.payment.core.sm.control.DefaultControlCompleted) MissingEntryException(org.killbill.automaton.MissingEntryException) PaymentApiException(org.killbill.billing.payment.api.PaymentApiException) LeavingStateCallback(org.killbill.automaton.State.LeavingStateCallback) EnteringStateCallback(org.killbill.automaton.State.EnteringStateCallback) OperationException(org.killbill.automaton.OperationException) PaymentControlApiException(org.killbill.billing.control.plugin.api.PaymentControlApiException)

Aggregations

MissingEntryException (org.killbill.automaton.MissingEntryException)1 OperationCallback (org.killbill.automaton.Operation.OperationCallback)1 OperationException (org.killbill.automaton.OperationException)1 EnteringStateCallback (org.killbill.automaton.State.EnteringStateCallback)1 LeavingStateCallback (org.killbill.automaton.State.LeavingStateCallback)1 PaymentControlApiException (org.killbill.billing.control.plugin.api.PaymentControlApiException)1 PaymentApiException (org.killbill.billing.payment.api.PaymentApiException)1 CompletionControlOperation (org.killbill.billing.payment.core.sm.control.CompletionControlOperation)1 DefaultControlCompleted (org.killbill.billing.payment.core.sm.control.DefaultControlCompleted)1 NoopControlInitiated (org.killbill.billing.payment.core.sm.control.NoopControlInitiated)1