forked from stripe-ruby-mock/stripe-ruby-mock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
payouts.rb
39 lines (32 loc) · 1.35 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
33
34
35
36
37
38
39
module StripeMock
module RequestHandlers
module Payouts
def Payouts.included(klass)
klass.add_handler 'post /v1/payouts', :new_payout
klass.add_handler 'post /v1/payouts/(.*)', :update_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)
params[:id] ||= new_id("po")
unless (params[:amount].is_a?(Integer) && params[:amount].positive?) || (params[:amount].is_a?(String) && /^\d+$/.match(params[:amount]))
raise Stripe::InvalidRequestError.new("Invalid integer: #{params[:amount]}", 'amount', http_status: 400)
end
payouts[params[:id]] = Data.mock_payout(params.merge :id => params[:id])
end
def update_payout(route, method_url, params, headers)
route =~ method_url
assert_existence :payout, $1, payouts[$1]
payouts[$1].merge!(params)
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