diff --git a/payment/src/main/java/com/ning/billing/payment/core/PaymentMethodProcessor.java b/payment/src/main/java/com/ning/billing/payment/core/PaymentMethodProcessor.java
index a2d66b0..07b82d0 100644
--- a/payment/src/main/java/com/ning/billing/payment/core/PaymentMethodProcessor.java
+++ b/payment/src/main/java/com/ning/billing/payment/core/PaymentMethodProcessor.java
@@ -88,10 +88,7 @@ public class PaymentMethodProcessor extends ProcessorBase {
PaymentMethod pm = null;
PaymentPluginApi pluginApi = null;
try {
- pluginApi = pluginRegistry.getServiceForName(paymentPluginServiceName);
- if (pluginApi == null) {
- throw new PaymentApiException(ErrorCode.PAYMENT_NO_SUCH_PAYMENT_PLUGIN, paymentPluginServiceName);
- }
+ pluginApi = getPaymentPluginApi(paymentPluginServiceName);
pm = new DefaultPaymentMethod(account.getId(), paymentPluginServiceName, paymentMethodProps);
pluginApi.addPaymentMethod(account.getId(), pm.getId(), paymentMethodProps, setDefault, context.toCallContext());
final PaymentMethodModelDao pmModel = new PaymentMethodModelDao(pm.getId(), pm.getCreatedDate(), pm.getUpdatedDate(),
@@ -113,6 +110,14 @@ public class PaymentMethodProcessor extends ProcessorBase {
});
}
+ private PaymentPluginApi getPaymentPluginApi(final String pluginName) throws PaymentApiException {
+ final PaymentPluginApi pluginApi = pluginRegistry.getServiceForName(pluginName);
+ if (pluginApi == null) {
+ throw new PaymentApiException(ErrorCode.PAYMENT_NO_SUCH_PAYMENT_PLUGIN, pluginName);
+ }
+ return pluginApi;
+ }
+
public List<PaymentMethod> getPaymentMethods(final Account account, final boolean withPluginInfo, final InternalTenantContext context) throws PaymentApiException {
final List<PaymentMethodModelDao> paymentMethodModels = paymentDao.getPaymentMethods(account.getId(), context);
@@ -136,7 +141,7 @@ public class PaymentMethodProcessor extends ProcessorBase {
final PaymentMethodPlugin paymentMethodPlugin;
if (withPluginInfo) {
try {
- final PaymentPluginApi pluginApi = pluginRegistry.getServiceForName(paymentMethodModelDao.getPluginName());
+ final PaymentPluginApi pluginApi = getPaymentPluginApi(paymentMethodModelDao.getPluginName());
paymentMethodPlugin = pluginApi.getPaymentMethodDetail(paymentMethodModelDao.getAccountId(), paymentMethodModelDao.getId(), context.toTenantContext());
} catch (PaymentPluginApiException e) {
log.warn("Error retrieving payment method " + paymentMethodModelDao.getId() + " from plugin " + paymentMethodModelDao.getPluginName(), e);
@@ -168,7 +173,7 @@ public class PaymentMethodProcessor extends ProcessorBase {
addPaymentMethod(ExternalPaymentProviderPlugin.PLUGIN_NAME, account, false, props, context);
}
- return (ExternalPaymentProviderPlugin) pluginRegistry.getServiceForName(ExternalPaymentProviderPlugin.PLUGIN_NAME);
+ return (ExternalPaymentProviderPlugin) getPaymentPluginApi(ExternalPaymentProviderPlugin.PLUGIN_NAME);
}
private List<PaymentMethod> getPaymentMethodInternal(final List<PaymentMethodModelDao> paymentMethodModels, final boolean withPluginInfo, final InternalTenantContext context)
@@ -256,12 +261,12 @@ public class PaymentMethodProcessor extends ProcessorBase {
if (paymentMethod == null) {
throw new PaymentApiException(ErrorCode.PAYMENT_NO_SUCH_PAYMENT_METHOD, paymentMethodId);
}
- return pluginRegistry.getServiceForName(paymentMethod.getPluginName());
+ return getPaymentPluginApi(paymentMethod.getPluginName());
}
/**
* This refreshed the payment methods from the plugin for cases when adding payment method does not flow through KB because of PCI compliance
- * issues. The logic below is not optimal because there is no atomicity in the step but the goos news is that this is idempotent so can always be
+ * issues. The logic below is not optimal because there is no atomicity in the step but the good news is that this is idempotent so can always be
* replayed if necessary-- partial failure scenario.
*
* @param pluginName
@@ -274,7 +279,7 @@ public class PaymentMethodProcessor extends ProcessorBase {
// Don't hold the account lock while fetching the payment methods from the gateway as those could change anyway
- final PaymentPluginApi pluginApi = pluginRegistry.getServiceForName(pluginName);
+ final PaymentPluginApi pluginApi = getPaymentPluginApi(pluginName);
final List<PaymentMethodInfoPlugin> pluginPms;
try {
pluginPms = pluginApi.getPaymentMethods(account.getId(), true, context.toCallContext());