killbill-memoizeit

analytics: handle deleted payment methods in the gateway Signed-off-by:

4/18/2013 8:27:13 PM

Details

diff --git a/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/BusinessAnalyticsBase.java b/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/BusinessAnalyticsBase.java
index 5d5589f..72cd3e0 100644
--- a/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/BusinessAnalyticsBase.java
+++ b/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/BusinessAnalyticsBase.java
@@ -420,9 +420,18 @@ public abstract class BusinessAnalyticsBase {
         final PaymentApi paymentApi = getPaymentUserApi();
 
         try {
+            // Try to get all payment methods, including deleted ones, with plugin information
             return paymentApi.getPaymentMethodById(paymentMethodId, true, true, context);
         } catch (PaymentApiException e) {
             logService.log(LogService.LOG_INFO, "Error retrieving payment method for id " + paymentMethodId + " (already deleted?)", e);
+        }
+
+        try {
+            // If we come here, it is possible that the plugin couldn't answer about the payment method, maybe
+            // because it was deleted in the gateway. Try to return the Kill Bill specific info only
+            return paymentApi.getPaymentMethodById(paymentMethodId, true, false, context);
+        } catch (PaymentApiException e) {
+            logService.log(LogService.LOG_INFO, "Error retrieving payment method for id " + paymentMethodId, e);
             return null;
         }
     }