killbill-memoizeit
Changes
osgi-bundles/bundles/jruby/src/main/java/com/ning/billing/osgi/bundles/jruby/JRubyPaymentPlugin.java 2(+1 -1)
osgi-bundles/tests/beatrix/src/test/java/com/ning/billing/osgi/bundles/test/TestPaymentPluginApi.java 2(+1 -1)
osgi-bundles/tests/payment/src/test/java/com/ning/billing/osgi/bundles/test/TestPaymentPluginApi.java 2(+1 -1)
Details
diff --git a/api/src/main/java/com/ning/billing/payment/api/Payment.java b/api/src/main/java/com/ning/billing/payment/api/Payment.java
index 2c31f46..6801101 100644
--- a/api/src/main/java/com/ning/billing/payment/api/Payment.java
+++ b/api/src/main/java/com/ning/billing/payment/api/Payment.java
@@ -27,44 +27,119 @@ import com.ning.billing.util.entity.Entity;
public interface Payment extends Entity {
- public UUID getAccountId();
-
- public UUID getInvoiceId();
-
- public UUID getPaymentMethodId();
-
- public Integer getPaymentNumber();
-
- public BigDecimal getAmount();
-
- public BigDecimal getPaidAmount();
-
- public DateTime getEffectiveDate();
-
- public Currency getCurrency();
-
- public PaymentStatus getPaymentStatus();
-
- public List<PaymentAttempt> getAttempts();
-
- public String getExtFirstPaymentIdRef();
-
- public String getExtSecondPaymentIdRef();
-
- public PaymentInfoPlugin getPaymentInfoPlugin();
-
+ /**
+ *
+ * @return the account id
+ */
+ UUID getAccountId();
+
+ /**
+ *
+ * @return the invoice id
+ */
+ UUID getInvoiceId();
+
+ /**
+ *
+ * @return the payment method id
+ */
+ UUID getPaymentMethodId();
+
+ /**
+ *
+ * @return the payment number
+ */
+ Integer getPaymentNumber();
+
+ /**
+ *
+ * @return the amount that needs to be paid
+ */
+ BigDecimal getAmount();
+
+ /**
+ *
+ * @return the paid amount
+ */
+ BigDecimal getPaidAmount();
+
+ /**
+ * If the payment is successful, this date is the date of payment, otherwise this is the date of the last attempt
+ *
+ * @return the effective date of the payment
+ */
+ DateTime getEffectiveDate();
+
+ /**
+ *
+ * @return the currency associated with that payment
+ */
+ Currency getCurrency();
+
+ /**
+ *
+ * @return the payment status
+ */
+ PaymentStatus getPaymentStatus();
+
+ /**
+ *
+ * @return the list of attempts on that payment
+ */
+ List<PaymentAttempt> getAttempts();
+
+ /**
+ *
+ * @return the first payment ref id from the plugin
+ */
+ @Deprecated
+ String getExtFirstPaymentIdRef();
+
+ /**
+ *
+ * @return the second payment ref id from the plugin
+ */
+ @Deprecated
+ String getExtSecondPaymentIdRef();
+
+ /**
+ * This will only be filled when the call requires the detail from the plugin
+ *
+ * @return the addtional info from the plugin
+ */
+ PaymentInfoPlugin getPaymentInfoPlugin();
+
+
public interface PaymentAttempt extends Entity {
- public UUID getId();
-
- public DateTime getEffectiveDate();
-
- public String getGatewayErrorCode();
-
- public String getGatewayErrorMsg();
-
- public PaymentStatus getPaymentStatus();
+ /**
+ *
+ * @return the payment attempt id
+ */
+ UUID getId();
+
+ /**
+ *
+ * @return the date when that attempt was made
+ */
+ DateTime getEffectiveDate();
+
+ /**
+ *
+ * @return the error code from the gateway
+ */
+ String getGatewayErrorCode();
+
+ /**
+ *
+ * @return the error message from the gateway
+ */
+ String getGatewayErrorMsg();
+
+ /**
+ *
+ * @return the status for that attempt
+ */
+ PaymentStatus getPaymentStatus();
}
-
-
}
diff --git a/api/src/main/java/com/ning/billing/payment/plugin/api/PaymentPluginApi.java b/api/src/main/java/com/ning/billing/payment/plugin/api/PaymentPluginApi.java
index 935c8ed..9ac1f20 100644
--- a/api/src/main/java/com/ning/billing/payment/plugin/api/PaymentPluginApi.java
+++ b/api/src/main/java/com/ning/billing/payment/plugin/api/PaymentPluginApi.java
@@ -77,7 +77,7 @@ public interface PaymentPluginApi {
* @return information about the refunds in the gateway
* @throws PaymentPluginApiException
*/
- public List<RefundInfoPlugin> getRefundInfo(UUID kbAccountId, UUID kbPaymentId, CallContext context)
+ public List<RefundInfoPlugin> getRefundInfo(UUID kbAccountId, UUID kbPaymentId, TenantContext context)
throws PaymentPluginApiException;
diff --git a/osgi-bundles/bundles/jruby/src/main/java/com/ning/billing/osgi/bundles/jruby/JRubyPaymentPlugin.java b/osgi-bundles/bundles/jruby/src/main/java/com/ning/billing/osgi/bundles/jruby/JRubyPaymentPlugin.java
index 37e8f37..99ab86b 100644
--- a/osgi-bundles/bundles/jruby/src/main/java/com/ning/billing/osgi/bundles/jruby/JRubyPaymentPlugin.java
+++ b/osgi-bundles/bundles/jruby/src/main/java/com/ning/billing/osgi/bundles/jruby/JRubyPaymentPlugin.java
@@ -104,7 +104,7 @@ public class JRubyPaymentPlugin extends JRubyPlugin implements PaymentPluginApi
}
@Override
- public List<RefundInfoPlugin> getRefundInfo(final UUID kbAccountId, final UUID kbPaymentId, final CallContext context) throws PaymentPluginApiException {
+ public List<RefundInfoPlugin> getRefundInfo(final UUID kbAccountId, final UUID kbPaymentId, final TenantContext context) throws PaymentPluginApiException {
return callWithRuntimeAndChecking(new PluginCallback() {
@Override
public List<RefundInfoPlugin> doCall(final Ruby runtime) throws PaymentPluginApiException {
diff --git a/osgi-bundles/tests/beatrix/src/test/java/com/ning/billing/osgi/bundles/test/TestPaymentPluginApi.java b/osgi-bundles/tests/beatrix/src/test/java/com/ning/billing/osgi/bundles/test/TestPaymentPluginApi.java
index 7ca9201..b010a8b 100644
--- a/osgi-bundles/tests/beatrix/src/test/java/com/ning/billing/osgi/bundles/test/TestPaymentPluginApi.java
+++ b/osgi-bundles/tests/beatrix/src/test/java/com/ning/billing/osgi/bundles/test/TestPaymentPluginApi.java
@@ -96,7 +96,7 @@ public class TestPaymentPluginApi implements PaymentPluginApi {
}
@Override
- public List<RefundInfoPlugin> getRefundInfo(final UUID kbAccountId, final UUID kbPaymentId, final CallContext context) {
+ public List<RefundInfoPlugin> getRefundInfo(final UUID kbAccountId, final UUID kbPaymentId, final TenantContext context) {
return Collections.<RefundInfoPlugin>emptyList();
}
diff --git a/osgi-bundles/tests/payment/src/test/java/com/ning/billing/osgi/bundles/test/TestPaymentPluginApi.java b/osgi-bundles/tests/payment/src/test/java/com/ning/billing/osgi/bundles/test/TestPaymentPluginApi.java
index 66959e9..5cbf7e1 100644
--- a/osgi-bundles/tests/payment/src/test/java/com/ning/billing/osgi/bundles/test/TestPaymentPluginApi.java
+++ b/osgi-bundles/tests/payment/src/test/java/com/ning/billing/osgi/bundles/test/TestPaymentPluginApi.java
@@ -165,7 +165,7 @@ public class TestPaymentPluginApi implements PaymentPluginApiWithTestControl {
}
@Override
- public List<RefundInfoPlugin> getRefundInfo(final UUID kbAccountId, final UUID kbPaymentId, final CallContext context) {
+ public List<RefundInfoPlugin> getRefundInfo(final UUID kbAccountId, final UUID kbPaymentId, final TenantContext context) {
return Collections.<RefundInfoPlugin>emptyList();
}
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 7e2663f..dc45727 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
@@ -428,7 +428,7 @@ public class PaymentProcessor extends ProcessorBase {
List<PaymentAttemptModelDao> allAttempts = null;
if (paymentConfig.isPaymentOff()) {
- paymentDao.updateStatusForPaymentWithAttempt(paymentInput.getId(), PaymentStatus.PAYMENT_SYSTEM_OFF, null, null, attemptInput.getId(), context);
+ paymentDao.updateStatusAndEffectiveDateForPaymentWithAttempt(paymentInput.getId(), PaymentStatus.PAYMENT_SYSTEM_OFF, clock.getUTCNow(), attemptInput.getId(), null, null, context);
allAttempts = paymentDao.getAttemptsForPayment(paymentInput.getId(), context);
return new DefaultPayment(paymentInput, null, allAttempts, Collections.<RefundModelDao>emptyList());
}
@@ -444,7 +444,13 @@ public class PaymentProcessor extends ProcessorBase {
case PROCESSED:
// Update Payment/PaymentAttempt status
paymentStatus = PaymentStatus.SUCCESS;
- paymentDao.updateStatusForPaymentWithAttempt(paymentInput.getId(), paymentStatus, paymentPluginInfo.getGatewayErrorCode(), null, attemptInput.getId(), context);
+
+ /*
+ UUID paymentId, PaymentStatus paymentStatus, DateTime newEffectiveDate,
+ String gatewayErrorMsg, UUID attemptId, InternalCallContext context, String gatewayErrorCode
+ */
+
+ paymentDao.updateStatusAndEffectiveDateForPaymentWithAttempt(paymentInput.getId(), paymentStatus, clock.getUTCNow(), attemptInput.getId(), paymentPluginInfo.getGatewayErrorCode(), null, context);
// Fetch latest objects
allAttempts = paymentDao.getAttemptsForPayment(paymentInput.getId(), context);
@@ -473,7 +479,7 @@ public class PaymentProcessor extends ProcessorBase {
paymentStatus = PaymentStatus.PAYMENT_FAILURE_ABORTED;
}
- paymentDao.updateStatusForPaymentWithAttempt(paymentInput.getId(), paymentStatus, paymentPluginInfo.getGatewayErrorCode(), paymentPluginInfo.getGatewayError(), attemptInput.getId(), context);
+ paymentDao.updateStatusAndEffectiveDateForPaymentWithAttempt(paymentInput.getId(), paymentStatus, clock.getUTCNow(), attemptInput.getId(), paymentPluginInfo.getGatewayErrorCode(), paymentPluginInfo.getGatewayError(), context);
log.info(String.format("Could not process payment for account %s, invoice %s, error = %s",
account.getId(), invoice.getId(), paymentPluginInfo.getGatewayError()));
@@ -495,7 +501,7 @@ public class PaymentProcessor extends ProcessorBase {
paymentStatus = isInstantPayment ? PaymentStatus.PAYMENT_FAILURE_ABORTED : scheduleRetryOnPluginFailure(paymentInput.getId(), context);
// STEPH message might need truncation to fit??
- paymentDao.updateStatusForPaymentWithAttempt(paymentInput.getId(), paymentStatus, null, e.getMessage(), attemptInput.getId(), context);
+ paymentDao.updateStatusAndEffectiveDateForPaymentWithAttempt(paymentInput.getId(), paymentStatus, clock.getUTCNow(), attemptInput.getId(), null, e.getMessage(), context);
throw new PaymentApiException(ErrorCode.PAYMENT_CREATE_PAYMENT, account.getId(), e.toString());
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 7e81ac1..05fbfa6 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
@@ -23,6 +23,7 @@ import java.util.UUID;
import javax.inject.Inject;
+import org.joda.time.DateTime;
import org.skife.jdbi.v2.IDBI;
import com.ning.billing.payment.api.PaymentStatus;
@@ -92,17 +93,18 @@ public class DefaultPaymentDao implements PaymentDao {
}
@Override
- public void updateStatusForPaymentWithAttempt(final UUID paymentId,
- final PaymentStatus paymentStatus,
- final String gatewayErrorCode,
- final String gatewayErrorMsg,
- final UUID attemptId,
- final InternalCallContext context) {
+ public void updateStatusAndEffectiveDateForPaymentWithAttempt(final UUID paymentId,
+ final PaymentStatus paymentStatus,
+ final DateTime newEffectiveDate,
+ final UUID attemptId,
+ final String gatewayErrorCode,
+ final String gatewayErrorMsg,
+ final InternalCallContext context) {
transactionalSqlDao.execute(new EntitySqlDaoTransactionWrapper<Void>() {
@Override
public Void inTransaction(final EntitySqlDaoWrapperFactory<EntitySqlDao> entitySqlDaoWrapperFactory) throws Exception {
- entitySqlDaoWrapperFactory.become(PaymentSqlDao.class).updatePaymentStatus(paymentId.toString(), paymentStatus.toString(), context);
+ entitySqlDaoWrapperFactory.become(PaymentSqlDao.class).updatePaymentStatus(paymentId.toString(), paymentStatus.toString(), newEffectiveDate.toDate(), context);
entitySqlDaoWrapperFactory.become(PaymentAttemptSqlDao.class).updatePaymentAttemptStatus(attemptId.toString(), paymentStatus.toString(), gatewayErrorCode, gatewayErrorMsg, context);
return null;
}
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 a5eaef5..304a03f 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
@@ -19,6 +19,8 @@ package com.ning.billing.payment.dao;
import java.util.List;
import java.util.UUID;
+import org.joda.time.DateTime;
+
import com.ning.billing.payment.api.PaymentStatus;
import com.ning.billing.payment.dao.RefundModelDao.RefundStatus;
import com.ning.billing.util.callcontext.InternalCallContext;
@@ -31,9 +33,8 @@ public interface PaymentDao {
public PaymentAttemptModelDao insertNewAttemptForPayment(UUID paymentId, PaymentAttemptModelDao attempt, InternalCallContext context);
- public void updateStatusForPaymentWithAttempt(UUID paymentId, PaymentStatus paymentStatus, String gatewayErrorCode,
- String gatewayErrorMsg,
- UUID attemptId, InternalCallContext context);
+ public void updateStatusAndEffectiveDateForPaymentWithAttempt(UUID paymentId, PaymentStatus paymentStatus, DateTime newEffectiveDate,
+ UUID attemptId, String gatewayErrorMsg, String gatewayErrorCode, InternalCallContext context);
public PaymentAttemptModelDao getPaymentAttempt(UUID attemptId, InternalTenantContext context);
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 5b289ea..2033bc6 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
@@ -17,6 +17,7 @@
package com.ning.billing.payment.dao;
import java.math.BigDecimal;
+import java.util.Date;
import java.util.List;
import org.skife.jdbi.v2.sqlobject.Bind;
@@ -39,6 +40,7 @@ public interface PaymentSqlDao extends EntitySqlDao<PaymentModelDao, Payment> {
@Audited(ChangeType.UPDATE)
void updatePaymentStatus(@Bind("id") final String paymentId,
@Bind("paymentStatus") final String paymentStatus,
+ @Bind("effectiveDate") final Date effectiveDate,
@BindBean final InternalCallContext context);
@SqlUpdate
diff --git a/payment/src/main/java/com/ning/billing/payment/provider/DefaultNoOpPaymentProviderPlugin.java b/payment/src/main/java/com/ning/billing/payment/provider/DefaultNoOpPaymentProviderPlugin.java
index f31b1fd..51fa4b2 100644
--- a/payment/src/main/java/com/ning/billing/payment/provider/DefaultNoOpPaymentProviderPlugin.java
+++ b/payment/src/main/java/com/ning/billing/payment/provider/DefaultNoOpPaymentProviderPlugin.java
@@ -181,7 +181,7 @@ public class DefaultNoOpPaymentProviderPlugin implements NoOpPaymentPluginApi {
}
@Override
- public List<RefundInfoPlugin> getRefundInfo(final UUID kbAccountId, final UUID kbPaymentId, final CallContext context) {
+ public List<RefundInfoPlugin> getRefundInfo(final UUID kbAccountId, final UUID kbPaymentId, final TenantContext context) {
return ImmutableList.<RefundInfoPlugin>copyOf(refunds.get(kbPaymentId.toString()));
}
}
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 15c9203..b7bc670 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
@@ -71,7 +71,8 @@ order by effective_date desc limit 1
updatePaymentStatus() ::= <<
update payments
-set payment_status = :paymentStatus
+set payment_status = :paymentStatus,
+effective_date = :effectiveDate
where id = :id
<AND_CHECK_TENANT()>
;
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 7a51f36..8eba46f 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
@@ -25,6 +25,8 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
+import org.joda.time.DateTime;
+
import com.ning.billing.payment.api.PaymentStatus;
import com.ning.billing.payment.dao.RefundModelDao.RefundStatus;
import com.ning.billing.util.callcontext.InternalCallContext;
@@ -56,9 +58,9 @@ public class MockPaymentDao implements PaymentDao {
}
@Override
- public void updateStatusForPaymentWithAttempt(final UUID paymentId, final PaymentStatus paymentStatus, final String gatewayErrorCode,
- final String gatewayErrorMsg,
- final UUID attemptId, final InternalCallContext context) {
+ public void updateStatusAndEffectiveDateForPaymentWithAttempt(final UUID paymentId, final PaymentStatus paymentStatus, final DateTime effectibeDate, final UUID attemptId, final String gatewayErrorCode,
+ final String gatewayErrorMsg,
+ final InternalCallContext context) {
synchronized (this) {
final PaymentModelDao entry = payments.remove(paymentId);
if (entry != null) {
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 a17fcac..0557324 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
@@ -25,6 +25,7 @@ import org.joda.time.DateTime;
import org.testng.annotations.Test;
import com.ning.billing.catalog.api.Currency;
+import com.ning.billing.catalog.api.Duration;
import com.ning.billing.payment.PaymentTestSuiteWithEmbeddedDB;
import com.ning.billing.payment.api.PaymentStatus;
import com.ning.billing.payment.dao.RefundModelDao.RefundStatus;
@@ -95,11 +96,14 @@ public class TestPaymentDao extends PaymentTestSuiteWithEmbeddedDB {
final PaymentModelDao payment = new PaymentModelDao(accountId, invoiceId, paymentMethodId, amount, currency, effectiveDate);
final PaymentAttemptModelDao attempt = new PaymentAttemptModelDao(accountId, invoiceId, payment.getId(), clock.getUTCNow(), amount);
PaymentModelDao savedPayment = paymentDao.insertPaymentWithAttempt(payment, attempt, internalCallContext);
+ assertEquals(savedPayment.getEffectiveDate().compareTo(effectiveDate), 0);
final PaymentStatus paymentStatus = PaymentStatus.SUCCESS;
final String gatewayErrorCode = "OK";
- paymentDao.updateStatusForPaymentWithAttempt(payment.getId(), paymentStatus, gatewayErrorCode, null, attempt.getId(), internalCallContext);
+ clock.addDays(1);
+ final DateTime newEffectiveDate = clock.getUTCNow();
+ paymentDao.updateStatusAndEffectiveDateForPaymentWithAttempt(payment.getId(), paymentStatus, newEffectiveDate, attempt.getId(), gatewayErrorCode, null, internalCallContext);
final List<PaymentModelDao> payments = paymentDao.getPaymentsForInvoice(invoiceId, internalCallContext);
assertEquals(payments.size(), 1);
@@ -110,7 +114,7 @@ public class TestPaymentDao extends PaymentTestSuiteWithEmbeddedDB {
assertEquals(savedPayment.getPaymentMethodId(), paymentMethodId);
assertEquals(savedPayment.getAmount().compareTo(amount), 0);
assertEquals(savedPayment.getCurrency(), currency);
- assertEquals(savedPayment.getEffectiveDate().compareTo(effectiveDate), 0);
+ assertEquals(savedPayment.getEffectiveDate().compareTo(newEffectiveDate), 0);
assertEquals(savedPayment.getPaymentStatus(), PaymentStatus.SUCCESS);
final List<PaymentAttemptModelDao> attempts = paymentDao.getAttemptsForPayment(payment.getId(), internalCallContext);
diff --git a/payment/src/test/java/com/ning/billing/payment/provider/MockPaymentProviderPlugin.java b/payment/src/test/java/com/ning/billing/payment/provider/MockPaymentProviderPlugin.java
index 6aebbd2..64f8a47 100644
--- a/payment/src/test/java/com/ning/billing/payment/provider/MockPaymentProviderPlugin.java
+++ b/payment/src/test/java/com/ning/billing/payment/provider/MockPaymentProviderPlugin.java
@@ -176,7 +176,7 @@ public class MockPaymentProviderPlugin implements NoOpPaymentPluginApi {
}
@Override
- public List<RefundInfoPlugin> getRefundInfo(final UUID kbAccountId, final UUID kbPaymentId, final CallContext context) throws PaymentPluginApiException {
+ public List<RefundInfoPlugin> getRefundInfo(final UUID kbAccountId, final UUID kbPaymentId, final TenantContext context) throws PaymentPluginApiException {
return Collections.<RefundInfoPlugin>emptyList();
}
}