Search in sources :

Example 1 with PaymentControlPluginApi

use of org.killbill.billing.control.plugin.api.PaymentControlPluginApi in project killbill by killbill.

the class ControlPluginRunner method executePluginOnFailureCalls.

public OnFailurePaymentControlResult executePluginOnFailureCalls(final Account account, final UUID paymentMethodId, final UUID paymentAttemptId, final UUID paymentId, final String paymentExternalKey, final UUID transactionId, final String paymentTransactionExternalKey, final PaymentApiType paymentApiType, final TransactionType transactionType, final HPPType hppType, final BigDecimal amount, final Currency currency, final BigDecimal processedAmount, final Currency processedCurrency, final boolean isApiPayment, final List<String> paymentControlPluginNames, final Iterable<PluginProperty> pluginProperties, final CallContext callContext) {
    final PaymentControlContext inputPaymentControlContext = new DefaultPaymentControlContext(account, paymentMethodId, paymentAttemptId, paymentId, paymentExternalKey, transactionId, paymentTransactionExternalKey, paymentApiType, transactionType, hppType, amount, currency, processedAmount, processedCurrency, isApiPayment, callContext);
    DateTime candidate = null;
    Iterable<PluginProperty> inputPluginProperties = pluginProperties;
    for (final String pluginName : paymentControlPluginNames) {
        final PaymentControlPluginApi plugin = paymentControlPluginRegistry.getServiceForName(pluginName);
        if (plugin != null) {
            try {
                log.debug("Calling onSuccessCall of plugin {}", pluginName);
                final OnFailurePaymentControlResult result = plugin.onFailureCall(inputPaymentControlContext, inputPluginProperties);
                log.debug("Successful executed onSuccessCall of plugin {}", pluginName);
                if (result == null) {
                    // Nothing returned by the plugin
                    continue;
                }
                if (candidate == null) {
                    candidate = result.getNextRetryDate();
                } else if (result.getNextRetryDate() != null) {
                    candidate = candidate.compareTo(result.getNextRetryDate()) > 0 ? result.getNextRetryDate() : candidate;
                }
                if (result.getAdjustedPluginProperties() != null) {
                    inputPluginProperties = result.getAdjustedPluginProperties();
                }
            } catch (final PaymentControlApiException e) {
                log.warn("Error during onFailureCall for plugin='{}', paymentExternalKey='{}'", pluginName, inputPaymentControlContext.getPaymentExternalKey(), e);
                return new DefaultFailureCallResult(candidate, inputPluginProperties);
            }
        }
    }
    return new DefaultFailureCallResult(candidate, inputPluginProperties);
}
Also used : DefaultFailureCallResult(org.killbill.billing.payment.retry.DefaultFailureCallResult) PluginProperty(org.killbill.billing.payment.api.PluginProperty) OnFailurePaymentControlResult(org.killbill.billing.control.plugin.api.OnFailurePaymentControlResult) PaymentControlPluginApi(org.killbill.billing.control.plugin.api.PaymentControlPluginApi) PaymentControlContext(org.killbill.billing.control.plugin.api.PaymentControlContext) DateTime(org.joda.time.DateTime) PaymentControlApiException(org.killbill.billing.control.plugin.api.PaymentControlApiException)

Example 2 with PaymentControlPluginApi

use of org.killbill.billing.control.plugin.api.PaymentControlPluginApi in project killbill by killbill.

the class ControlPluginRunner method executePluginPriorCalls.

