Class: Square::Payouts::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/square/payouts/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Square::Payouts::Client



7
8
9
# File 'lib/square/payouts/client.rb', line 7

def initialize(client:)
  @client = client
end

Instance Method Details

#get(request_options: {}, **params) ⇒ Square::Types::GetPayoutResponse

Retrieves details of a specific payout identified by a payout ID. To call this endpoint, set ‘PAYOUTS_READ` for the OAuth scope.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/square/payouts/client.rb', line 48

def get(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "GET",
    path: "v2/payouts/#{params[:payout_id]}"
  )
  begin
    _response = @client.send(_request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = _response.code.to_i
  if code.between?(200, 299)
    Square::Types::GetPayoutResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end

#list(request_options: {}, **params) ⇒ Square::Types::ListPayoutsResponse

Retrieves a list of all payouts for the default location. You can filter payouts by location ID, status, time range, and order them in ascending or descending order. To call this endpoint, set ‘PAYOUTS_READ` for the OAuth scope.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/square/payouts/client.rb', line 16

def list(request_options: {}, **params)
  _query_param_names = [
    %w[location_id status begin_time end_time sort_order cursor limit],
    %i[location_id status begin_time end_time sort_order cursor limit]
  ].flatten
  _query = params.slice(*_query_param_names)
  params.except(*_query_param_names)

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "GET",
    path: "v2/payouts",
    query: _query
  )
  begin
    _response = @client.send(_request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = _response.code.to_i
  if code.between?(200, 299)
    Square::Types::ListPayoutsResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end

#list_entries(request_options: {}, **params) ⇒ Square::Types::ListPayoutEntriesResponse

Retrieves a list of all payout entries for a specific payout. To call this endpoint, set ‘PAYOUTS_READ` for the OAuth scope.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/square/payouts/client.rb', line 72

def list_entries(request_options: {}, **params)
  _query_param_names = [
    %w[sort_order cursor limit],
    %i[sort_order cursor limit]
  ].flatten
  _query = params.slice(*_query_param_names)
  params = params.except(*_query_param_names)

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "GET",
    path: "v2/payouts/#{params[:payout_id]}/payout-entries",
    query: _query
  )
  begin
    _response = @client.send(_request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = _response.code.to_i
  if code.between?(200, 299)
    Square::Types::ListPayoutEntriesResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end