Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make the abstraction clearer.

  • Loading branch information...
commit ae86ebec055e2d73b56c58ba2b8d77e24b61a74c 1 parent c6cead6
@gabebw gabebw authored
Showing with 25 additions and 8 deletions.
  1. +25 −8 lib/fake_braintree/customer.rb
View
33 lib/fake_braintree/customer.rb
@@ -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]
@@ -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
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.