Class: Square::PaymentsApi

Inherits:
BaseApi
  • Object
show all
Defined in:
lib/square/api/payments_api.rb

Overview

PaymentsApi

Instance Attribute Summary

Attributes inherited from BaseApi

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseApi

#execute_request, #get_user_agent, #validate_parameters

Constructor Details

#initialize(config, http_call_back: nil) ⇒ PaymentsApi

Returns a new instance of PaymentsApi.



4
5
6
# File 'lib/square/api/payments_api.rb', line 4

def initialize(config, http_call_back: nil)
  super(config, http_call_back: http_call_back)
end

Instance Method Details

#cancel_payment(payment_id:) ⇒ CancelPaymentResponse Hash

Cancels (voids) a payment. You can use this endpoint to cancel a payment with the APPROVED ‘status`. cancel.

Parameters:

  • payment_id (String)

    Required parameter: The ID of the payment to

Returns:

  • (CancelPaymentResponse Hash)

    response from the API call



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/square/api/payments_api.rb', line 261

def cancel_payment(payment_id:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/payments/{payment_id}/cancel'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'payment_id' => { 'value' => payment_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#cancel_payment_by_idempotency_key(body:) ⇒ CancelPaymentByIdempotencyKeyResponse Hash

Cancels (voids) a payment identified by the idempotency key that is specified in the request. Use this method when the status of a ‘CreatePayment` request is unknown (for example, after you send a `CreatePayment` request, a network error occurs and you do not get a response). In this case, you can direct Square to cancel the payment using this endpoint. In the request, you provide the same idempotency key that you provided in your `CreatePayment` request that you want to cancel. After canceling the payment, you can submit your `CreatePayment` request again. Note that if no payment with the specified idempotency key is found, no action is taken and the endpoint returns successfully. object containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • body (CancelPaymentByIdempotencyKeyRequest)

    Required parameter: An

Returns:

  • (CancelPaymentByIdempotencyKeyResponse Hash)

    response from the API call



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/square/api/payments_api.rb', line 149

def cancel_payment_by_idempotency_key(body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/payments/cancel'
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#complete_payment(payment_id:, body:) ⇒ CompletePaymentResponse Hash

Completes (captures) a payment. By default, payments are set to complete immediately after they are created. You can use this endpoint to complete a payment with the APPROVED ‘status`. the payment to be completed. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • payment_id (String)

    Required parameter: The unique ID identifying

  • body (CompletePaymentRequest)

    Required parameter: An object

Returns:

  • (CompletePaymentResponse Hash)

    response from the API call



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/square/api/payments_api.rb', line 303

def complete_payment(payment_id:,
                     body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/payments/{payment_id}/complete'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'payment_id' => { 'value' => payment_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#create_payment(body:) ⇒ CreatePaymentResponse Hash

Creates a payment using the provided source. You can use this endpoint to charge a card (credit/debit card or Square gift card) or record a payment that the seller received outside of Square (cash payment from a buyer or a payment that an external entity processed on behalf of the seller). The endpoint creates a ‘Payment` object and returns it in the response. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • body (CreatePaymentRequest)

    Required parameter: An object

Returns:

  • (CreatePaymentResponse Hash)

    response from the API call



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/square/api/payments_api.rb', line 101

def create_payment(body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/payments'
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#get_payment(payment_id:) ⇒ GetPaymentResponse Hash

Retrieves details for a specific payment. payment.

Parameters:

  • payment_id (String)

    Required parameter: A unique ID for the desired

Returns:

  • (GetPaymentResponse Hash)

    response from the API call



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/square/api/payments_api.rb', line 182

def get_payment(payment_id:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/payments/{payment_id}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'payment_id' => { 'value' => payment_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#list_payments(begin_time: nil, end_time: nil, sort_order: nil, cursor: nil, location_id: nil, total: nil, last_4: nil, card_brand: nil, limit: nil) ⇒ ListPaymentsResponse Hash

Retrieves a list of payments taken by the account making the request. Results are eventually consistent, and new payments or changes to payments might take several seconds to appear. The maximum results per page is 100. beginning of the reporting period, in RFC 3339 format. Inclusive. Default: The current time minus one year. the reporting period, in RFC 3339 format. Default: The current time. are listed: - ‘ASC` - Oldest to newest. - `DESC` - Newest to oldest (default). a previous call to this endpoint. Provide this cursor to retrieve the next set of results for the original query. For more information, see [Pagination](developer.squareup.com/docs/basics/api101/pagination) . location supplied. By default, results are returned for the default (main) location associated with the seller. `total_money` for a payment. payment card. card (for example, VISA). to be returned in a single page. It is possible to receive fewer results than the specified limit on a given page. The default value of 100 is also the maximum allowed value. If the provided value is greater than 100, it is ignored and the default value is used instead. Default: `100`

Parameters:

  • begin_time (String) (defaults to: nil)

    Optional parameter: The timestamp for the

  • end_time (String) (defaults to: nil)

    Optional parameter: The timestamp for the end of

  • sort_order (String) (defaults to: nil)

    Optional parameter: The order in which results

  • cursor (String) (defaults to: nil)

    Optional parameter: A pagination cursor returned by

  • location_id (String) (defaults to: nil)

    Optional parameter: Limit results to the

  • total (Long) (defaults to: nil)

    Optional parameter: The exact amount in the

  • last_4 (String) (defaults to: nil)

    Optional parameter: The last four digits of a

  • card_brand (String) (defaults to: nil)

    Optional parameter: The brand of the payment

  • limit (Integer) (defaults to: nil)

    Optional parameter: The maximum number of results

Returns:

  • (ListPaymentsResponse Hash)

    response from the API call



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/square/api/payments_api.rb', line 42

def list_payments(begin_time: nil,
                  end_time: nil,
                  sort_order: nil,
                  cursor: nil,
                  location_id: nil,
                  total: nil,
                  last_4: nil,
                  card_brand: nil,
                  limit: nil)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/payments'
  _query_builder = APIHelper.append_url_with_query_parameters(
    _query_builder,
    'begin_time' => begin_time,
    'end_time' => end_time,
    'sort_order' => sort_order,
    'cursor' => cursor,
    'location_id' => location_id,
    'total' => total,
    'last_4' => last_4,
    'card_brand' => card_brand,
    'limit' => limit
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#update_payment(payment_id:, body:) ⇒ UpdatePaymentResponse Hash

Updates a payment with the APPROVED status. You can update the ‘amount_money` and `tip_money` using this endpoint. update. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • payment_id (String)

    Required parameter: The ID of the payment to

  • body (UpdatePaymentRequest)

    Required parameter: An object

Returns:

  • (UpdatePaymentResponse Hash)

    response from the API call



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/square/api/payments_api.rb', line 221

def update_payment(payment_id:,
                   body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/payments/{payment_id}'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'payment_id' => { 'value' => payment_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.put(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end