Class: Square::Locations::Transactions::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



10
11
12
# File 'lib/square/locations/transactions/client.rb', line 10

def initialize(client:)
  @client = client
end

Instance Method Details

#capture(request_options: {}, **params) ⇒ Square::Types::CaptureTransactionResponse

Captures a transaction that was created with the [Charge](api-endpoint:Transactions-Charge) endpoint with a ‘delay_capture` value of `true`.

See [Delayed capture transactions](developer.squareup.com/docs/payments/transactions/overview#delayed-capture) for more information.

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):

  • :location_id (String)
  • :transaction_id (String)

Returns:



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/square/locations/transactions/client.rb', line 120

def capture(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/locations/#{params[:location_id]}/transactions/#{params[:transaction_id]}/capture",
    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::CaptureTransactionResponse.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::GetTransactionResponse

Retrieves details for a single transaction.

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):

  • :location_id (String)
  • :transaction_id (String)

Returns:



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/square/locations/transactions/client.rb', line 79

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/locations/#{params[:location_id]}/transactions/#{params[:transaction_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::GetTransactionResponse.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::ListTransactionsResponse

Lists transactions for a particular location.

Transactions include payment information from sales and exchanges and refund information from returns and exchanges.

Max results per [page](developer.squareup.com/docs/working-with-apis/pagination): 50

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):

  • :location_id (String)
  • :begin_time (String, nil)
  • :end_time (String, nil)
  • :sort_order (Square::Types::SortOrder, nil)
  • :cursor (String, nil)

Returns:



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/locations/transactions/client.rb', line 35

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

  request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "v2/locations/#{params[:location_id]}/transactions",
    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::ListTransactionsResponse.load(response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#void(request_options: {}, **params) ⇒ Square::Types::VoidTransactionResponse

Cancels a transaction that was created with the [Charge](api-endpoint:Transactions-Charge) endpoint with a ‘delay_capture` value of `true`.

See [Delayed capture transactions](developer.squareup.com/docs/payments/transactions/overview#delayed-capture) for more information.

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):

  • :location_id (String)
  • :transaction_id (String)

Returns:



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/square/locations/transactions/client.rb', line 161

def void(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/locations/#{params[:location_id]}/transactions/#{params[:transaction_id]}/void",
    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::VoidTransactionResponse.load(response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end