Class: Square::BankAccounts::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



9
10
11
# File 'lib/square/bank_accounts/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#create_bank_account(request_options: {}, **params) ⇒ Square::Types::CreateBankAccountResponse

Store a bank account on file for a square account

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



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/bank_accounts/client.rb', line 77

def (request_options: {}, **params)
  params = Square::Internal::Types::Utils.normalize_keys(params)
  request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "v2/bank-accounts",
    body: Square::BankAccounts::Types::CreateBankAccountRequest.new(params).to_h,
    request_options: request_options
  )
  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::CreateBankAccountResponse.load(response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#disable_bank_account(request_options: {}, **params) ⇒ Square::Types::DisableBankAccountResponse

Disable a bank account.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :bank_account_id (String)

Returns:



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/square/bank_accounts/client.rb', line 180

def (request_options: {}, **params)
  params = Square::Internal::Types::Utils.normalize_keys(params)
  request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "v2/bank-accounts/#{params[:bank_account_id]}/disable",
    request_options: request_options
  )
  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::DisableBankAccountResponse.load(response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

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

Retrieve details of a [BankAccount](entity:BankAccount) bank account linked to a Square account.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :bank_account_id (String)

Returns:



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/square/bank_accounts/client.rb', line 146

def get(request_options: {}, **params)
  params = Square::Internal::Types::Utils.normalize_keys(params)
  request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "v2/bank-accounts/#{params[:bank_account_id]}",
    request_options: request_options
  )
  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::GetBankAccountResponse.load(response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get_by_v_1_id(request_options: {}, **params) ⇒ Square::Types::GetBankAccountByV1IdResponse

Returns details of a [BankAccount](entity:BankAccount) identified by V1 bank account ID.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :v_1_bank_account_id (String)

Returns:



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/square/bank_accounts/client.rb', line 112

def get_by_v_1_id(request_options: {}, **params)
  params = Square::Internal::Types::Utils.normalize_keys(params)
  request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "v2/bank-accounts/by-v1-id/#{params[:v_1_bank_account_id]}",
    request_options: request_options
  )
  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::GetBankAccountByV1IdResponse.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::ListBankAccountsResponse

Returns a list of [BankAccount](entity:BankAccount) objects linked to a Square account.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :cursor (String, nil)
  • :limit (Integer, nil)
  • :location_id (String, nil)
  • :customer_id (String, nil)

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/square/bank_accounts/client.rb', line 28

def list(request_options: {}, **params)
  params = Square::Internal::Types::Utils.normalize_keys(params)
  query_param_names = %i[cursor limit location_id customer_id]
  query_params = {}
  query_params["cursor"] = params[:cursor] if params.key?(:cursor)
  query_params["limit"] = params[:limit] if params.key?(:limit)
  query_params["location_id"] = params[:location_id] if params.key?(:location_id)
  query_params["customer_id"] = params[:customer_id] if params.key?(:customer_id)
  params.except(*query_param_names)

  Square::Internal::CursorItemIterator.new(
    cursor_field: :cursor,
    item_field: :bank_accounts,
    initial_cursor: query_params[:cursor]
  ) do |next_cursor|
    query_params[:cursor] = next_cursor
    request = Square::Internal::JSON::Request.new(
      base_url: request_options[:base_url],
      method: "GET",
      path: "v2/bank-accounts",
      query: query_params,
      request_options: request_options
    )
    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::ListBankAccountsResponse.load(response.body)
    else
      error_class = Square::Errors::ResponseError.subclass_for_code(code)
      raise error_class.new(response.body, code: code)
    end
  end
end