Module: StripeMock::RequestHandlers::Recipients

Included in:
Instance
Defined in:
lib/stripe_mock/request_handlers/recipients.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



5
6
7
8
9
# File 'lib/stripe_mock/request_handlers/recipients.rb', line 5

def Recipients.included(klass)
  klass.add_handler 'post /v1/recipients',            :new_recipient
  klass.add_handler 'post /v1/recipients/(.*)',       :update_recipient
  klass.add_handler 'get /v1/recipients/(.*)',        :get_recipient
end

Instance Method Details

#get_recipient(route, method_url, params, headers) ⇒ Object



42
43
44
45
# File 'lib/stripe_mock/request_handlers/recipients.rb', line 42

def get_recipient(route, method_url, params, headers)
  route =~ method_url
  assert_existance :recipient, $1, recipients[$1]
end

#new_recipient(route, method_url, params, headers) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/stripe_mock/request_handlers/recipients.rb', line 11

def new_recipient(route, method_url, params, headers)
  params[:id] ||= new_id('rp')
  cards = []

  if params[:bank_account]
    params[:active_account] = get_bank_by_token(params.delete(:bank_account))
  end

  if params[:card]
    cards << get_card_by_token(params.delete(:card))
    params[:default_card] = cards.first[:id]
  end

  recipients[ params[:id] ] = Data.mock_recipient(cards, params)
  recipients[ params[:id] ]
end

#update_recipient(route, method_url, params, headers) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/stripe_mock/request_handlers/recipients.rb', line 28

def update_recipient(route, method_url, params, headers)
  route =~ method_url
  recipient = assert_existance :recipient, $1, recipients[$1]
  recipient.merge!(params)

  if params[:card]
    new_card = get_card_by_token(params.delete(:card))
    add_card_to_object(:recipient, new_card, recipient, true)
    recipient[:default_card] = new_card[:id]
  end

  recipient
end