Class: FakeBraintree::Customer
- Inherits:
-
Object
- Object
- FakeBraintree::Customer
show all
- Includes:
- Helpers
- Defined in:
- lib/fake_braintree/customer.rb
Instance Method Summary
collapse
Methods included from Helpers
#gzip, #gzipped_response, #md5
Constructor Details
#initialize(request, merchant_id) ⇒ Customer
Returns a new instance of Customer.
5
6
7
8
|
# File 'lib/fake_braintree/customer.rb', line 5
def initialize(request, merchant_id)
@request_hash = Hash.from_xml(request.body).delete("customer")
@merchant_id = merchant_id
end
|
Instance Method Details
#customer_hash ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/fake_braintree/customer.rb', line 18
def customer_hash
hash = @request_hash.dup
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']}")
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]
credit_card = hash.delete("credit_card")
hash["credit_cards"] = [credit_card]
end
end
hash
end
|
#failure_response ⇒ Object
14
15
16
|
# File 'lib/fake_braintree/customer.rb', line 14
def failure_response
gzipped_response(422, FakeBraintree.failure_response(@request_hash["credit_card"]["number"]).to_xml(:root => 'api_error_response'))
end
|
#invalid? ⇒ Boolean
10
11
12
|
# File 'lib/fake_braintree/customer.rb', line 10
def invalid?
credit_card_is_failure? || invalid_credit_card?
end
|