public PriorPaymentControlResult executePluginPriorCalls(final Account account, final UUID paymentMethodId, final UUID paymentAttemptId, final UUID paymentId, final String paymentExternalKey, final UUID paymentTransactionId, final String paymentTransactionExternalKey, final PaymentApiType paymentApiType, final TransactionType transactionType, final HPPType hppType, final BigDecimal amount, final Currency currency, final BigDecimal processedAmount, final Currency processedCurrency, final boolean isApiPayment, final List<String> paymentControlPluginNames, final Iterable<PluginProperty> pluginProperties, final CallContext callContext) throws PaymentControlApiException {
    // Return as soon as the first plugin aborts, or the last result for the last plugin
    PriorPaymentControlResult prevResult = new DefaultPriorPaymentControlResult(false, amount, currency, paymentMethodId, pluginProperties);
    // Those values are adjusted prior each call with the result of what previous call to plugin returned
    UUID inputPaymentMethodId = paymentMethodId;
    BigDecimal inputAmount = amount;
    Currency inputCurrency = currency;
    Iterable<PluginProperty> inputPluginProperties = pluginProperties;
    PaymentControlContext inputPaymentControlContext = new DefaultPaymentControlContext(account, paymentMethodId, paymentAttemptId, paymentId, paymentExternalKey, paymentTransactionId, paymentTransactionExternalKey, paymentApiType, transactionType, hppType, amount, currency, processedAmount, processedCurrency, isApiPayment, callContext);
    for (final String pluginName : paymentControlPluginNames) {
        final PaymentControlPluginApi plugin = paymentControlPluginRegistry.getServiceForName(pluginName);
        if (plugin == null) {
            // First call to plugin, we log warn, if plugin is not registered
            log.warn("Skipping unknown payment control plugin {} when fetching results", pluginName);
            continue;
        }
        log.debug("Calling priorCall of plugin {}", pluginName);
        prevResult = plugin.priorCall(inputPaymentControlContext, inputPluginProperties);
        log.debug("Successful executed priorCall of plugin {}", pluginName);
        if (prevResult == null) {
            // Nothing returned by the plugin
            continue;
        }
        if (prevResult.getAdjustedPaymentMethodId() != null) {
            inputPaymentMethodId = prevResult.getAdjustedPaymentMethodId();
        }
        if (prevResult.getAdjustedAmount() != null) {
            inputAmount = prevResult.getAdjustedAmount();
        }
        if (prevResult.getAdjustedCurrency() != null) {
            inputCurrency = prevResult.getAdjustedCurrency();
        }
        if (prevResult.getAdjustedPluginProperties() != null) {
            inputPluginProperties = prevResult.getAdjustedPluginProperties();
        }
        if (prevResult.isAborted()) {
            throw new PaymentControlApiAbortException(pluginName);
        }
        inputPaymentControlContext = new DefaultPaymentControlContext(account, inputPaymentMethodId, paymentAttemptId, paymentId, paymentExternalKey, paymentTransactionId, paymentTransactionExternalKey, paymentApiType, transactionType, hppType, inputAmount, inputCurrency, processedAmount, processedCurrency, isApiPayment, callContext);
    }
    // Rebuild latest result to include inputPluginProperties
    prevResult = new DefaultPriorPaymentControlResult(prevResult != null && prevResult.isAborted(), inputPaymentMethodId, inputAmount, inputCurrency, inputPluginProperties);
    return prevResult;
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) PaymentControlPluginApi(org.killbill.billing.control.plugin.api.PaymentControlPluginApi) Currency(org.killbill.billing.catalog.api.Currency) DefaultPriorPaymentControlResult(org.killbill.billing.payment.retry.DefaultPriorPaymentControlResult) PriorPaymentControlResult(org.killbill.billing.control.plugin.api.PriorPaymentControlResult) PaymentControlContext(org.killbill.billing.control.plugin.api.PaymentControlContext) UUID(java.util.UUID) DefaultPriorPaymentControlResult(org.killbill.billing.payment.retry.DefaultPriorPaymentControlResult) BigDecimal(java.math.BigDecimal)

Example 3 with PaymentControlPluginApi

use of org.killbill.billing.control.plugin.api.PaymentControlPluginApi in project killbill by killbill.

the class ControlPluginRunner method executePluginOnSuccessCalls.

