killbill-aplcache

Details

diff --git a/api/src/main/java/com/ning/billing/payment/api/PaymentInfo.java b/api/src/main/java/com/ning/billing/payment/api/PaymentInfo.java
index 9cfa71f..409ee7f 100644
--- a/api/src/main/java/com/ning/billing/payment/api/PaymentInfo.java
+++ b/api/src/main/java/com/ning/billing/payment/api/PaymentInfo.java
@@ -34,24 +34,14 @@ public class PaymentInfo implements EventBusNotification {
     private final String status;
     private final String type;
     private final String referenceId;
+    private final String paymentMethodId;
+    private final String paymentMethod;
+    private final String creditCardType;
+    private final String creditCardCountry;
     private final DateTime effectiveDate;
     private final DateTime createdDate;
     private final DateTime updatedDate;
 
-    public PaymentInfo(PaymentInfo src) {
-        this.paymentId = src.paymentId;
-        this.amount = src.amount;
-        this.refundAmount = src.refundAmount;
-        this.paymentNumber = src.paymentNumber;
-        this.bankIdentificationNumber = src.bankIdentificationNumber;
-        this.status = src.status;
-        this.type = src.type;
-        this.referenceId = src.referenceId;
-        this.effectiveDate = src.effectiveDate;
-        this.createdDate = src.createdDate;
-        this.updatedDate = src.updatedDate;
-    }
-
     @JsonCreator
     public PaymentInfo(@JsonProperty("paymentId") String paymentId,
                        @JsonProperty("amount") BigDecimal amount,
@@ -61,6 +51,10 @@ public class PaymentInfo implements EventBusNotification {
                        @JsonProperty("status") String status,
                        @JsonProperty("type") String type,
                        @JsonProperty("referenceId") String referenceId,
+                       @JsonProperty("paymentMethodId") String paymentMethodId,
+                       @JsonProperty("paymentMethod") String paymentMethod,
+                       @JsonProperty("creditCardType") String creditCardType,
+                       @JsonProperty("creditCardCountry") String creditCardCountry,
                        @JsonProperty("effectiveDate") DateTime effectiveDate,
                        @JsonProperty("createdDate") DateTime createdDate,
                        @JsonProperty("updatedDate") DateTime updatedDate) {
@@ -70,13 +64,35 @@ public class PaymentInfo implements EventBusNotification {
         this.bankIdentificationNumber = bankIdentificationNumber;
         this.effectiveDate = effectiveDate;
         this.paymentNumber = paymentNumber;
-        this.referenceId = referenceId;
         this.status = status;
         this.type = type;
+        this.referenceId = referenceId;
+        this.paymentMethodId = paymentMethodId;
+        this.paymentMethod = paymentMethod;
+        this.creditCardType = creditCardType;
+        this.creditCardCountry = creditCardCountry;
         this.createdDate = createdDate;
         this.updatedDate = updatedDate;
     }
 
+    public PaymentInfo(PaymentInfo src) {
+        this.paymentId = src.paymentId;
+        this.amount = src.amount;
+        this.refundAmount = src.refundAmount;
+        this.paymentNumber = src.paymentNumber;
+        this.bankIdentificationNumber = src.bankIdentificationNumber;
+        this.status = src.status;
+        this.type = src.type;
+        this.referenceId = src.referenceId;
+        this.paymentMethodId = src.paymentMethodId;
+        this.paymentMethod = src.paymentMethod;
+        this.creditCardType = src.creditCardType;
+        this.creditCardCountry = src.creditCardCountry;
+        this.effectiveDate = src.effectiveDate;
+        this.createdDate = src.createdDate;
+        this.updatedDate = src.updatedDate;
+    }
+
     public Builder cloner() {
         return new Builder(this);
     }
@@ -109,6 +125,22 @@ public class PaymentInfo implements EventBusNotification {
         return referenceId;
     }
 
+    public String getPaymentMethodType() {
+        return paymentMethod;
+    }
+
+    public String getCardType() {
+        return creditCardType;
+    }
+
+    public String getPaymentMethodId() {
+        return paymentMethodId;
+    }
+
+    public String getCardCountry() {
+        return creditCardCountry;
+    }
+
     public BigDecimal getRefundAmount() {
         return refundAmount;
     }
@@ -134,6 +166,10 @@ public class PaymentInfo implements EventBusNotification {
         private String type;
         private String status;
         private String referenceId;
+        private String paymentMethodId;
+        private String paymentMethod;
+        private String creditCardType;
+        private String creditCardCountry;
         private DateTime effectiveDate;
         private DateTime createdDate;
         private DateTime updatedDate;
@@ -151,6 +187,10 @@ public class PaymentInfo implements EventBusNotification {
             this.status = src.status;
             this.effectiveDate = src.effectiveDate;
             this.referenceId = src.referenceId;
+            this.paymentMethodId = src.paymentMethodId;
+            this.paymentMethod = src.paymentMethod;
+            this.creditCardType = src.creditCardType;
+            this.creditCardCountry = src.creditCardCountry;
             this.createdDate = src.createdDate;
             this.updatedDate = src.updatedDate;
         }
@@ -205,6 +245,26 @@ public class PaymentInfo implements EventBusNotification {
             return this;
         }
 
+        public Builder setPaymentMethodId(String paymentMethodId) {
+            this.paymentMethodId = paymentMethodId;
+            return this;
+        }
+
+        public Builder setPaymentMethodType(String paymentMethodType) {
+            this.paymentMethod = paymentMethodType;
+            return this;
+        }
+
+        public Builder setCreditCardType(String creditCardType) {
+            this.creditCardType = creditCardType;
+            return this;
+        }
+
+        public Builder setCreditCardCountry(String creditCardCountry) {
+            this.creditCardCountry = creditCardCountry;
+            return this;
+        }
+
         public Builder setUpdatedDate(DateTime updatedDate) {
             this.updatedDate = updatedDate;
             return this;
@@ -216,9 +276,13 @@ public class PaymentInfo implements EventBusNotification {
                                    refundAmount,
                                    bankIdentificationNumber,
                                    paymentNumber,
-                                   type,
                                    status,
+                                   type,
                                    referenceId,
+                                   paymentMethodId,
+                                   paymentMethod,
+                                   creditCardType,
+                                   creditCardCountry,
                                    effectiveDate,
                                    createdDate,
                                    updatedDate);
@@ -227,16 +291,20 @@ public class PaymentInfo implements EventBusNotification {
 
     @Override
     public int hashCode() {
-        return Objects.hashCode(amount,
+        return Objects.hashCode(paymentId,
+                                amount,
+                                refundAmount,
                                 bankIdentificationNumber,
-                                createdDate,
-                                effectiveDate,
-                                paymentId,
                                 paymentNumber,
-                                referenceId,
-                                refundAmount,
                                 status,
                                 type,
+                                referenceId,
+                                paymentMethodId,
+                                paymentMethod,
+                                creditCardType,
+                                creditCardCountry,
+                                effectiveDate,
+                                createdDate,
                                 updatedDate);
     }
 
@@ -250,14 +318,18 @@ public class PaymentInfo implements EventBusNotification {
             else {
                 return Objects.equal(amount, other.amount) &&
                        Objects.equal(bankIdentificationNumber, other.bankIdentificationNumber) &&
-                       Objects.equal(createdDate, other.createdDate) &&
-                       Objects.equal(effectiveDate, other.effectiveDate) &&
                        Objects.equal(paymentId, other.paymentId) &&
                        Objects.equal(paymentNumber, other.paymentNumber) &&
                        Objects.equal(referenceId, other.referenceId) &&
                        Objects.equal(refundAmount, other.refundAmount) &&
                        Objects.equal(status, other.status) &&
                        Objects.equal(type, other.type) &&
+                       Objects.equal(paymentMethodId, other.paymentMethodId) &&
+                       Objects.equal(paymentMethod, other.paymentMethod) &&
+                       Objects.equal(creditCardType, other.creditCardType) &&
+                       Objects.equal(creditCardCountry, other.creditCardCountry) &&
+                       Objects.equal(effectiveDate, other.effectiveDate) &&
+                       Objects.equal(createdDate, other.createdDate) &&
                        Objects.equal(updatedDate, other.updatedDate);
             }
         }
@@ -266,6 +338,7 @@ public class PaymentInfo implements EventBusNotification {
 
     @Override
     public String toString() {
-        return "PaymentInfo [paymentId=" + paymentId + ", amount=" + amount + ", refundAmount=" + refundAmount + ", paymentNumber=" + paymentNumber + ", bankIdentificationNumber=" + bankIdentificationNumber + ", status=" + status + ", type=" + type + ", referenceId=" + referenceId + ", effectiveDate=" + effectiveDate + ", createdDate=" + createdDate + ", updatedDate=" + updatedDate + "]";
+        return "PaymentInfo [paymentId=" + paymentId + ", amount=" + amount + ", refundAmount=" + refundAmount + ", paymentNumber=" + paymentNumber + ", bankIdentificationNumber=" + bankIdentificationNumber + ", status=" + status + ", type=" + type + ", referenceId=" + referenceId + ", paymentMethodId=" + paymentMethodId + ", paymentMethodType=" + paymentMethod + ", creditCardType=" + creditCardType + ", creditCardCountry=" + creditCardCountry + ", effectiveDate=" + effectiveDate + ", createdDate=" + createdDate + ", updatedDate=" + updatedDate + "]";
     }
+
 }
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 e89e799..1d78623 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
@@ -151,9 +151,24 @@ public class DefaultPaymentApi implements PaymentApi {
 
                 if (paymentOrError.isRight()) {
                     paymentInfo = paymentOrError.getRight();
-
                     paymentDao.savePaymentInfo(paymentInfo);
 
+                    Either<PaymentError, PaymentMethodInfo> paymentMethodInfoOrError = plugin.getPaymentMethodInfo(paymentInfo.getPaymentMethodId());
+
+                    if (paymentMethodInfoOrError.isRight()) {
+                        PaymentMethodInfo paymentMethodInfo = paymentMethodInfoOrError.getRight();
+
+                        if (paymentMethodInfo instanceof CreditCardPaymentMethodInfo) {
+                            CreditCardPaymentMethodInfo ccPaymentMethod = (CreditCardPaymentMethodInfo)paymentMethodInfo;
+                            paymentDao.updatePaymentInfo(ccPaymentMethod.getType(), paymentInfo.getPaymentId(), ccPaymentMethod.getCardType(), ccPaymentMethod.getCardCountry());
+                        }
+                        else if (paymentMethodInfo instanceof PaypalPaymentMethodInfo) {
+                            PaypalPaymentMethodInfo paypalPaymentMethodInfo = (PaypalPaymentMethodInfo)paymentMethodInfo;
+                            paymentDao.updatePaymentInfo(paypalPaymentMethodInfo.getType(), paymentInfo.getPaymentId(), null, null);
+                        }
+                    }
+
+
                     if (paymentInfo.getPaymentId() != null) {
                         paymentDao.updatePaymentAttemptWithPaymentId(paymentAttempt.getPaymentAttemptId(), paymentInfo.getPaymentId());
                     }
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 ceba7a7..eacc226 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
@@ -61,4 +61,9 @@ public class DefaultPaymentDao implements PaymentDao {
         sqlDao.updatePaymentAttemptWithPaymentId(paymentAttemptId.toString(), paymentId);
     }
 
+    @Override
+    public void updatePaymentInfo(String type, String paymentId, String cardType, String cardCountry) {
+        sqlDao.updatePaymentInfo(type, paymentId, cardType, cardCountry);
+    }
+
 }
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 d40b264..5cf065b 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
@@ -34,4 +34,6 @@ public interface PaymentDao {
 
     PaymentAttempt getPaymentAttemptForInvoiceId(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 7cd8adb..2a9d7f2 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
@@ -57,7 +57,13 @@ public interface PaymentSqlDao extends Transactional<PaymentSqlDao>, CloseMe, Tr
 
     @SqlUpdate
     void updatePaymentAttemptWithPaymentId(@Bind("payment_attempt_id") String paymentAttemptId,
-                                           @Bind("payment_id") String payment_id);
+                                           @Bind("payment_id") String paymentId);
+
+    @SqlUpdate
+    void updatePaymentInfo(@Bind("payment_method") String paymentMethod,
+                           @Bind("payment_id") String paymentId,
+                           @Bind("card_type") String cardType,
+                           @Bind("card_country") String cardCountry);
 
     @SqlUpdate
     void insertPaymentInfo(@Bind(binder = PaymentInfoBinder.class) PaymentInfo paymentInfo);
@@ -73,7 +79,7 @@ public interface PaymentSqlDao extends Transactional<PaymentSqlDao>, CloseMe, Tr
             stmt.bind("payment_attempt_id", paymentAttempt.getPaymentAttemptId().toString());
             stmt.bind("invoice_id", paymentAttempt.getInvoiceId().toString());
             stmt.bind("account_id", paymentAttempt.getAccountId().toString());
-            stmt.bind("amount", paymentAttempt.getAmount()); //TODO: suppport partial payments
+            stmt.bind("amount", paymentAttempt.getAmount());
             stmt.bind("currency", paymentAttempt.getCurrency().toString());
             stmt.bind("invoice_dt", getDate(paymentAttempt.getInvoiceDate()));
             stmt.bind("payment_attempt_dt", getDate(paymentAttempt.getPaymentAttemptDate()));
@@ -124,6 +130,10 @@ public interface PaymentSqlDao extends Transactional<PaymentSqlDao>, CloseMe, Tr
             stmt.bind("status", paymentInfo.getStatus());
             stmt.bind("payment_type", paymentInfo.getType());
             stmt.bind("reference_id", paymentInfo.getReferenceId());
+            stmt.bind("payment_method_id", paymentInfo.getPaymentMethodId());
+            stmt.bind("payment_method", paymentInfo.getPaymentMethodType());
+            stmt.bind("card_type", paymentInfo.getCardType());
+            stmt.bind("card_country", paymentInfo.getCardCountry());
             stmt.bind("effective_dt", getDate(paymentInfo.getEffectiveDate()));
             stmt.bind("created_dt", getDate(paymentInfo.getCreatedDate()));
             stmt.bind("updated_dt", getDate(paymentInfo.getUpdatedDate()));
@@ -148,6 +158,10 @@ public interface PaymentSqlDao extends Transactional<PaymentSqlDao>, CloseMe, Tr
             String status = rs.getString("status");
             String type = rs.getString("payment_type");
             String referenceId = rs.getString("reference_id");
+            String paymentMethodId = rs.getString("payment_method_id");
+            String paymentMethod = rs.getString("payment_method");
+            String cardType = rs.getString("card_type");
+            String cardCountry = rs.getString("card_country");
             DateTime effectiveDate = getDate(rs, "effective_dt");
             DateTime createdDate = getDate(rs, "created_dt");
             DateTime updatedDate = getDate(rs, "updated_dt");
@@ -160,6 +174,10 @@ public interface PaymentSqlDao extends Transactional<PaymentSqlDao>, CloseMe, Tr
                                    status,
                                    type,
                                    referenceId,
+                                   paymentMethodId,
+                                   paymentMethod,
+                                   cardType,
+                                   cardCountry,
                                    effectiveDate,
                                    createdDate,
                                    updatedDate);
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 5156b03..4582d6e 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
@@ -22,6 +22,9 @@ paymentInfoFields(prefix) ::= <<
     <prefix>payment_type,
     <prefix>status,
     <prefix>reference_id,
+    <prefix>payment_method,
+    <prefix>card_type,
+    <prefix>card_country,
     <prefix>effective_dt,
     <prefix>created_dt,
     <prefix>updated_dt
@@ -53,5 +56,14 @@ updatePaymentAttemptWithPaymentId() ::= <<
 
 insertPaymentInfo() ::= <<
     INSERT INTO payments (<paymentInfoFields()>)
-    VALUES (:payment_id, :amount, :refund_amount, :bank_identification_number, :payment_number, :payment_type, :status, :reference_id, :effective_dt, NOW(), NOW());
+    VALUES (:payment_id, :amount, :refund_amount, :bank_identification_number, :payment_number, :payment_type, :status, :reference_id, :payment_method, :card_type, :card_country, :effective_dt, :created_dt, :updated_dt);
 >>
+
+updatePaymentInfo() ::= <<
+    UPDATE payments
+       SET payment_method = :payment_method,
+           card_type = :card_type,
+           card_country = :card_country,
+           updated_dt = NOW()
+     WHERE payment_id = :payment_id
+>>
\ No newline at end of file
diff --git a/payment/src/main/resources/com/ning/billing/payment/ddl.sql b/payment/src/main/resources/com/ning/billing/payment/ddl.sql
index fd6a1ea..e4e3501 100644
--- a/payment/src/main/resources/com/ning/billing/payment/ddl.sql
+++ b/payment/src/main/resources/com/ning/billing/payment/ddl.sql
@@ -21,8 +21,12 @@ CREATE TABLE payments (
       payment_number varchar(36) COLLATE utf8_bin,
       bank_identification_number varchar(36) COLLATE utf8_bin,
       status varchar(20) COLLATE utf8_bin,
-      payment_type varchar(20) COLLATE utf8_bin,
       reference_id varchar(36) COLLATE utf8_bin,
+      payment_type varchar(20) COLLATE utf8_bin,
+      payment_method_id varchar(20) COLLATE utf8_bin,
+      payment_method varchar(20) COLLATE utf8_bin,
+      card_type varchar(20) COLLATE utf8_bin,
+      card_country varchar(50) COLLATE utf8_bin,
       effective_dt datetime,
       created_dt datetime NOT NULL,
       updated_dt datetime NOT NULL,
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 c756963..748a447 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
@@ -17,6 +17,7 @@
 package com.ning.billing.payment.api;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
 
@@ -88,6 +89,7 @@ public abstract class TestPaymentApi {
         assertNotNull(paymentInfo.getPaymentId());
         assertTrue(paymentInfo.getAmount().compareTo(amount) == 0);
         assertNotNull(paymentInfo.getPaymentNumber());
+        assertFalse(paymentInfo.getStatus().equals("Error"));
 
         PaymentAttempt paymentAttempt = paymentApi.getPaymentAttemptForPaymentId(paymentInfo.getPaymentId());
         assertNotNull(paymentAttempt);
@@ -96,7 +98,7 @@ public abstract class TestPaymentApi {
         assertTrue(paymentAttempt.getAmount().compareTo(amount) == 0);
         assertEquals(paymentAttempt.getCurrency(), Currency.USD);
         assertEquals(paymentAttempt.getPaymentId(), paymentInfo.getPaymentId());
-        assertEquals(paymentAttempt.getPaymentAttemptDate().withMillisOfSecond(0), now.withMillisOfSecond(0));
+        assertEquals(paymentAttempt.getPaymentAttemptDate().withMillisOfSecond(0).withSecondOfMinute(0), now.withMillisOfSecond(0).withSecondOfMinute(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 74d8552..bb83927 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
@@ -70,4 +70,10 @@ public class MockPaymentDao implements PaymentDao {
         return null;
     }
 
+    @Override
+    public void updatePaymentInfo(String paymentMethodType, String paymentId, String cardType, String cardCountry) {
+        // TODO Auto-generated method stub
+
+    }
+
 }