killbill-memoizeit

Details

diff --git a/api/src/main/java/com/ning/billing/account/api/IFieldStore.java b/api/src/main/java/com/ning/billing/account/api/IFieldStore.java
index 1ecb9b2..aa6b8ec 100644
--- a/api/src/main/java/com/ning/billing/account/api/IFieldStore.java
+++ b/api/src/main/java/com/ning/billing/account/api/IFieldStore.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at:
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
 package com.ning.billing.account.api;
 
 import java.util.List;
diff --git a/invoice/src/main/java/com/ning/billing/invoice/model/Invoice.java b/invoice/src/main/java/com/ning/billing/invoice/model/Invoice.java
index d15c387..a5d7d58 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/model/Invoice.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/model/Invoice.java
@@ -87,5 +87,11 @@ public class Invoice implements IEventBusType {
     public BigDecimal getTotalAmount() {
         return items.getTotalAmount();
     }
+
+    @Override
+    public String toString() {
+        return "Invoice [items=" + items + ", invoiceId=" + invoiceId + ", accountId=" + accountId + ", invoiceDate=" + invoiceDate + ", currency=" + currency + "]";
+    }
+
 }
 

payment/pom.xml 4(+4 -0)

diff --git a/payment/pom.xml b/payment/pom.xml
index 73cf60a..41b9aa6 100644
--- a/payment/pom.xml
+++ b/payment/pom.xml
@@ -33,6 +33,10 @@
             <artifactId>killbill-account</artifactId>
         </dependency>
         <dependency>
+            <groupId>com.ning.billing</groupId>
+            <artifactId>killbill-util</artifactId>
+        </dependency>
+        <dependency>
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
             <scope>provided</scope>
diff --git a/payment/src/main/java/com/ning/billing/payment/CreditCardPaymentMethod.java b/payment/src/main/java/com/ning/billing/payment/CreditCardPaymentMethod.java
new file mode 100644
index 0000000..98710dc
--- /dev/null
+++ b/payment/src/main/java/com/ning/billing/payment/CreditCardPaymentMethod.java
@@ -0,0 +1,42 @@
+package com.ning.billing.payment;
+
+public class CreditCardPaymentMethod  extends PaymentMethodInfo {
+    private final String cardHolderName;
+    private final String cardType; // e.g. MasterCard
+    private final String expirationDateStr; // e.g. 2012-01
+    private final String maskNumber; // e.g. "************1234"
+
+    public CreditCardPaymentMethod(String id,
+                                   String accountId,
+                                   Boolean defaultMethod,
+                                   String email,
+                                   String type,
+                                   String cardHolderName,
+                                   String cardType,
+                                   String expirationDateStr,
+                                   String maskNumber) {
+        super(id, accountId, defaultMethod, email, "creditCard");
+        this.cardHolderName = cardHolderName;
+        this.cardType = cardType;
+        this.expirationDateStr = expirationDateStr;
+        this.maskNumber = maskNumber;
+    }
+
+    public String getCardHolderName() {
+        return cardHolderName;
+    }
+
+    public String getCardType() {
+        return cardType;
+    }
+
+    public String getExpirationDateStr() {
+        return expirationDateStr;
+    }
+
+    public String getMaskNumber() {
+        return maskNumber;
+    }
+
+
+}
diff --git a/payment/src/main/java/com/ning/billing/payment/PaymentInfo.java b/payment/src/main/java/com/ning/billing/payment/PaymentInfo.java
index 9b753c5..1a6f15d 100644
--- a/payment/src/main/java/com/ning/billing/payment/PaymentInfo.java
+++ b/payment/src/main/java/com/ning/billing/payment/PaymentInfo.java
@@ -20,22 +20,22 @@ import java.math.BigDecimal;
 
 import org.joda.time.DateTime;
 
