Skip to content

Commit

Permalink
Make the abstraction clearer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Berke-Williams committed Jan 13, 2012
1 parent c6cead6 commit ae86ebe
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions lib/fake_braintree/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ def customer_hash
if !hash["credit_card"].empty?
hash["credit_card"]["last_4"] = last_four(hash)
hash["credit_card"]["token"] = credit_card_token(hash)
split_expiration_date_into_month_and_year!(hash)

if credit_card_expiration_month
hash["credit_card"]["expiration_month"] = credit_card_expiration_month
end

if credit_card_expiration_year
hash["credit_card"]["expiration_year"] = credit_card_expiration_year
end

credit_card = hash.delete("credit_card")
hash["credit_cards"] = [credit_card]
Expand All @@ -58,13 +65,6 @@ def invalid?
credit_card_is_failure? || invalid_credit_card?
end

def split_expiration_date_into_month_and_year!(hash)
if expiration_date = hash["credit_card"].delete("expiration_date")
hash["credit_card"]["expiration_month"] = expiration_date.split('/')[0]
hash["credit_card"]["expiration_year"] = expiration_date.split('/')[1]
end
end

def existing_customer_hash
existing_customer_id && FakeBraintree.registry.customers[existing_customer_id]
end
Expand Down Expand Up @@ -142,5 +142,22 @@ def create_credit_card_with(hash)
def add_credit_card_to_registry(credit_card_hash)
FakeBraintree.registry.credit_cards[credit_card_hash["token"]] = credit_card_hash
end

def credit_card_expiration_date
credit_card_hash = @customer_hash["credit_card"]
if credit_card_hash && credit_card_hash.key?("expiration_date")
credit_card_hash["expiration_date"].split('/')
else
[]
end
end

def credit_card_expiration_month
credit_card_expiration_date[0]
end

def credit_card_expiration_year
credit_card_expiration_date[1]
end
end
end

0 comments on commit ae86ebe

Please sign in to comment.