Skip to content

Commit

Permalink
Higher-level code goes first. Better variable names.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Berke-Williams committed Jan 13, 2012
1 parent a72e31b commit e775167
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions lib/fake_braintree/customer.rb
Expand Up @@ -2,11 +2,11 @@ module FakeBraintree
class Customer
include Helpers

def initialize(customer_hash, options)
def initialize(customer_hash_from_params, options)
@customer_hash = {
"id" => options[:id],
"id" => options[:id],
"merchant_id" => options[:merchant_id]
}.merge(customer_hash)
}.merge(customer_hash_from_params)
end

def create
Expand Down Expand Up @@ -81,18 +81,6 @@ def customer_from_registry
FakeBraintree.registry.customers[customer_id]
end

def credit_card_token(hash)
md5("#{hash['merchant_id']}#{hash['id']}")
end

def last_four(hash)
hash["credit_card"].delete("number")[-4..-1]
end

def failure_response(code)
gzipped_response(code, FakeBraintree.failure_response(credit_card_number).to_xml(:root => 'api_error_response'))
end

def credit_card_is_failure?
has_credit_card? && FakeBraintree.failure?(credit_card_hash["number"])
end
Expand Down Expand Up @@ -121,10 +109,6 @@ def credit_card_number
credit_card_hash["number"]
end

def response_for_created_customer(hash)
gzipped_response(201, hash.to_xml(:root => 'customer'))
end

def create_customer_with(hash)
FakeBraintree.registry.customers[hash["id"]] = hash
end
Expand All @@ -134,6 +118,14 @@ def add_credit_card_to_registry(new_credit_card_hash)
FakeBraintree.registry.credit_cards[token] = new_credit_card_hash
end

def credit_card_expiration_month
credit_card_expiration_date[0]
end

def credit_card_expiration_year
credit_card_expiration_date[1]
end

def credit_card_expiration_date
if credit_card_hash.key?("expiration_date")
credit_card_hash["expiration_date"].split('/')
Expand All @@ -142,20 +134,16 @@ def credit_card_expiration_date
end
end

def credit_card_expiration_month
credit_card_expiration_date[0]
end

def credit_card_expiration_year
credit_card_expiration_date[1]
def delete_customer_with_id(id)
FakeBraintree.registry.customers[id] = nil
end

def deletion_response
gzipped_response(200, '')
end

def delete_customer_with_id(id)
FakeBraintree.registry.customers[id] = nil
def response_for_created_customer(hash)
gzipped_response(201, hash.to_xml(:root => 'customer'))
end

def response_for_updated_customer(hash)
Expand All @@ -170,6 +158,10 @@ def response_for_customer_not_found
failure_response(404)
end

def failure_response(code)
gzipped_response(code, FakeBraintree.failure_response(credit_card_number).to_xml(:root => 'api_error_response'))
end

def customer_id
@customer_hash["id"]
end
Expand All @@ -181,5 +173,14 @@ def has_credit_card?
def credit_card_hash
@customer_hash["credit_card"] || {}
end

def credit_card_token(hash)
md5("#{hash['merchant_id']}#{hash['id']}")
end

def last_four(hash)
hash["credit_card"].delete("number")[-4..-1]
end

end
end

0 comments on commit e775167

Please sign in to comment.