+import com.google.common.base.Objects;
 import com.ning.billing.util.eventbus.IEventBusType;
 
 public class PaymentInfo implements IEventBusType {
     public static class Builder {
         private String id;
         private BigDecimal amount;
+        private BigDecimal refundAmount;
         private BigDecimal appliedCreditBalanceAmount;
-        private String bankIdentificationNumber;
-        private DateTime createdDate;
-        private DateTime effectiveDate;
         private String paymentNumber;
-        private String referenceId;
-        private BigDecimal refundAmount;
-        private String secondPaymentReferenceId;
-        private String status;
+        private String bankIdentificationNumber;
         private String type;
+        private String status;
+        private String referenceId;
+        private DateTime effectiveDate;
+        private DateTime createdDate;
         private DateTime updatedDate;
 
         public Builder() {
@@ -44,16 +44,15 @@ public class PaymentInfo implements IEventBusType {
         public Builder(PaymentInfo src) {
             this.id = src.id;
             this.amount = src.amount;
+            this.refundAmount = src.refundAmount;
             this.appliedCreditBalanceAmount = src.appliedCreditBalanceAmount;
+            this.paymentNumber = src.paymentNumber;
             this.bankIdentificationNumber = src.bankIdentificationNumber;
-            this.createdDate = src.createdDate;
+            this.type = src.type;
+            this.status = src.status;
             this.effectiveDate = src.effectiveDate;
-            this.paymentNumber = src.paymentNumber;
             this.referenceId = src.referenceId;
-            this.refundAmount = src.refundAmount;
-            this.secondPaymentReferenceId = src.secondPaymentReferenceId;
-            this.status = src.status;
-            this.type = src.type;
+            this.createdDate = src.createdDate;
             this.updatedDate = src.updatedDate;
         }
 
@@ -102,11 +101,6 @@ public class PaymentInfo implements IEventBusType {
             return this;
         }
 
-        public Builder setSecondPaymentReferenceId(String secondPaymentReferenceId) {
-            this.secondPaymentReferenceId = secondPaymentReferenceId;
-            return this;
-        }
-
         public Builder setStatus(String status) {
             this.status = status;
             return this;
@@ -125,47 +119,44 @@ public class PaymentInfo implements IEventBusType {
         public PaymentInfo build() {
             return new PaymentInfo(id,
                                    amount,
-                                   appliedCreditBalanceAmount,
+                                   refundAmount,
                                    bankIdentificationNumber,
-                                   createdDate,
-                                   effectiveDate,
                                    paymentNumber,
-                                   referenceId,
-                                   refundAmount,
-                                   secondPaymentReferenceId,
-                                   status,
+                                   appliedCreditBalanceAmount,
                                    type,
+                                   status,
+                                   referenceId,
+                                   effectiveDate,
+                                   createdDate,
                                    updatedDate);
         }
     }
 
     private final String id;
     private final BigDecimal amount;
+    private final BigDecimal refundAmount;
     private final BigDecimal appliedCreditBalanceAmount;
-    private final String bankIdentificationNumber;
-    private final DateTime createdDate;
-    private final DateTime effectiveDate;
     private final String paymentNumber;
-    private final String referenceId;
-    private final BigDecimal refundAmount;
-    private final String secondPaymentReferenceId;
+    private final String bankIdentificationNumber;
     private final String status;
     private final String type;
+    private final String referenceId;
+    private final DateTime effectiveDate;
+    private final DateTime createdDate;
     private final DateTime updatedDate;
 
     public PaymentInfo(PaymentInfo src) {
         this.id = src.id;
         this.amount = src.amount;
+        this.refundAmount = src.refundAmount;
         this.appliedCreditBalanceAmount = src.appliedCreditBalanceAmount;
-        this.bankIdentificationNumber = src.bankIdentificationNumber;
-        this.createdDate = src.createdDate;
-        this.effectiveDate = src.effectiveDate;
         this.paymentNumber = src.paymentNumber;
-        this.referenceId = src.referenceId;
-        this.refundAmount = src.refundAmount;
-        this.secondPaymentReferenceId = src.secondPaymentReferenceId;
+        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;
     }
 
@@ -173,14 +164,13 @@ public class PaymentInfo implements IEventBusType {
                        BigDecimal amount,
                        BigDecimal appliedCreditBalanceAmount,
                        String bankIdentificationNumber,
-                       DateTime createdDate,
-                       DateTime effectiveDate,
                        String paymentNumber,
-                       String referenceId,
                        BigDecimal refundAmount,
-                       String secondPaymentReferenceId,
                        String status,
                        String type,
+                       String referenceId,
+                       DateTime effectiveDate,
+                       DateTime createdDate,
                        DateTime updatedDate) {
         this.id = id;
         this.amount = amount;
@@ -191,7 +181,6 @@ public class PaymentInfo implements IEventBusType {
         this.paymentNumber = paymentNumber;
         this.referenceId = referenceId;
         this.refundAmount = refundAmount;
-        this.secondPaymentReferenceId = secondPaymentReferenceId;
         this.status = status;
         this.type = type;
         this.updatedDate = updatedDate;
@@ -237,10 +226,6 @@ public class PaymentInfo implements IEventBusType {
         return refundAmount;
     }
 
-    public String getSecondPaymentReferenceId() {
-        return secondPaymentReferenceId;
-    }
-
     public String getStatus() {
         return status;
     }
@@ -255,126 +240,47 @@ public class PaymentInfo implements IEventBusType {
 
     @Override
     public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((amount == null) ? 0 : amount.hashCode());
-        result = prime * result + ((appliedCreditBalanceAmount == null) ? 0
-                                                                       : appliedCreditBalanceAmount.hashCode());
-        result = prime * result + ((bankIdentificationNumber == null) ? 0
-                                                                     : bankIdentificationNumber.hashCode());
-        result = prime * result + ((createdDate == null) ? 0
-                                                        : createdDate.hashCode());
-        result = prime * result + ((effectiveDate == null) ? 0
-                                                          : effectiveDate.hashCode());
-        result = prime * result + ((id == null) ? 0 : id.hashCode());
-        result = prime * result + ((paymentNumber == null) ? 0
-                                                          : paymentNumber.hashCode());
-        result = prime * result + ((referenceId == null) ? 0
-                                                        : referenceId.hashCode());
-        result = prime * result + ((refundAmount == null) ? 0
-                                                         : refundAmount.hashCode());
-        result = prime * result + ((secondPaymentReferenceId == null) ? 0
-                                                                     : secondPaymentReferenceId.hashCode());
-        result = prime * result + ((status == null) ? 0 : status.hashCode());
-        result = prime * result + ((type == null) ? 0 : type.hashCode());
-        result = prime * result + ((updatedDate == null) ? 0
-                                                        : updatedDate.hashCode());
-        return result;
+        return Objects.hashCode(amount,
+                                appliedCreditBalanceAmount,
+                                bankIdentificationNumber,
+                                createdDate,
+                                effectiveDate,
+                                id,
+                                paymentNumber,
+                                referenceId,
+                                refundAmount,
+                                status,
+                                type,
+                                updatedDate);
     }
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
-            return false;
-        PaymentInfo other = (PaymentInfo) obj;
-        if (amount == null) {
-            if (other.amount != null)
-                return false;
-        }
-        else if (!amount.equals(other.amount))
-            return false;
-        if (appliedCreditBalanceAmount == null) {
-            if (other.appliedCreditBalanceAmount != null)
-                return false;
-        }
-        else if (!appliedCreditBalanceAmount.equals(other.appliedCreditBalanceAmount))
-            return false;
-        if (bankIdentificationNumber == null) {
-            if (other.bankIdentificationNumber != null)
-                return false;
-        }
-        else if (!bankIdentificationNumber.equals(other.bankIdentificationNumber))
-            return false;
-        if (createdDate == null) {
-            if (other.createdDate != null)
-                return false;
-        }
-        else if (!createdDate.equals(other.createdDate))
-            return false;
-        if (effectiveDate == null) {
-            if (other.effectiveDate != null)
-                return false;
+        if (getClass() == obj.getClass()) {
+            PaymentInfo other = (PaymentInfo)obj;
+            if (obj == other) {
+                return true;
+            }
+            else {
+                return Objects.equal(amount, other.amount) &&
+                       Objects.equal(appliedCreditBalanceAmount, other.appliedCreditBalanceAmount) &&
+                       Objects.equal(bankIdentificationNumber, other.bankIdentificationNumber) &&
+                       Objects.equal(createdDate, other.createdDate) &&
+                       Objects.equal(effectiveDate, other.effectiveDate) &&
+                       Objects.equal(id, other.id) &&
+                       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(updatedDate, other.updatedDate);
+            }
         }
-        else if (!effectiveDate.equals(other.effectiveDate))
-            return false;
-        if (id == null) {
-            if (other.id != null)
-                return false;
-        }
-        else if (!id.equals(other.id))
-            return false;
-        if (paymentNumber == null) {
-            if (other.paymentNumber != null)
-                return false;
-        }
-        else if (!paymentNumber.equals(other.paymentNumber))
-            return false;
-        if (referenceId == null) {
-            if (other.referenceId != null)
-                return false;
-        }
-        else if (!referenceId.equals(other.referenceId))
-            return false;
-        if (refundAmount == null) {
-            if (other.refundAmount != null)
-                return false;
-        }
-        else if (!refundAmount.equals(other.refundAmount))
-            return false;
-        if (secondPaymentReferenceId == null) {
-            if (other.secondPaymentReferenceId != null)
-                return false;
-        }
-        else if (!secondPaymentReferenceId.equals(other.secondPaymentReferenceId))
-            return false;
-        if (status == null) {
-            if (other.status != null)
-                return false;
-        }
-        else if (!status.equals(other.status))
-            return false;
-        if (type == null) {
-            if (other.type != null)
-                return false;
-        }
-        else if (!type.equals(other.type))
-            return false;
-        if (updatedDate == null) {
-            if (other.updatedDate != null)
-                return false;
-        }
-        else if (!updatedDate.equals(other.updatedDate))
-            return false;
-        return true;
+        return false;
     }
 
     @Override
     public String toString() {
-        return "PaymentInfo [id=" + id + ", amount=" + amount + ", appliedCreditBalanceAmount=" + appliedCreditBalanceAmount + ", bankIdentificationNumber=" + bankIdentificationNumber + ", createdDate=" + createdDate + ", effectiveDate=" + effectiveDate + ", paymentNumber=" + paymentNumber + ", referenceId=" + referenceId + ", refundAmount=" + refundAmount + ", secondPaymentReferenceId=" + secondPaymentReferenceId + ", status=" + status + ", type=" + type + ", updatedDate=" + updatedDate + "]";
+        return "PaymentInfo [id=" + id + ", amount=" + amount + ", refundAmount=" + refundAmount + ", appliedCreditBalanceAmount=" + appliedCreditBalanceAmount + ", paymentNumber=" + paymentNumber + ", bankIdentificationNumber=" + bankIdentificationNumber + ", status=" + status + ", type=" + type + ", referenceId=" + referenceId + ", effectiveDate=" + effectiveDate + ", createdDate=" + createdDate + ", updatedDate=" + updatedDate + "]";
     }
-
 }
diff --git a/payment/src/main/java/com/ning/billing/payment/PaymentProviderAccount.java b/payment/src/main/java/com/ning/billing/payment/PaymentProviderAccount.java
new file mode 100644
index 0000000..8668cd8
--- /dev/null
+++ b/payment/src/main/java/com/ning/billing/payment/PaymentProviderAccount.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at:
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.payment;
+
+public class PaymentProviderAccount {
+    private final String id;
+    private final String accountNumber;
+    private final String defaultPaymentMethodId;
+
+    public PaymentProviderAccount(String id,
+                                  String accountNumber,
+                                  String defaultPaymentMethodId) {
+        this.id = id;
+        this.accountNumber = accountNumber;
+        this.defaultPaymentMethodId = defaultPaymentMethodId;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public String getAccountNumber() {
+        return accountNumber;
+    }
+
+    public String getDefaultPaymentMethodId() {
+        return defaultPaymentMethodId;
+    }
+
+}
diff --git a/payment/src/main/java/com/ning/billing/payment/provider/PaymentProviderPlugin.java b/payment/src/main/java/com/ning/billing/payment/provider/PaymentProviderPlugin.java
index a108136..52bb320 100644
--- a/payment/src/main/java/com/ning/billing/payment/provider/PaymentProviderPlugin.java
+++ b/payment/src/main/java/com/ning/billing/payment/provider/PaymentProviderPlugin.java
@@ -20,9 +20,15 @@ import com.ning.billing.account.api.IAccount;
 import com.ning.billing.invoice.model.Invoice;
 import com.ning.billing.payment.PaymentError;
 import com.ning.billing.payment.PaymentInfo;
+import com.ning.billing.payment.PaymentMethodInfo;
+import com.ning.billing.payment.PaymentProviderAccount;
 import com.ning.billing.util.Either;
 
 public interface PaymentProviderPlugin {
     Either<PaymentError, PaymentInfo> processInvoice(IAccount account, Invoice invoice);
     Either<PaymentError, PaymentInfo> getPaymentInfo(String paymentId);
+    Either<PaymentError, PaymentProviderAccount> createPaymentProviderAccount(IAccount account);
+    Either<PaymentError, PaymentMethodInfo> getPaymentMethodInfo(String paymentMethodId);
+//    Either<PaymentError, List<PaymentMethodInfo>> getPaymentMethodInfo(IAccount account);
+
 }
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 9c90733..86f1129 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
@@ -25,6 +25,8 @@ import com.ning.billing.account.api.IAccount;
 import com.ning.billing.invoice.model.Invoice;
 import com.ning.billing.payment.PaymentError;
 import com.ning.billing.payment.PaymentInfo;
+import com.ning.billing.payment.PaymentMethodInfo;
+import com.ning.billing.payment.PaymentProviderAccount;
 import com.ning.billing.util.Either;
 
 public class MockPaymentProviderPlugin implements PaymentProviderPlugin {
@@ -55,4 +57,16 @@ public class MockPaymentProviderPlugin implements PaymentProviderPlugin {
             return Either.right(payment);
         }
     }
+
+    @Override
+    public Either<PaymentError, PaymentProviderAccount> createPaymentProviderAccount(IAccount account) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Either<PaymentError, PaymentMethodInfo> getPaymentMethodInfo(String paymentMethodId) {
+        // TODO Auto-generated method stub
+        return null;
+    }
 }
diff --git a/payment/src/test/java/com/ning/billing/payment/TestPaymentProvider.java b/payment/src/test/java/com/ning/billing/payment/TestPaymentProvider.java
index 10d6518..d728021 100644
--- a/payment/src/test/java/com/ning/billing/payment/TestPaymentProvider.java
+++ b/payment/src/test/java/com/ning/billing/payment/TestPaymentProvider.java
@@ -105,10 +105,10 @@ public class TestPaymentProvider {
         assertTrue(paymentInfoReceiver.getErrors().isEmpty());
 
         final PaymentInfo paymentInfo = paymentInfoReceiver.getProcessedPayments().get(0);
-        final PaymentInfoRequest infoRequest = new PaymentInfoRequest(account.getId(), paymentInfo.getId());
+        final PaymentInfoRequest paymentInfoRequest = new PaymentInfoRequest(account.getId(), paymentInfo.getId());
 
         paymentInfoReceiver.clear();
-        eventBus.post(infoRequest);
+        eventBus.post(paymentInfoRequest);
         await().atMost(1, MINUTES).until(new Callable<Boolean>() {
             @Override
             public Boolean call() throws Exception {
@@ -123,4 +123,5 @@ public class TestPaymentProvider {
         assertTrue(paymentInfoReceiver.getErrors().isEmpty());
         assertEquals(paymentInfoReceiver.getProcessedPayments().get(0), paymentInfo);
     }
+
 }