public OnSuccessPaymentControlResult executePluginOnSuccessCalls(final Account account, final UUID paymentMethodId, final UUID paymentAttemptId, final UUID paymentId, final String paymentExternalKey, final UUID paymentTransactionId, final String paymentTransactionExternalKey, final PaymentApiType paymentApiType, final TransactionType transactionType, final HPPType hppType, final BigDecimal amount, final Currency currency, final BigDecimal processedAmount, final Currency processedCurrency, final boolean isApiPayment, final List<String> paymentControlPluginNames, final Iterable<PluginProperty> pluginProperties, final CallContext callContext) {
    final PaymentControlContext inputPaymentControlContext = new DefaultPaymentControlContext(account, paymentMethodId, paymentAttemptId, paymentId, paymentExternalKey, paymentTransactionId, paymentTransactionExternalKey, paymentApiType, transactionType, hppType, amount, currency, processedAmount, processedCurrency, isApiPayment, callContext);
    Iterable<PluginProperty> inputPluginProperties = pluginProperties;
    for (final String pluginName : paymentControlPluginNames) {
        final PaymentControlPluginApi plugin = paymentControlPluginRegistry.getServiceForName(pluginName);
        if (plugin != null) {
            try {
                log.debug("Calling onSuccessCall of plugin {}", pluginName);
                final OnSuccessPaymentControlResult result = plugin.onSuccessCall(inputPaymentControlContext, inputPluginProperties);
                log.debug("Successful executed onSuccessCall of plugin {}", pluginName);
                if (result == null) {
                    // Nothing returned by the plugin
                    continue;
                }
                if (result.getAdjustedPluginProperties() != null) {
                    inputPluginProperties = result.getAdjustedPluginProperties();
                }
            // Exceptions from the control plugins are ignored (and logged) because the semantics on what to do are undefined.
            } catch (final PaymentControlApiException e) {
                log.warn("Error during onSuccessCall for plugin='{}', paymentExternalKey='{}'", pluginName, inputPaymentControlContext.getPaymentExternalKey(), e);
            } catch (final RuntimeException e) {
                log.warn("Error during onSuccessCall for plugin='{}', paymentExternalKey='{}'", pluginName, inputPaymentControlContext.getPaymentExternalKey(), e);
            }
        }
    }
    return new DefaultOnSuccessPaymentControlResult(inputPluginProperties);
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) DefaultOnSuccessPaymentControlResult(org.killbill.billing.payment.retry.DefaultOnSuccessPaymentControlResult) PaymentControlPluginApi(org.killbill.billing.control.plugin.api.PaymentControlPluginApi) OnSuccessPaymentControlResult(org.killbill.billing.control.plugin.api.OnSuccessPaymentControlResult) DefaultOnSuccessPaymentControlResult(org.killbill.billing.payment.retry.DefaultOnSuccessPaymentControlResult) PaymentControlContext(org.killbill.billing.control.plugin.api.PaymentControlContext) PaymentControlApiException(org.killbill.billing.control.plugin.api.PaymentControlApiException)

Example 4 with PaymentControlPluginApi

use of org.killbill.billing.control.plugin.api.PaymentControlPluginApi in project killbill by killbill.

the class TestDefaultAdminPaymentApi method beforeMethod.

@BeforeMethod(groups = "slow")
public void beforeMethod() throws Exception {
    super.beforeMethod();
    mockPaymentProviderPlugin.clear();
    account = testHelper.createTestAccount("bobo@gmail.com", true);
    final PaymentControlPluginApi mockPaymentControlProviderPlugin = new MockPaymentControlProviderPlugin();
    controlPluginRegistry.registerService(new OSGIServiceDescriptor() {

        @Override
        public String getPluginSymbolicName() {
            return null;
        }

        @Override
        public String getPluginName() {
            return MockPaymentControlProviderPlugin.PLUGIN_NAME;
        }

        @Override
        public String getRegistrationName() {
            return MockPaymentControlProviderPlugin.PLUGIN_NAME;
        }
    }, mockPaymentControlProviderPlugin);
}
Also used : PaymentControlPluginApi(org.killbill.billing.control.plugin.api.PaymentControlPluginApi) OSGIServiceDescriptor(org.killbill.billing.osgi.api.OSGIServiceDescriptor) MockPaymentControlProviderPlugin(org.killbill.billing.payment.provider.MockPaymentControlProviderPlugin) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

PaymentControlPluginApi (org.killbill.billing.control.plugin.api.PaymentControlPluginApi)4 PaymentControlContext (org.killbill.billing.control.plugin.api.PaymentControlContext)3 PluginProperty (org.killbill.billing.payment.api.PluginProperty)3 PaymentControlApiException (org.killbill.billing.control.plugin.api.PaymentControlApiException)2 BigDecimal (java.math.BigDecimal)1 UUID (java.util.UUID)1 DateTime (org.joda.time.DateTime)1 Currency (org.killbill.billing.catalog.api.Currency)1 OnFailurePaymentControlResult (org.killbill.billing.control.plugin.api.OnFailurePaymentControlResult)1 OnSuccessPaymentControlResult (org.killbill.billing.control.plugin.api.OnSuccessPaymentControlResult)1 PriorPaymentControlResult (org.killbill.billing.control.plugin.api.PriorPaymentControlResult)1 OSGIServiceDescriptor (org.killbill.billing.osgi.api.OSGIServiceDescriptor)1 MockPaymentControlProviderPlugin (org.killbill.billing.payment.provider.MockPaymentControlProviderPlugin)1 DefaultFailureCallResult (org.killbill.billing.payment.retry.DefaultFailureCallResult)1 DefaultOnSuccessPaymentControlResult (org.killbill.billing.payment.retry.DefaultOnSuccessPaymentControlResult)1 DefaultPriorPaymentControlResult (org.killbill.billing.payment.retry.DefaultPriorPaymentControlResult)1 BeforeMethod (org.testng.annotations.BeforeMethod)1