killbill-memoizeit

Added builder to PaymentMethod

12/12/2011 6:02:20 PM

Details

diff --git a/api/src/main/java/com/ning/billing/payment/api/PaymentMethodInfo.java b/api/src/main/java/com/ning/billing/payment/api/PaymentMethodInfo.java
index 8326015..78f73d3 100644
--- a/api/src/main/java/com/ning/billing/payment/api/PaymentMethodInfo.java
+++ b/api/src/main/java/com/ning/billing/payment/api/PaymentMethodInfo.java
@@ -22,18 +22,15 @@ public class PaymentMethodInfo {
     private final String id;
     private final String accountId;
     private final Boolean defaultMethod;
-    private final String email;
     private final String type;
 
     public PaymentMethodInfo(String id,
                              String accountId,
                              Boolean defaultMethod,
-                             String email,
                              String type) {
         this.id = id;
         this.accountId = accountId;
         this.defaultMethod = defaultMethod;
-        this.email = email;
         this.type = type;
     }
 
@@ -49,10 +46,6 @@ public class PaymentMethodInfo {
         return defaultMethod;
     }
 
-    public String getEmail() {
-        return email;
-    }
-
     public String getType() {
         return type;
     }
@@ -62,7 +55,6 @@ public class PaymentMethodInfo {
         return Objects.hashCode(id,
                                 accountId,
                                 defaultMethod,
-                                email,
                                 type);
     }
 
@@ -77,7 +69,6 @@ public class PaymentMethodInfo {
                 return Objects.equal(id, other.id) &&
                        Objects.equal(accountId, other.accountId) &&
                        Objects.equal(defaultMethod, other.defaultMethod) &&
-                       Objects.equal(email, other.email) &&
                        Objects.equal(type, other.type);
             }
         }
@@ -86,7 +77,61 @@ public class PaymentMethodInfo {
 
     @Override
     public String toString() {
-        return "PaymentMethodInfo [id=" + id + ", accountId=" + accountId + ", defaultMethod=" + defaultMethod + ", email=" + email + ", type=" + type + "]";
+        return "PaymentMethodInfo [id=" + id + ", accountId=" + accountId + ", defaultMethod=" + defaultMethod + ", type=" + type + "]";
     }
 
+    protected abstract static class BuilderBase<T extends PaymentMethodInfo, V extends BuilderBase<T, V>> {
+        protected final Class<V> builderClazz;
+        protected String id;
+        protected String accountId;
+        protected Boolean defaultMethod;
+
+        protected BuilderBase(Class<V> builderClazz) {
+            this.builderClazz = builderClazz;
+        }
+
+        protected BuilderBase(Class<V> builderClazz, T src) {
+            this(builderClazz);
+            this.id = src.id;
+            this.accountId = src.accountId;
+            this.defaultMethod = src.defaultMethod;
+        }
+
+        public V setId(String id) {
+            this.id = id;
+            return builderClazz.cast(this);
+        }
+
+        public V setAccountId(String accountId) {
+            this.accountId = accountId;
+            return builderClazz.cast(this);
+        }
+
+        public V setDefaultMethod(Boolean defaultMethod) {
+            this.defaultMethod = defaultMethod;
+            return builderClazz.cast(this);
+        }
+    }
+
+    public static class Builder extends BuilderBase<PaymentMethodInfo, Builder> {
+        private String type;
+
+        public Builder() {
+            super(Builder.class);
+        }
+
+        public Builder(PaymentMethodInfo src) {
+            super(Builder.class, src);
+            this.type = src.type;
+        }
+
+        public Builder setType(String type) {
+            this.type = type;
+            return this;
+        }
+
+        public PaymentMethodInfo build() {
+            return new PaymentMethodInfo(id, accountId, defaultMethod, type);
+        }
+    }
 }
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 d132275..e997a9b 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
@@ -56,14 +56,15 @@ public class DefaultPaymentApi implements PaymentApi {
     }
 
     @Override
