Class: PayjpMock::Response::Resource::Customer

Inherits:
Base
  • Object
show all
Defined in:
lib/payjp_mock/response/resource/customer.rb

Constant Summary collapse

PREFIX =
'cus'.freeze
OBJECT =
'customer'.freeze

Instance Attribute Summary

Attributes inherited from Base

#attributes

Instance Method Summary collapse

Methods inherited from Base

#initialize, #set, #status

Methods included from Util

#generate_fingerprint, #generate_resource_id

Methods inherited from Base

#body, #exception, #status, #to_h

Constructor Details

This class inherits a constructor from PayjpMock::Response::Resource::Base

Instance Method Details

#canonicalize(key, value) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/payjp_mock/response/resource/customer.rb', line 24

def canonicalize(key, value)
  case key
  when :card
    cards = Response::List.new("/customers/#{@attributes[:id]}/cards", count: 1) do
      Card.new(value.is_a?(Hash) ? value : {})
    end
    { cards: cards.to_h, default_card: cards.attributes[:data][0][:id] }
  when :default_card
    cards = Response::List.new("/customers/#{@attributes[:id]}/cards", count: 1) do
      Card.new(id: value)
    end
    { cards: cards.to_h, default_card: value }
  else
    super
  end
end

#default_attributesObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/payjp_mock/response/resource/customer.rb', line 7

def default_attributes
  id = generate_resource_id(PREFIX)

  {
    cards:         Response::List.new("/customers/#{id}/cards").to_h,
    created:       Time.now.to_i,
    default_card:  nil,
    description:   'test',
    email:         nil,
    id:            id,
    livemode:      false,
    metadata:      nil,
    object:        OBJECT,
    subscriptions: Response::List.new("/customers/#{id}/subscriptions").to_h
  }
end