Details
diff --git a/payment/src/main/java/com/ning/billing/payment/api/DefaultPayment.java b/payment/src/main/java/com/ning/billing/payment/api/DefaultPayment.java
index b47865b..7b707e4 100644
--- a/payment/src/main/java/com/ning/billing/payment/api/DefaultPayment.java
+++ b/payment/src/main/java/com/ning/billing/payment/api/DefaultPayment.java
@@ -18,6 +18,7 @@ package com.ning.billing.payment.api;
import java.math.BigDecimal;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
@@ -47,18 +48,15 @@ public class DefaultPayment extends EntityBase implements Payment {
private final DateTime effectiveDate;
private final Integer paymentNumber;
private final PaymentStatus paymentStatus;
- private final String extFirstPaymentIdRef;
- private final String extSecondPaymentIdRef;
private final List<PaymentAttempt> attempts;
private final PaymentInfoPlugin paymentPluginInfo;
private DefaultPayment(final UUID id, @Nullable final DateTime createdDate, @Nullable final DateTime updatedDate, final UUID accountId, final UUID invoiceId,
final UUID paymentMethodId, final BigDecimal amount, final BigDecimal paidAmount, final Currency currency,
final DateTime effectiveDate, final Integer paymentNumber,
- final PaymentStatus paymentStatus, final String paymentError,
- final PaymentInfoPlugin paymentPluginInfo,
- final String extFirstPaymentIdRef,
- final String extSecondPaymentIdRef, final List<PaymentAttempt> attempts) {
+ final PaymentStatus paymentStatus,
+ @Nullable final PaymentInfoPlugin paymentPluginInfo,
+ final List<PaymentAttempt> attempts) {
super(id, createdDate, updatedDate);
this.accountId = accountId;
this.invoiceId = invoiceId;
@@ -69,13 +67,11 @@ public class DefaultPayment extends EntityBase implements Payment {
this.effectiveDate = effectiveDate;
this.paymentNumber = paymentNumber;
this.paymentStatus = paymentStatus;
- this.extFirstPaymentIdRef = extFirstPaymentIdRef;
- this.extSecondPaymentIdRef = extSecondPaymentIdRef;
this.attempts = attempts;
this.paymentPluginInfo = paymentPluginInfo;
}
- public DefaultPayment(final PaymentModelDao src, final PaymentInfoPlugin paymentPluginInfo, final List<PaymentAttemptModelDao> attempts, final List<RefundModelDao> refunds) {
+ public DefaultPayment(final PaymentModelDao src, @Nullable final PaymentInfoPlugin paymentPluginInfo, final List<PaymentAttemptModelDao> attempts, final List<RefundModelDao> refunds) {
this(src.getId(),
src.getCreatedDate(),
src.getUpdatedDate(),
@@ -88,10 +84,7 @@ public class DefaultPayment extends EntityBase implements Payment {
src.getEffectiveDate(),
src.getPaymentNumber(),
src.getPaymentStatus(),
- null,
paymentPluginInfo,
- src.getExtFirstPaymentRefId(),
- src.getExtSecondPaymentRefId(),
toPaymentAttempts(attempts));
}
@@ -150,14 +143,13 @@ public class DefaultPayment extends EntityBase implements Payment {
return attempts;
}
- private final static BigDecimal toPaidAmount(final PaymentStatus paymentStatus, final BigDecimal amount, final List<RefundModelDao> refunds) {
-
+ private static BigDecimal toPaidAmount(final PaymentStatus paymentStatus, final BigDecimal amount, final Iterable<RefundModelDao> refunds) {
if (paymentStatus != PaymentStatus.SUCCESS) {
return BigDecimal.ZERO;
}
BigDecimal result = amount;
- for (RefundModelDao cur : refunds) {
+ for (final RefundModelDao cur : refunds) {
if (cur.getRefundStatus() == RefundStatus.COMPLETED) {
result = result.subtract(cur.getAmount());
}
@@ -165,10 +157,11 @@ public class DefaultPayment extends EntityBase implements Payment {
return result;
}
- private static List<PaymentAttempt> toPaymentAttempts(final List<PaymentAttemptModelDao> attempts) {
- if (attempts == null || attempts.size() == 0) {
+ private static List<PaymentAttempt> toPaymentAttempts(final Collection<PaymentAttemptModelDao> attempts) {
+ if (attempts == null || attempts.isEmpty()) {
return Collections.emptyList();
}
+
return new ArrayList<PaymentAttempt>(Collections2.transform(attempts, new Function<PaymentAttemptModelDao, PaymentAttempt>() {
@Override
public PaymentAttempt apply(final PaymentAttemptModelDao input) {
diff --git a/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentMethod.java b/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentMethod.java
index 6de92ae..8c70cda 100644
--- a/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentMethod.java
+++ b/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentMethod.java
@@ -33,7 +33,7 @@ public class DefaultPaymentMethod extends EntityBase implements PaymentMethod {
private final PaymentMethodPlugin pluginDetail;
public DefaultPaymentMethod(final UUID paymentMethodId, @Nullable final DateTime createdDate, @Nullable final DateTime updatedDate,
- final UUID accountId, final Boolean isActive, final String pluginName, final PaymentMethodPlugin pluginDetail) {
+ final UUID accountId, final Boolean isActive, final String pluginName, @Nullable final PaymentMethodPlugin pluginDetail) {
super(paymentMethodId, createdDate, updatedDate);
this.accountId = accountId;
this.isActive = isActive;
@@ -49,7 +49,7 @@ public class DefaultPaymentMethod extends EntityBase implements PaymentMethod {
this(paymentMethodId, null, null, accountId, true, pluginName, null);
}
- public DefaultPaymentMethod(final PaymentMethodModelDao input, final PaymentMethodPlugin pluginDetail) {
+ public DefaultPaymentMethod(final PaymentMethodModelDao input, @Nullable final PaymentMethodPlugin pluginDetail) {
this(input.getId(), input.getCreatedDate(), input.getUpdatedDate(), input.getAccountId(), input.isActive(), input.getPluginName(), pluginDetail);
}
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 19f8e02..4117e03 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
@@ -20,7 +20,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
-import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
@@ -202,18 +201,16 @@ public class PaymentMethodProcessor extends ProcessorBase {
new Function<PaymentMethodModelDao, PaymentMethod>() {
@Override
public PaymentMethod apply(final PaymentMethodModelDao paymentMethodModelDao) {
- final PaymentMethodPlugin paymentMethodPlugin;
+ PaymentMethodPlugin paymentMethodPlugin = null;
try {
paymentMethodPlugin = pluginApi.getPaymentMethodDetail(paymentMethodModelDao.getAccountId(), paymentMethodModelDao.getId(), tenantContext);
+ if (paymentMethodPlugin.getKbPaymentMethodId() == null) {
+ // Garbage from the plugin?
+ log.debug("Plugin {} returned a payment method without a kbPaymentMethodId", pluginName);
+ paymentMethodPlugin = null;
+ }
} catch (PaymentPluginApiException e) {
log.warn("Unable to find payment method id " + paymentMethodModelDao.getId() + " in plugin " + pluginName);
- return null;
- }
-
- if (paymentMethodPlugin.getKbPaymentMethodId() == null) {
- // Garbage from the plugin?
- log.debug("Plugin {} returned a payment method without a kbPaymentMethodId", pluginName);
- return null;
}
return new DefaultPaymentMethod(paymentMethodModelDao, paymentMethodPlugin);
diff --git a/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java b/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java
index 3f36672..567a8ca 100644
--- a/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java
+++ b/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java
@@ -194,18 +194,16 @@ public class PaymentProcessor extends ProcessorBase {
new Function<PaymentModelDao, Payment>() {
@Override
public Payment apply(final PaymentModelDao paymentModelDao) {
- final PaymentInfoPlugin pluginInfo;
+ PaymentInfoPlugin pluginInfo = null;
try {
pluginInfo = pluginApi.getPaymentInfo(paymentModelDao.getAccountId(), paymentModelDao.getId(), tenantContext);
+ if (pluginInfo.getKbPaymentId() == null) {
+ // Garbage from the plugin?
+ log.debug("Plugin {} returned a payment without a kbPaymentId", pluginName);
+ pluginInfo = null;
+ }
} catch (final PaymentPluginApiException e) {
log.warn("Unable to find payment id " + paymentModelDao.getId() + " in plugin " + pluginName);
- return null;
- }
-
- if (pluginInfo.getKbPaymentId() == null) {
- // Garbage from the plugin?
- log.debug("Plugin {} returned a payment without a kbPaymentId", pluginName);
- return null;
}
return fromPaymentModelDao(paymentModelDao, pluginInfo, internalTenantContext);
@@ -301,7 +299,7 @@ public class PaymentProcessor extends ProcessorBase {
return result;
}
- private Payment fromPaymentModelDao(final PaymentModelDao input, final PaymentInfoPlugin pluginInfo, final InternalTenantContext context) {
+ private Payment fromPaymentModelDao(final PaymentModelDao input, @Nullable final PaymentInfoPlugin pluginInfo, final InternalTenantContext context) {
final List<PaymentAttemptModelDao> attempts = paymentDao.getAttemptsForPayment(input.getId(), context);
final List<RefundModelDao> refunds = paymentDao.getRefundsForPayment(input.getId(), context);
final Payment payment = new DefaultPayment(input, pluginInfo, attempts, refunds);
diff --git a/payment/src/main/resources/com/ning/billing/payment/dao/PaymentSqlDao.sql.stg b/payment/src/main/resources/com/ning/billing/payment/dao/PaymentSqlDao.sql.stg
index cc119e5..1d0ac63 100644
--- a/payment/src/main/resources/com/ning/billing/payment/dao/PaymentSqlDao.sql.stg
+++ b/payment/src/main/resources/com/ning/billing/payment/dao/PaymentSqlDao.sql.stg
@@ -110,7 +110,6 @@ select SQL_CALC_FOUND_ROWS
from <tableName()> t
join payment_methods pm on pm.id = t.payment_method_id
where pm.plugin_name = :pluginName
-and pm.is_active = 1
order by record_id
limit :offset, :rowCount
;