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.



7
8
9
# File 'lib/fake_braintree/address.rb', line 7

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

Instance Method Details

#createObject



11
12
13
14
15
16
# File 'lib/fake_braintree/address.rb', line 11

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

#customerObject



18
19
20
# File 'lib/fake_braintree/address.rb', line 18

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

#generate_idObject



33
34
35
# File 'lib/fake_braintree/address.rb', line 33

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

#idObject



37
38
39
# File 'lib/fake_braintree/address.rb', line 37

def id
  @address['id']
end

#response_for_updated_addressObject



22
23
24
# File 'lib/fake_braintree/address.rb', line 22

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

#set_up_address(address_hash_from_params, options) ⇒ Object



26
27
28
29
30
31
# File 'lib/fake_braintree/address.rb', line 26

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