Module: StripeMock::RequestHandlers::Accounts

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

Constant Summary collapse

VALID_START_YEAR =
2009

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/stripe_mock/request_handlers/accounts.rb', line 6

def Accounts.included(klass)
  klass.add_handler 'post /v1/accounts',      :new_account
  klass.add_handler 'get /v1/account',        :get_account
  klass.add_handler 'get /v1/accounts/(.*)',  :get_account
  klass.add_handler 'post /v1/accounts/(.*)', :update_account
  klass.add_handler 'get /v1/accounts',       :list_accounts
  klass.add_handler 'post /oauth/deauthorize',:deauthorize
end

Instance Method Details

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



45
46
47
48
49
# File 'lib/stripe_mock/request_handlers/accounts.rb', line 45

def deauthorize(route, method_url, params, headers)
  
  route =~ method_url
  Stripe::StripeObject.construct_from(:stripe_user_id => params[:stripe_user_id])
end

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



21
22
23
24
25
26
# File 'lib/stripe_mock/request_handlers/accounts.rb', line 21

def (route, method_url, params, headers)
  route =~ method_url
  
  id = $1 || accounts.keys[0]
  assert_existence :account, id, accounts[id]
end

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



40
41
42
43
# File 'lib/stripe_mock/request_handlers/accounts.rb', line 40

def list_accounts(route, method_url, params, headers)
  
  Data.mock_list_object(accounts.values, params)
end

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



15
16
17
18
19
# File 'lib/stripe_mock/request_handlers/accounts.rb', line 15

def (route, method_url, params, headers)
  params[:id] ||= new_id('acct')
  route =~ method_url
  accounts[params[:id]] ||= Data.(params)
end

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



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

def (route, method_url, params, headers)
  route =~ method_url
   = assert_existence :account, $1, accounts[$1]
  .merge!(params)
  if blank_value?(params[:tos_acceptance], :date)
    raise Stripe::InvalidRequestError.new("Invalid integer: ", "tos_acceptance[date]", http_status: 400)
  elsif params[:tos_acceptance] && params[:tos_acceptance][:date]
    validate_acceptance_date(params[:tos_acceptance][:date])
  end
  
end