-    public Either<PaymentError, List<PaymentMethodInfo>> getPaymentMethods(String accountId) {
+    public Either<PaymentError, List<PaymentMethodInfo>> getPaymentMethods(String accountKey) {
         final String paymentProviderName;
+        paymentProviderName = null;
 
-        final IAccount account = accountUserApi.getAccountFromId(UUID.fromString(accountId));
-        paymentProviderName = account.getFieldValue(RequestProcessor.PAYMENT_PROVIDER_KEY);
+//        final IAccount account = accountUserApi.getAccountByKey(accountKey);
+//        paymentProviderName = account.getFieldValue(RequestProcessor.PAYMENT_PROVIDER_KEY);
 
         final PaymentProviderPlugin plugin = pluginRegistry.getPlugin(paymentProviderName);
 
-        return plugin.getPaymentMethods(accountId);
+        return plugin.getPaymentMethods(accountKey);
     }
 }
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 f686090..0579119 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
@@ -22,6 +22,7 @@ import com.ning.billing.account.api.IAccount;
 import com.ning.billing.invoice.model.Invoice;
 import com.ning.billing.payment.PaymentInfo;
 import com.ning.billing.payment.PaymentProviderAccount;
+import com.ning.billing.payment.PaypalPaymentMethodInfo;
 import com.ning.billing.payment.api.Either;
 import com.ning.billing.payment.api.PaymentError;
 import com.ning.billing.payment.api.PaymentMethodInfo;
@@ -31,6 +32,7 @@ public interface PaymentProviderPlugin {
     Either<PaymentError, PaymentInfo> getPaymentInfo(String paymentId);
     Either<PaymentError, PaymentProviderAccount> createPaymentProviderAccount(IAccount account);
     Either<PaymentError, PaymentMethodInfo> getPaymentMethodInfo(String paymentMethodId);
-    Either<PaymentError, List<PaymentMethodInfo>> getPaymentMethods(String accountId);
+    Either<PaymentError, List<PaymentMethodInfo>> getPaymentMethods(String screenName);
+    Either<PaymentError, PaypalPaymentMethodInfo> addPaypalPaymentMethod(IAccount account, PaypalPaymentMethodInfo paypalPaymentMethod);
 
 }
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 2af9f41..37a35ad 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,7 @@ import com.ning.billing.account.api.IAccount;
 import com.ning.billing.invoice.model.Invoice;
 import com.ning.billing.payment.PaymentInfo;
 import com.ning.billing.payment.PaymentProviderAccount;
+import com.ning.billing.payment.PaypalPaymentMethodInfo;
 import com.ning.billing.payment.api.Either;
 import com.ning.billing.payment.api.PaymentError;
 import com.ning.billing.payment.api.PaymentMethodInfo;
@@ -69,4 +70,10 @@ public class MockPaymentProviderPlugin implements PaymentProviderPlugin {
         // TODO Auto-generated method stub
         return null;
     }
+
+    @Override
+    public Either<PaymentError, PaypalPaymentMethodInfo> addPaypalPaymentMethod(IAccount account, PaypalPaymentMethodInfo paypalPaymentMethod) {
+        // 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 b401a96..d74c959 100644
--- a/payment/src/test/java/com/ning/billing/payment/TestPaymentProvider.java
+++ b/payment/src/test/java/com/ning/billing/payment/TestPaymentProvider.java
@@ -110,7 +110,7 @@ public class TestPaymentProvider {
 
         paymentInfoReceiver.clear();
         eventBus.post(paymentInfoRequest);
-        await().atMost(1, MINUTES).until(new Callable<Boolean>() {
+        await().atMost(5, MINUTES).until(new Callable<Boolean>() {
             @Override
             public Boolean call() throws Exception {
                 List<PaymentInfo> processedPayments = paymentInfoReceiver.getProcessedPayments();

pom.xml 15(+15 -0)

diff --git a/pom.xml b/pom.xml
index b5cc9bd..fcb837e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -417,6 +417,21 @@
                     <attachClasses>true</attachClasses>
                 </configuration>
             </plugin>
+            <plugin>
+              <groupId>org.apache.maven.plugins</groupId>
+              <artifactId>maven-source-plugin</artifactId>
+              <version>2.1.2</version>
+              <executions>
+                <execution>
+                  <id>attach-sources</id>
+                  <phase>verify</phase>
+                  <goals>
+                    <goal>jar</goal>
+                    <goal>test-jar</goal>
+                  </goals>
+                </execution>
+              </executions>
+            </plugin>
         </plugins>
     </build>
     <profiles>