Details
diff --git a/api/src/main/java/com/ning/billing/payment/api/PaymentApi.java b/api/src/main/java/com/ning/billing/payment/api/PaymentApi.java
index 57c76a0..3b593fd 100644
--- a/api/src/main/java/com/ning/billing/payment/api/PaymentApi.java
+++ b/api/src/main/java/com/ning/billing/payment/api/PaymentApi.java
@@ -53,7 +53,7 @@ public interface PaymentApi {
List<PaymentInfo> getPaymentInfo(List<String> invoiceIds);
- PaymentAttempt getPaymentAttemptForInvoiceId(String invoiceId);
+ List<PaymentAttempt> getPaymentAttemptsForInvoiceId(String invoiceId);
PaymentInfo getPaymentInfoForPaymentAttemptId(String paymentAttemptId);
diff --git a/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentApi.java b/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentApi.java
index 63bc87e..e12d963 100644
--- a/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentApi.java
+++ b/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentApi.java
@@ -315,8 +315,8 @@ public class DefaultPaymentApi implements PaymentApi {
}
@Override
- public PaymentAttempt getPaymentAttemptForInvoiceId(String invoiceId) {
- return paymentDao.getPaymentAttemptForInvoiceId(invoiceId);
+ public List<PaymentAttempt> getPaymentAttemptsForInvoiceId(String invoiceId) {
+ return paymentDao.getPaymentAttemptsForInvoiceId(invoiceId);
}
@Override
diff --git a/payment/src/main/java/com/ning/billing/payment/dao/DefaultPaymentDao.java b/payment/src/main/java/com/ning/billing/payment/dao/DefaultPaymentDao.java
index 00cdb31..e090a94 100644
--- a/payment/src/main/java/com/ning/billing/payment/dao/DefaultPaymentDao.java
+++ b/payment/src/main/java/com/ning/billing/payment/dao/DefaultPaymentDao.java
@@ -44,8 +44,8 @@ public class DefaultPaymentDao implements PaymentDao {
}
@Override
- public PaymentAttempt getPaymentAttemptForInvoiceId(String invoiceId) {
- return sqlDao.getPaymentAttemptForInvoiceId(invoiceId);
+ public List<PaymentAttempt> getPaymentAttemptsForInvoiceId(String invoiceId) {
+ return sqlDao.getPaymentAttemptsForInvoiceId(invoiceId);
}
@Override
diff --git a/payment/src/main/java/com/ning/billing/payment/dao/PaymentDao.java b/payment/src/main/java/com/ning/billing/payment/dao/PaymentDao.java
index 2c9ee06..2184841 100644
--- a/payment/src/main/java/com/ning/billing/payment/dao/PaymentDao.java
+++ b/payment/src/main/java/com/ning/billing/payment/dao/PaymentDao.java
@@ -35,7 +35,7 @@ public interface PaymentDao {
void updatePaymentAttemptWithPaymentId(UUID paymentAttemptId, String paymentId);
- PaymentAttempt getPaymentAttemptForInvoiceId(String invoiceId);
+ List<PaymentAttempt> getPaymentAttemptsForInvoiceId(String invoiceId);
void updatePaymentInfo(String paymentMethodType, String paymentId, String cardType, String cardCountry);
diff --git a/payment/src/main/java/com/ning/billing/payment/dao/PaymentSqlDao.java b/payment/src/main/java/com/ning/billing/payment/dao/PaymentSqlDao.java
index 69117fb..6a53978 100644
--- a/payment/src/main/java/com/ning/billing/payment/dao/PaymentSqlDao.java
+++ b/payment/src/main/java/com/ning/billing/payment/dao/PaymentSqlDao.java
@@ -59,7 +59,7 @@ public interface PaymentSqlDao extends Transactional<PaymentSqlDao>, CloseMe, Tr
@SqlQuery
@Mapper(PaymentAttemptMapper.class)
- PaymentAttempt getPaymentAttemptForInvoiceId(@Bind("invoice_id") String invoiceId);
+ List<PaymentAttempt> getPaymentAttemptsForInvoiceId(@Bind("invoice_id") String invoiceId);
@SqlQuery
@Mapper(PaymentAttemptMapper.class)
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 91eeb22..55c3efa 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
@@ -55,7 +55,7 @@ getPaymentAttemptsForInvoiceIds(invoiceIds) ::= <<
WHERE invoice_id in (<invoiceIds>)
>>
-getPaymentAttemptForInvoiceId() ::= <<
+getPaymentAttemptsForInvoiceId() ::= <<
SELECT <paymentAttemptFields()>
FROM payment_attempts
WHERE invoice_id = :invoice_id
diff --git a/payment/src/test/java/com/ning/billing/payment/api/TestPaymentApi.java b/payment/src/test/java/com/ning/billing/payment/api/TestPaymentApi.java
index 0fda201..03f4428 100644
--- a/payment/src/test/java/com/ning/billing/payment/api/TestPaymentApi.java
+++ b/payment/src/test/java/com/ning/billing/payment/api/TestPaymentApi.java
@@ -26,7 +26,6 @@ import java.util.Arrays;
import java.util.List;
import java.util.UUID;
-import com.ning.billing.util.entity.EntityPersistenceException;
import org.apache.commons.lang.RandomStringUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
@@ -44,6 +43,7 @@ import com.ning.billing.invoice.model.RecurringInvoiceItem;
import com.ning.billing.payment.TestHelper;
import com.ning.billing.util.bus.Bus;
import com.ning.billing.util.bus.Bus.EventBusException;
+import com.ning.billing.util.entity.EntityPersistenceException;
public abstract class TestPaymentApi {
@Inject
@@ -119,8 +119,8 @@ public abstract class TestPaymentApi {
assertEquals(paymentInfo.getPaymentMethodId(), paymentInfoFromGet.getPaymentMethodId());
assertEquals(paymentInfo.getEffectiveDate(), paymentInfoFromGet.getEffectiveDate());
- PaymentAttempt paymentAttemptFromGet = paymentApi.getPaymentAttemptForInvoiceId(invoice.getId().toString());
- assertEquals(paymentAttempt, paymentAttemptFromGet);
+ List<PaymentAttempt> paymentAttemptsFromGet = paymentApi.getPaymentAttemptsForInvoiceId(invoice.getId().toString());
+ assertEquals(paymentAttempt, paymentAttemptsFromGet.get(0));
}
diff --git a/payment/src/test/java/com/ning/billing/payment/dao/MockPaymentDao.java b/payment/src/test/java/com/ning/billing/payment/dao/MockPaymentDao.java
index b4bfb51..c1ba1db 100644
--- a/payment/src/test/java/com/ning/billing/payment/dao/MockPaymentDao.java
+++ b/payment/src/test/java/com/ning/billing/payment/dao/MockPaymentDao.java
@@ -17,11 +17,13 @@
package com.ning.billing.payment.dao;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
+import org.apache.commons.collections.CollectionUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
@@ -74,13 +76,14 @@ public class MockPaymentDao implements PaymentDao {
}
@Override
- public PaymentAttempt getPaymentAttemptForInvoiceId(String invoiceId) {
- for (PaymentAttempt paymentAttempt : paymentAttempts.values()) {
- if (invoiceId.equals(paymentAttempt.getInvoiceId().toString())) {
- return paymentAttempt;
- }
- }
- return null;
+ public List<PaymentAttempt> getPaymentAttemptsForInvoiceId(final String invoiceId) {
+ Collection<PaymentAttempt> attempts = Collections2.filter(paymentAttempts.values(), new Predicate<PaymentAttempt>() {
+ @Override
+ public boolean apply(PaymentAttempt input) {
+ return invoiceId.equals(input.getInvoiceId().toString());
+ }
+ });
+ return new ArrayList<PaymentAttempt>(attempts);
}
@Override
@@ -118,9 +121,9 @@ public class MockPaymentDao implements PaymentDao {
public List<PaymentAttempt> getPaymentAttemptsForInvoiceIds(List<String> invoiceIds) {
List<PaymentAttempt> paymentAttempts = new ArrayList<PaymentAttempt>(invoiceIds.size());
for (String invoiceId : invoiceIds) {
- PaymentAttempt attempt = getPaymentAttemptForInvoiceId(invoiceId);
- if (attempt != null) {
- paymentAttempts.add(attempt);
+ List<PaymentAttempt> attempts = getPaymentAttemptsForInvoiceId(invoiceId);
+ if (CollectionUtils.isNotEmpty(attempts)) {
+ paymentAttempts.addAll(attempts);
}
}
return paymentAttempts;
diff --git a/payment/src/test/java/com/ning/billing/payment/dao/TestPaymentDao.java b/payment/src/test/java/com/ning/billing/payment/dao/TestPaymentDao.java
index 70708eb..a97786d 100644
--- a/payment/src/test/java/com/ning/billing/payment/dao/TestPaymentDao.java
+++ b/payment/src/test/java/com/ning/billing/payment/dao/TestPaymentDao.java
@@ -18,6 +18,7 @@ package com.ning.billing.payment.dao;
import java.math.BigDecimal;
import java.util.Arrays;
+import java.util.List;
import java.util.UUID;
import org.joda.time.DateTime;
@@ -103,9 +104,9 @@ public abstract class TestPaymentDao {
PaymentAttempt attempt = paymentDao.createPaymentAttempt(originalPaymenAttempt);
- PaymentAttempt attempt2 = paymentDao.getPaymentAttemptForInvoiceId(invoiceId.toString());
+ List<PaymentAttempt> attemptsFromGet = paymentDao.getPaymentAttemptsForInvoiceId(invoiceId.toString());
- Assert.assertEquals(attempt, attempt2);
+ Assert.assertEquals(attempt, attemptsFromGet.get(0));
PaymentAttempt attempt3 = paymentDao.getPaymentAttemptsForInvoiceIds(Arrays.asList(invoiceId.toString())).get(0);
diff --git a/payment/src/test/java/com/ning/billing/payment/TestRetryService.java b/payment/src/test/java/com/ning/billing/payment/TestRetryService.java
index ac33d99..fe1d5e0 100644
--- a/payment/src/test/java/com/ning/billing/payment/TestRetryService.java
+++ b/payment/src/test/java/com/ning/billing/payment/TestRetryService.java
@@ -25,11 +25,8 @@ import java.util.Arrays;
import java.util.List;
import java.util.UUID;
-import com.ning.billing.util.clock.Clock;
-import com.ning.billing.util.clock.ClockMock;
import org.joda.time.DateTime;
import org.joda.time.Days;
-import org.joda.time.Months;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
@@ -55,6 +52,8 @@ import com.ning.billing.payment.provider.PaymentProviderPluginRegistry;
import com.ning.billing.payment.setup.PaymentConfig;
import com.ning.billing.payment.setup.PaymentTestModuleWithMocks;
import com.ning.billing.util.bus.Bus;
+import com.ning.billing.util.clock.Clock;
+import com.ning.billing.util.clock.ClockMock;
import com.ning.billing.util.notificationq.MockNotificationQueue;
import com.ning.billing.util.notificationq.Notification;
import com.ning.billing.util.notificationq.NotificationQueueService;
@@ -136,12 +135,12 @@ public class TestRetryService {
assertEquals(pendingNotifications.size(), 1);
Notification notification = pendingNotifications.get(0);
- PaymentAttempt paymentAttempt = paymentApi.getPaymentAttemptForInvoiceId(invoice.getId().toString());
+ List<PaymentAttempt> paymentAttempts = paymentApi.getPaymentAttemptsForInvoiceId(invoice.getId().toString());
- assertNotNull(paymentAttempt);
- assertEquals(notification.getNotificationKey(), paymentAttempt.getPaymentAttemptId().toString());
+ assertNotNull(paymentAttempts);
+ assertEquals(notification.getNotificationKey(), paymentAttempts.get(0).getPaymentAttemptId().toString());
- DateTime expectedRetryDate = paymentAttempt.getPaymentAttemptDate().plusDays(paymentConfig.getPaymentRetryDays().get(0));
+ DateTime expectedRetryDate = paymentAttempts.get(0).getPaymentAttemptDate().plusDays(paymentConfig.getPaymentRetryDays().get(0));
assertEquals(notification.getEffectiveDate(), expectedRetryDate);
}
@@ -186,8 +185,8 @@ public class TestRetryService {
PaymentInfo paymentInfo = paymentInfos.get(0);
assertEquals(paymentInfo.getStatus(), PaymentStatus.Processed.toString());
- PaymentAttempt updatedAttempt = paymentApi.getPaymentAttemptForInvoiceId(invoice.getId().toString());
- assertEquals(paymentInfo.getPaymentId(), updatedAttempt.getPaymentId());
+ List<PaymentAttempt> updatedAttempts = paymentApi.getPaymentAttemptsForInvoiceId(invoice.getId().toString());
+ assertEquals(paymentInfo.getPaymentId(), updatedAttempts.get(0).getPaymentId());
}
}