square.rb 3.3.0.20191217

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +10 -0
  3. data/README.md +285 -0
  4. data/lib/square/api/apple_pay_api.rb +50 -0
  5. data/lib/square/api/base_api.rb +43 -0
  6. data/lib/square/api/cash_drawers_api.rb +150 -0
  7. data/lib/square/api/catalog_api.rb +545 -0
  8. data/lib/square/api/checkout_api.rb +49 -0
  9. data/lib/square/api/customers_api.rb +327 -0
  10. data/lib/square/api/employees_api.rb +86 -0
  11. data/lib/square/api/inventory_api.rb +295 -0
  12. data/lib/square/api/labor_api.rb +553 -0
  13. data/lib/square/api/locations_api.rb +146 -0
  14. data/lib/square/api/merchants_api.rb +82 -0
  15. data/lib/square/api/mobile_authorization_api.rb +52 -0
  16. data/lib/square/api/o_auth_api.rb +163 -0
  17. data/lib/square/api/orders_api.rb +266 -0
  18. data/lib/square/api/payments_api.rb +277 -0
  19. data/lib/square/api/refunds_api.rb +144 -0
  20. data/lib/square/api/reporting_api.rb +138 -0
  21. data/lib/square/api/transactions_api.rb +377 -0
  22. data/lib/square/api/v1_employees_api.rb +715 -0
  23. data/lib/square/api/v1_items_api.rb +2046 -0
  24. data/lib/square/api/v1_locations_api.rb +83 -0
  25. data/lib/square/api/v1_transactions_api.rb +568 -0
  26. data/lib/square/api_helper.rb +276 -0
  27. data/lib/square/client.rb +156 -0
  28. data/lib/square/configuration.rb +93 -0
  29. data/lib/square/exceptions/api_exception.rb +15 -0
  30. data/lib/square/http/api_response.rb +45 -0
  31. data/lib/square/http/auth/o_auth2.rb +12 -0
  32. data/lib/square/http/faraday_client.rb +59 -0
  33. data/lib/square/http/http_call_back.rb +19 -0
  34. data/lib/square/http/http_client.rb +99 -0
  35. data/lib/square/http/http_method_enum.rb +8 -0
  36. data/lib/square/http/http_request.rb +45 -0
  37. data/lib/square/http/http_response.rb +24 -0
  38. data/lib/square.rb +49 -0
  39. data/spec/user_journey_spec.rb +145 -0
  40. data/test/api/api_test_base.rb +24 -0
  41. data/test/api/test_catalog_api.rb +59 -0
  42. data/test/api/test_customers_api.rb +45 -0
  43. data/test/api/test_employees_api.rb +36 -0
  44. data/test/api/test_labor_api.rb +74 -0
  45. data/test/api/test_locations_api.rb +35 -0
  46. data/test/api/test_merchants_api.rb +40 -0
  47. data/test/api/test_payments_api.rb +42 -0
  48. data/test/api/test_refunds_api.rb +41 -0
  49. data/test/http_response_catcher.rb +19 -0
  50. data/test/test_helper.rb +94 -0
  51. metadata +190 -0
