Skip to content
This repository
Browse code

Higher-level code goes first. Better variable names.

  • Loading branch information...
commit e775167cda8ab3d5e52fa23624ff5c31e2e161e0 1 parent a72e31b
Gabe Berke-Williams authored January 13, 2012

Showing 1 changed file with 28 additions and 27 deletions. Show diff stats Hide diff stats

  1. 55  lib/fake_braintree/customer.rb
55  lib/fake_braintree/customer.rb
@@ -2,11 +2,11 @@ module FakeBraintree
2 2
   class Customer
3 3
     include Helpers
4 4
 
5  
-    def initialize(customer_hash, options)
  5
+    def initialize(customer_hash_from_params, options)
6 6
       @customer_hash = {
7  
-        "id" => options[:id],
  7
+        "id"          => options[:id],
8 8
         "merchant_id" => options[:merchant_id]
9  
-      }.merge(customer_hash)
  9
+      }.merge(customer_hash_from_params)
10 10
     end
11 11
 
12 12
     def create
@@ -81,18 +81,6 @@ def customer_from_registry
81 81
       FakeBraintree.registry.customers[customer_id]
82 82
     end
83 83
 
84  
-    def credit_card_token(hash)
85  
-      md5("#{hash['merchant_id']}#{hash['id']}")
86  
-    end
87  
-
88  
-    def last_four(hash)
89  
-      hash["credit_card"].delete("number")[-4..-1]
90  
-    end
91  
-
92  
-    def failure_response(code)
93  
-      gzipped_response(code, FakeBraintree.failure_response(credit_card_number).to_xml(:root => 'api_error_response'))
94  
-    end
95  
-
96 84
     def credit_card_is_failure?
97 85
       has_credit_card? && FakeBraintree.failure?(credit_card_hash["number"])
98 86
     end
@@ -121,10 +109,6 @@ def credit_card_number
121 109
       credit_card_hash["number"]
122 110
     end
123 111
 
124  
-    def response_for_created_customer(hash)
125  
-      gzipped_response(201, hash.to_xml(:root => 'customer'))
126  
-    end
127  
-
128 112
     def create_customer_with(hash)
129 113
       FakeBraintree.registry.customers[hash["id"]] = hash
130 114
     end
@@ -134,6 +118,14 @@ def add_credit_card_to_registry(new_credit_card_hash)
134 118
       FakeBraintree.registry.credit_cards[token] = new_credit_card_hash
135 119
     end
136 120
 
  121
+    def credit_card_expiration_month
  122
+      credit_card_expiration_date[0]
  123
+    end
  124
+
  125
+    def credit_card_expiration_year
  126
+      credit_card_expiration_date[1]
  127
+    end
  128
+
137 129
     def credit_card_expiration_date
138 130
       if credit_card_hash.key?("expiration_date")
139 131
         credit_card_hash["expiration_date"].split('/')
@@ -142,20 +134,16 @@ def credit_card_expiration_date
142 134
       end
143 135
     end
144 136
 
145  
-    def credit_card_expiration_month
146  
-      credit_card_expiration_date[0]
147  
-    end
148  
-
149  
-    def credit_card_expiration_year
150  
-      credit_card_expiration_date[1]
  137
+    def delete_customer_with_id(id)
  138
+      FakeBraintree.registry.customers[id] = nil
151 139
     end
152 140
 
153 141
     def deletion_response
154 142
       gzipped_response(200, '')
155 143
     end
156 144
 
157  
-    def delete_customer_with_id(id)
158  
-      FakeBraintree.registry.customers[id] = nil
  145
+    def response_for_created_customer(hash)
  146
+      gzipped_response(201, hash.to_xml(:root => 'customer'))
159 147
     end
160 148
 
161 149
     def response_for_updated_customer(hash)
@@ -170,6 +158,10 @@ def response_for_customer_not_found
170 158
       failure_response(404)
171 159
     end
172 160
 
  161
+    def failure_response(code)
  162
+      gzipped_response(code, FakeBraintree.failure_response(credit_card_number).to_xml(:root => 'api_error_response'))
  163
+    end
  164
+
173 165
     def customer_id
174 166
       @customer_hash["id"]
175 167
     end
@@ -181,5 +173,14 @@ def has_credit_card?
181 173
     def credit_card_hash
182 174
       @customer_hash["credit_card"] || {}
183 175
     end
  176
+
  177
+    def credit_card_token(hash)
  178
+      md5("#{hash['merchant_id']}#{hash['id']}")
  179
+    end
  180
+
  181
+    def last_four(hash)
  182
+      hash["credit_card"].delete("number")[-4..-1]
  183
+    end
  184
+
184 185
   end
185 186
 end

0 notes on commit e775167

Please sign in to comment.
Something went wrong with that request. Please try again.