Class: FakeBraintree::Address

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/fake_braintree/address.rb

Instance Method Summary collapse

Methods included from Helpers

#create_id, #gzip, #gzipped_response, #md5

Constructor Details

#initialize(address_hash_from_params, options) ⇒ Address

Returns a new instance of Address.



5
6
7
# File 'lib/fake_braintree/address.rb', line 5

def initialize(address_hash_from_params, options)
  set_up_address(address_hash_from_params, options)
end

Instance Method Details

#createObject



9
10
11
12
13
14
# File 'lib/fake_braintree/address.rb', line 9

def create
  @address['id'] = generate_id
  FakeBraintree.registry.addresses[id] = @address
  customer['addresses'] << @address
  response_for_updated_address
end

#customerObject



16
17
18
# File 'lib/fake_braintree/address.rb', line 16

def customer
  FakeBraintree.registry.customers[@address['customer_id']]
end

#generate_idObject



31
32
33
# File 'lib/fake_braintree/address.rb', line 31

def generate_id
  "#{@address['customer_id']}_#{customer['addresses'].size}"
end

#idObject



35
36
37
# File 'lib/fake_braintree/address.rb', line 35

def id
  @address['id']
end

#response_for_updated_addressObject



20
21
22
# File 'lib/fake_braintree/address.rb', line 20

def response_for_updated_address
  gzipped_response(200, @address.to_xml(root: 'address'))
end

#set_up_address(address_hash_from_params, options) ⇒ Object



24
25
26
27
28
29
# File 'lib/fake_braintree/address.rb', line 24

def set_up_address(address_hash_from_params, options)
  @address = {
    "merchant_id" => options[:merchant_id],
    "customer_id" => options[:customer_id],
  }.merge(address_hash_from_params)
end