@@ -0,0 +1,377 @@
1
+ module Square
2
+ # TransactionsApi
3
+ class TransactionsApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Lists refunds for one of a business's locations.
9
+ # Deprecated - recommend using [SearchOrders](#endpoint-orders-searchorders)
10
+ # In addition to full or partial tender refunds processed through Square
11
+ # APIs,
12
+ # refunds may result from itemized returns or exchanges through Square's
13
+ # Point of Sale applications.
14
+ # Refunds with a `status` of `PENDING` are not currently included in this
15
+ # endpoint's response.
16
+ # Max results per [page](#paginatingresults): 50
17
+ # @param [String] location_id Required parameter: The ID of the location to
18
+ # list refunds for.
19
+ # @param [String] begin_time Optional parameter: The beginning of the
20
+ # requested reporting period, in RFC 3339 format. See [Date
21
+ # ranges](#dateranges) for details on date inclusivity/exclusivity. Default
22
+ # value: The current time minus one year.
23
+ # @param [String] end_time Optional parameter: The end of the requested
24
+ # reporting period, in RFC 3339 format. See [Date ranges](#dateranges) for
25
+ # details on date inclusivity/exclusivity. Default value: The current
26
+ # time.
27
+ # @param [SortOrder] sort_order Optional parameter: The order in which
28
+ # results are listed in the response (`ASC` for oldest first, `DESC` for
29
+ # newest first). Default value: `DESC`
30
+ # @param [String] cursor Optional parameter: A pagination cursor returned by
31
+ # a previous call to this endpoint. Provide this to retrieve the next set of
32
+ # results for your original query. See [Paginating
33
+ # results](#paginatingresults) for more information.
34
+ # @return [ListRefundsResponse Hash] response from the API call
35
+ def list_refunds(location_id:,
36
+ begin_time: nil,
37
+ end_time: nil,
38
+ sort_order: nil,
39
+ cursor: nil)
40
+ warn 'Endpoint list_refunds in TransactionsApi is deprecated'
41
+ # Prepare query url.
42
+ _query_builder = config.get_base_uri
43
+ _query_builder << '/v2/locations/{location_id}/refunds'
44
+ _query_builder = APIHelper.append_url_with_template_parameters(
45
+ _query_builder,
46
+ 'location_id' => location_id
47
+ )
48
+ _query_builder = APIHelper.append_url_with_query_parameters(
49
+ _query_builder,
50
+ 'begin_time' => begin_time,
51
+ 'end_time' => end_time,
52
+ 'sort_order' => sort_order,
53
+ 'cursor' => cursor
54
+ )
55
+ _query_url = APIHelper.clean_url _query_builder
56
+
57
+ # Prepare headers.
58
+ _headers = {
59
+ 'accept' => 'application/json'
60
+ }
61
+
62
+ # Prepare and execute HttpRequest.
63
+ _request = config.http_client.get(
64
+ _query_url,
65
+ headers: _headers
66
+ )
67
+ OAuth2.apply(config, _request)
68
+ _response = execute_request(_request)
69
+
70
+ # Return appropriate response type.
71
+ decoded = APIHelper.json_deserialize(_response.raw_body)
72
+ _errors = APIHelper.map_response(decoded, ['errors'])
73
+ ApiResponse.new(_response, data: decoded, errors: _errors)
74
+ end
75
+
76
+ # Lists transactions for a particular location.
77
+ # Deprecated - recommend using [SearchOrders](#endpoint-orders-searchorders)
78
+ # Transactions include payment information from sales and exchanges and
79
+ # refund
80
+ # information from returns and exchanges.
81
+ # Max results per [page](#paginatingresults): 50
82
+ # @param [String] location_id Required parameter: The ID of the location to
83
+ # list transactions for.
84
+ # @param [String] begin_time Optional parameter: The beginning of the
85
+ # requested reporting period, in RFC 3339 format. See [Date
86
+ # ranges](#dateranges) for details on date inclusivity/exclusivity. Default
87
+ # value: The current time minus one year.
88
+ # @param [String] end_time Optional parameter: The end of the requested
89
+ # reporting period, in RFC 3339 format. See [Date ranges](#dateranges) for
90
+ # details on date inclusivity/exclusivity. Default value: The current
91
+ # time.
92
+ # @param [SortOrder] sort_order Optional parameter: The order in which
93
+ # results are listed in the response (`ASC` for oldest first, `DESC` for
94
+ # newest first). Default value: `DESC`
95
+ # @param [String] cursor Optional parameter: A pagination cursor returned by
96
+ # a previous call to this endpoint. Provide this to retrieve the next set of
97
+ # results for your original query. See [Paginating
98
+ # results](#paginatingresults) for more information.
99
+ # @return [ListTransactionsResponse Hash] response from the API call
100
+ def list_transactions(location_id:,
101
+ begin_time: nil,
102
+ end_time: nil,
103
+ sort_order: nil,
104
+ cursor: nil)
105
+ warn 'Endpoint list_transactions in TransactionsApi is deprecated'
106
+ # Prepare query url.
107
+ _query_builder = config.get_base_uri
108
+ _query_builder << '/v2/locations/{location_id}/transactions'
109
+ _query_builder = APIHelper.append_url_with_template_parameters(
110
+ _query_builder,
111
+ 'location_id' => location_id
112
+ )
113
+ _query_builder = APIHelper.append_url_with_query_parameters(
114
+ _query_builder,
115
+ 'begin_time' => begin_time,
116
+ 'end_time' => end_time,
117
+ 'sort_order' => sort_order,
118
+ 'cursor' => cursor
119
+ )
120
+ _query_url = APIHelper.clean_url _query_builder
121
+
122
+ # Prepare headers.
123
+ _headers = {
124
+ 'accept' => 'application/json'
125
+ }
126
+
127
+ # Prepare and execute HttpRequest.
128
+ _request = config.http_client.get(
129
+ _query_url,
130
+ headers: _headers
131
+ )
132
+ OAuth2.apply(config, _request)
133
+ _response = execute_request(_request)
134
+
135
+ # Return appropriate response type.
136
+ decoded = APIHelper.json_deserialize(_response.raw_body)
137
+ _errors = APIHelper.map_response(decoded, ['errors'])
138
+ ApiResponse.new(_response, data: decoded, errors: _errors)
139
+ end
140
+
141
+ # Charges a card represented by a card nonce or a customer's card on file.
142
+ # Deprecated - recommend using
143
+ # [CreatePayment](#endpoint-payments-createpayment)
144
+ # Your request to this endpoint must include _either_:
145
+ # - A value for the `card_nonce` parameter (to charge a card nonce generated
146
+ # with the `SqPaymentForm`)
147
+ # - Values for the `customer_card_id` and `customer_id` parameters (to
148
+ # charge
149
+ # a customer's card on file)
150
+ # In order for an eCommerce payment to potentially qualify for
151
+ # [Square chargeback protection](https://squareup.com/help/article/5394),
152
+ # you
153
+ # _must_ provide values for the following parameters in your request:
154
+ # - `buyer_email_address`
155
+ # - At least one of `billing_address` or `shipping_address`
156
+ # When this response is returned, the amount of Square's processing fee
157
+ # might not yet be
158
+ # calculated. To obtain the processing fee, wait about ten seconds and call
159
+ # [RetrieveTransaction](#endpoint-retrievetransaction). See the
160
+ # `processing_fee_money`
161
+ # field of each [Tender included](#type-tender) in the transaction.
162
+ # @param [String] location_id Required parameter: The ID of the location to
163
+ # associate the created transaction with.
164
+ # @param [ChargeRequest] body Required parameter: An object containing the
165
+ # fields to POST for the request. See the corresponding object definition
166
+ # for field details.
167
+ # @return [ChargeResponse Hash] response from the API call
168
+ def charge(location_id:,
169
+ body:)
170
+ warn 'Endpoint charge in TransactionsApi is deprecated'
171
+ # Prepare query url.
172
+ _query_builder = config.get_base_uri
173
+ _query_builder << '/v2/locations/{location_id}/transactions'
174
+ _query_builder = APIHelper.append_url_with_template_parameters(
175
+ _query_builder,
176
+ 'location_id' => location_id
177
+ )
178
+ _query_url = APIHelper.clean_url _query_builder
179
+
180
+ # Prepare headers.
181
+ _headers = {
182
+ 'accept' => 'application/json',
183
+ 'content-type' => 'application/json; charset=utf-8'
184
+ }
185
+
186
+ # Prepare and execute HttpRequest.
187
+ _request = config.http_client.post(
188
+ _query_url,
189
+ headers: _headers,
190
+ parameters: body.to_json
191
+ )
192
+ OAuth2.apply(config, _request)
193
+ _response = execute_request(_request)
194
+
195
+ # Return appropriate response type.
196
+ decoded = APIHelper.json_deserialize(_response.raw_body)
197
+ _errors = APIHelper.map_response(decoded, ['errors'])
198
+ ApiResponse.new(_response, data: decoded, errors: _errors)
199
+ end
200
+
201
+ # Retrieves details for a single transaction.
202
+ # Deprecated - recommend using
203
+ # [BatchRetrieveOrders](#endpoint-batchretrieveorders)
204
+ # @param [String] location_id Required parameter: The ID of the
205
+ # transaction's associated location.
206
+ # @param [String] transaction_id Required parameter: The ID of the
207
+ # transaction to retrieve.
208
+ # @return [RetrieveTransactionResponse Hash] response from the API call
209
+ def retrieve_transaction(location_id:,
210
+ transaction_id:)
211
+ warn 'Endpoint retrieve_transaction in TransactionsApi is deprecated'
212
+ # Prepare query url.
213
+ _query_builder = config.get_base_uri
214
+ _query_builder << '/v2/locations/{location_id}/transactions/{transaction_id}'
215
+ _query_builder = APIHelper.append_url_with_template_parameters(
216
+ _query_builder,
217
+ 'location_id' => location_id,
218
+ 'transaction_id' => transaction_id
219
+ )
220
+ _query_url = APIHelper.clean_url _query_builder
221
+
222
+ # Prepare headers.
223
+ _headers = {
224
+ 'accept' => 'application/json'
225
+ }
226
+
227
+ # Prepare and execute HttpRequest.
228
+ _request = config.http_client.get(
229
+ _query_url,
230
+ headers: _headers
231
+ )
232
+ OAuth2.apply(config, _request)
233
+ _response = execute_request(_request)
234
+
235
+ # Return appropriate response type.
236
+ decoded = APIHelper.json_deserialize(_response.raw_body)
237
+ _errors = APIHelper.map_response(decoded, ['errors'])
238
+ ApiResponse.new(_response, data: decoded, errors: _errors)
239
+ end
240
+
241
+ # Captures a transaction that was created with the
242
+ # [Charge](#endpoint-charge)
243
+ # endpoint with a `delay_capture` value of `true`.
244
+ # See [Delayed capture
245
+ # transactions](https://developer.squareup.com/docs/payments/transactions/ov
246
+ # erview#delayed-capture)
247
+ # for more information.
248
+ # @param [String] location_id Required parameter: Example:
249
+ # @param [String] transaction_id Required parameter: Example:
250
+ # @return [CaptureTransactionResponse Hash] response from the API call
251
+ def capture_transaction(location_id:,
252
+ transaction_id:)
253
+ warn 'Endpoint capture_transaction in TransactionsApi is deprecated'
254
+ # Prepare query url.
255
+ _query_builder = config.get_base_uri
256
+ _query_builder << '/v2/locations/{location_id}/transactions/{transaction_id}/capture'
257
+ _query_builder = APIHelper.append_url_with_template_parameters(
258
+ _query_builder,
259
+ 'location_id' => location_id,
260
+ 'transaction_id' => transaction_id
261
+ )
262
+ _query_url = APIHelper.clean_url _query_builder
263
+
264
+ # Prepare headers.
265
+ _headers = {
266
+ 'accept' => 'application/json'
267
+ }
268
+
269
+ # Prepare and execute HttpRequest.
270
+ _request = config.http_client.post(
271
+ _query_url,
272
+ headers: _headers
273
+ )
274
+ OAuth2.apply(config, _request)
275
+ _response = execute_request(_request)
276
+
277
+ # Return appropriate response type.
278
+ decoded = APIHelper.json_deserialize(_response.raw_body)
279
+ _errors = APIHelper.map_response(decoded, ['errors'])
280
+ ApiResponse.new(_response, data: decoded, errors: _errors)
281
+ end
282
+
283
+ # Initiates a refund for a previously charged tender.
284
+ # Deprecated - recommend using
285
+ # [RefundPayment](#endpoint-refunds-refundpayment)
286
+ # You must issue a refund within 120 days of the associated payment. See
287
+ # [this article](https://squareup.com/help/us/en/article/5060) for more
288
+ # information
289
+ # on refund behavior.
290
+ # NOTE: Card-present transactions with Interac credit cards **cannot be
291
+ # refunded using the Connect API**. Interac transactions must refunded
292
+ # in-person (e.g., dipping the card using POS app).
293
+ # @param [String] location_id Required parameter: The ID of the original
294
+ # transaction's associated location.
295
+ # @param [String] transaction_id Required parameter: The ID of the original
296
+ # transaction that includes the tender to refund.
297
+ # @param [CreateRefundRequest] body Required parameter: An object containing
298
+ # the fields to POST for the request. See the corresponding object
299
+ # definition for field details.
300
+ # @return [CreateRefundResponse Hash] response from the API call
301
+ def create_refund(location_id:,
302
+ transaction_id:,
303
+ body:)
304
+ warn 'Endpoint create_refund in TransactionsApi is deprecated'
305
+ # Prepare query url.
306
+ _query_builder = config.get_base_uri
307
+ _query_builder << '/v2/locations/{location_id}/transactions/{transaction_id}/refund'
308
+ _query_builder = APIHelper.append_url_with_template_parameters(
309
+ _query_builder,
310
+ 'location_id' => location_id,
311
+ 'transaction_id' => transaction_id
312
+ )
313
+ _query_url = APIHelper.clean_url _query_builder
314
+
315
+ # Prepare headers.
316
+ _headers = {
317
+ 'accept' => 'application/json',
318
+ 'content-type' => 'application/json; charset=utf-8'
319
+ }
320
+
321
+ # Prepare and execute HttpRequest.
322
+ _request = config.http_client.post(
323
+ _query_url,
324
+ headers: _headers,
325
+ parameters: body.to_json
326
+ )
327
+ OAuth2.apply(config, _request)
328
+ _response = execute_request(_request)
329
+
330
+ # Return appropriate response type.
331
+ decoded = APIHelper.json_deserialize(_response.raw_body)
332
+ _errors = APIHelper.map_response(decoded, ['errors'])
333
+ ApiResponse.new(_response, data: decoded, errors: _errors)
334
+ end
335
+
336
+ # Cancels a transaction that was created with the [Charge](#endpoint-charge)
337
+ # endpoint with a `delay_capture` value of `true`.
338
+ # See [Delayed capture
339
+ # transactions](https://developer.squareup.com/docs/payments/transactions/ov
340
+ # erview#delayed-capture)
341
+ # for more information.
342
+ # @param [String] location_id Required parameter: Example:
343
+ # @param [String] transaction_id Required parameter: Example:
344
+ # @return [VoidTransactionResponse Hash] response from the API call
345
+ def void_transaction(location_id:,
346
+ transaction_id:)
347
+ warn 'Endpoint void_transaction in TransactionsApi is deprecated'
348
+ # Prepare query url.
349
+ _query_builder = config.get_base_uri
350
+ _query_builder << '/v2/locations/{location_id}/transactions/{transaction_id}/void'
351
+ _query_builder = APIHelper.append_url_with_template_parameters(
352
+ _query_builder,
353
+ 'location_id' => location_id,
354
+ 'transaction_id' => transaction_id
355
+ )
356
+ _query_url = APIHelper.clean_url _query_builder
357
+
358
+ # Prepare headers.
359
+ _headers = {
360
+ 'accept' => 'application/json'
361
+ }
362
+
363
+ # Prepare and execute HttpRequest.
364
+ _request = config.http_client.post(
365
+ _query_url,
366
+ headers: _headers
367
+ )
368
+ OAuth2.apply(config, _request)
369
+ _response = execute_request(_request)
370
+
371
+ # Return appropriate response type.
372
+ decoded = APIHelper.json_deserialize(_response.raw_body)
373
+ _errors = APIHelper.map_response(decoded, ['errors'])
374
+ ApiResponse.new(_response, data: decoded, errors: _errors)
375
+ end
376
+ end
377
+ end