Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Berke-Williams committed Nov 3, 2011
1 parent d7811aa commit 2aaf85c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/fake_braintree/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ def failure_response

def customer_hash
hash = @request_hash.dup
hash["id"] ||= md5("#{@merchant_id}#{Time.now.to_f}")
hash["id"] ||= create_id
hash["merchant-id"] = @merchant_id
if hash["credit_card"] && hash["credit_card"].is_a?(Hash)
hash["credit_card"].delete("__content__")
if !hash["credit_card"].empty?
hash["credit_card"]["last_4"] = hash["credit_card"].delete("number")[-4..-1]
hash["credit_card"]["token"] = md5("#{hash['merchant_id']}#{hash['id']}#{Time.now.to_f}")
hash["credit_card"]["token"] = md5("#{hash['merchant_id']}#{hash['id']}")
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]
Expand All @@ -38,6 +38,10 @@ def customer_hash

private

def create_id
md5("#{@merchant_id}#{Time.now.to_f}")
end

def credit_card_is_failure?
FakeBraintree.failure?(@request_hash["credit_card"]["number"])
end
Expand Down
3 changes: 1 addition & 2 deletions lib/fake_braintree/sinatra_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def md5(content)
end

delete "/merchants/:merchant_id/customers/:id" do
FakeBraintree.customers[params["id"]] = nil
FakeBraintree.customers[params[:id]] = nil
gzipped_response(200, "")
end

Expand Down Expand Up @@ -111,7 +111,6 @@ def md5(content)

# Braintree::Transaction.search
post "/merchants/:merchant_id/transactions/advanced_search" do
# "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<search>\n <ids type=\"array\">\n <item>49sbx6</item>\n </ids>\n <created-at>\n <min type=\"datetime\">2011-01-10T14:14:26Z</min>\n </created-at>\n</search>\n"
gzipped_response(200, FakeBraintree.generated_transaction.to_xml)
end

Expand Down

0 comments on commit 2aaf85c

Please sign in to comment.