forked from stripe-ruby-mock/stripe-ruby-mock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
payouts.rb
32 lines (26 loc) · 1.04 KB
/
payouts.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module StripeMock
module RequestHandlers
module Payouts
def Payouts.included(klass)
klass.add_handler 'post /v1/payouts', :new_payout
klass.add_handler 'get /v1/payouts', :list_payouts
klass.add_handler 'get /v1/payouts/(.*)', :get_payout
end
def new_payout(route, method_url, params, headers)
id = new_id('po')
unless params[:amount].is_a?(Integer) || (params[:amount].is_a?(String) && /^\d+$/.match(params[:amount]))
raise Stripe::InvalidRequestError.new("Invalid integer: #{params[:amount]}", 'amount', http_status: 400)
end
payouts[id] = Data.mock_payout(params.merge :id => id)
end
def list_payouts(route, method_url, params, headers)
Data.mock_list_object(payouts.clone.values, params)
end
def get_payout(route, method_url, params, headers)
route =~ method_url
assert_existence :payout, $1, payouts[$1]
payouts[$1] ||= Data.mock_payout(:id => $1)
end
end
end
end