Class: FakeBraintree::Customer

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

Instance Method Summary collapse

Methods included from Helpers

#create_id, #gzip, #gzipped_response, #md5

Constructor Details

#initialize(customer_hash_from_params, options) ⇒ Customer

Returns a new instance of Customer.



5
6
7
8
9
10
11
12
13
# File 'lib/fake_braintree/customer.rb', line 5

def initialize(customer_hash_from_params, options)
  @customer_hash = {
    'id' => options[:id],
    'merchant_id' => options[:merchant_id],
    'addresses' => []
  }
  @customer_hash.merge!(customer_hash_from_params)
  set_customer_id
end

Instance Method Details

#createObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fake_braintree/customer.rb', line 15

def create
  if invalid?
    response_for_invalid_card
  else
    credit_cards = customer_hash['credit_cards']
    create_customer_with(customer_hash)
    credit_cards.each { |card| add_credit_card_to_registry(card) }
    set_default_credit_card credit_cards.first
    response_for_created_customer(customer_hash)
  end
end

#deleteObject



41
42
43
44
# File 'lib/fake_braintree/customer.rb', line 41

def delete
  delete_customer_with_id(customer_id)
  deletion_response
end

#updateObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fake_braintree/customer.rb', line 27

def update
  if customer_exists_in_registry?
    if credit_card_is_failure?
      response_for_invalid_card
    else
      updates = customer_hash
      updated_customer = update_existing_customer(updates)
      response_for_updated_customer(updated_customer)
    end
  else
    response_for_customer_not_found
  end
end