square.rb 3.20190624.0 → 3.20190814.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +10 -28
  3. data/README.md +281 -17235
  4. data/lib/square/api/apple_pay_api.rb +55 -54
  5. data/lib/square/api/base_api.rb +45 -45
  6. data/lib/square/api/catalog_api.rb +461 -460
  7. data/lib/square/api/checkout_api.rb +54 -54
  8. data/lib/square/api/customers_api.rb +335 -334
  9. data/lib/square/api/employees_api.rb +91 -91
  10. data/lib/square/api/inventory_api.rb +300 -298
  11. data/lib/square/api/labor_api.rb +558 -558
  12. data/lib/square/api/locations_api.rb +45 -45
  13. data/lib/square/api/mobile_authorization_api.rb +56 -56
  14. data/lib/square/api/o_auth_api.rb +168 -164
  15. data/lib/square/api/orders_api.rb +269 -151
  16. data/lib/square/api/payments_api.rb +282 -0
  17. data/lib/square/api/refunds_api.rb +149 -0
  18. data/lib/square/api/reporting_api.rb +143 -139
  19. data/lib/square/api/transactions_api.rb +379 -360
  20. data/lib/square/api/v1_employees_api.rb +720 -720
  21. data/lib/square/api/v1_items_api.rb +1651 -1651
  22. data/lib/square/api/v1_locations_api.rb +67 -67
  23. data/lib/square/api/v1_locations_api.rbe +67 -0
  24. data/lib/square/api/v1_transactions_api.rb +574 -574
  25. data/lib/square/api_helper.rb +281 -277
  26. data/lib/square/client.rb +139 -127
  27. data/lib/square/configuration.rb +88 -85
  28. data/lib/square/exceptions/api_exception.rb +20 -20
  29. data/lib/square/http/api_response.rb +50 -50
  30. data/lib/square/http/auth/o_auth2.rb +17 -17
  31. data/lib/square/http/faraday_client.rb +64 -64
  32. data/lib/square/http/http_call_back.rb +24 -24
  33. data/lib/square/http/http_client.rb +104 -104
  34. data/lib/square/http/http_method_enum.rb +13 -13
  35. data/lib/square/http/http_request.rb +50 -50
  36. data/lib/square/http/http_response.rb +29 -29
  37. data/lib/square.rb +52 -50
  38. data/spec/user_journey_spec.rb +4 -1
  39. data/test/api/api_test_base.rb +2 -1
  40. data/test/api/test_catalog_api.rb +59 -0
  41. data/test/api/test_employees_api.rb +36 -0
  42. data/test/api/test_locations_api.rb +35 -0
  43. data/test/api/test_payments_api.rb +42 -0
  44. data/test/api/test_refunds_api.rb +41 -0
  45. metadata +19 -11
@@ -0,0 +1,282 @@
1
+ # square
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Square
7
+ # PaymentsApi
8
+ class PaymentsApi < BaseApi
9
+ def initialize(config, http_call_back: nil)
10
+ super(config, http_call_back: http_call_back)
11
+ end
12
+
13
+ # Retrieves a list of payments taken by the account making the request.
14
+ # Max results per page: 100
15
+ # @param [String] begin_time Optional parameter: Timestamp for the beginning
16
+ # of the reporting period, in RFC 3339 format. Inclusive. Default: The
17
+ # current time minus one year.
18
+ # @param [String] end_time Optional parameter: Timestamp for the end of the
19
+ # requested reporting period, in RFC 3339 format. Default: The current
20
+ # time.
21
+ # @param [String] sort_order Optional parameter: The order in which results
22
+ # are listed. - `ASC` - oldest to newest - `DESC` - newest to oldest
23
+ # (default).
24
+ # @param [String] cursor Optional parameter: A pagination cursor returned by
25
+ # a previous call to this endpoint. Provide this to retrieve the next set of
26
+ # results for the original query. See
27
+ # [Pagination](https://developer.squareup.com/docs/basics/api101/pagination)
28
+ # for more information.
29
+ # @param [String] location_id Optional parameter: ID of location associated
30
+ # with payment
31
+ # @param [Long] total Optional parameter: The exact amount in the
32
+ # total_money for a `Payment`.
33
+ # @param [String] last_4 Optional parameter: The last 4 digits of `Payment`
34
+ # card.
35
+ # @param [String] card_brand Optional parameter: The brand of `Payment`
36
+ # card. For example, `VISA`
37
+ # @return [ListPaymentsResponse Hash] response from the API call
38
+ def list_payments(begin_time: nil,
39
+ end_time: nil,
40
+ sort_order: nil,
41
+ cursor: nil,
42
+ location_id: nil,
43
+ total: nil,
44
+ last_4: nil,
45
+ card_brand: nil)
46
+ # Prepare query url.
47
+ _query_builder = config.get_base_uri
48
+ _query_builder << '/v2/payments'
49
+ _query_builder = APIHelper.append_url_with_query_parameters(
50
+ _query_builder,
51
+ 'begin_time' => begin_time,
52
+ 'end_time' => end_time,
53
+ 'sort_order' => sort_order,
54
+ 'cursor' => cursor,
55
+ 'location_id' => location_id,
56
+ 'total' => total,
57
+ 'last_4' => last_4,
58
+ 'card_brand' => card_brand
59
+ )
60
+ _query_url = APIHelper.clean_url _query_builder
61
+
62
+ # Prepare headers.
63
+ _headers = {
64
+ 'accept' => 'application/json'
65
+ }
66
+
67
+ # Prepare and execute HttpRequest.
68
+ _request = config.http_client.get(
69
+ _query_url,
70
+ headers: _headers
71
+ )
72
+ OAuth2.apply(config, _request)
73
+ _response = execute_request(_request)
74
+
75
+ # Return appropriate response type.
76
+ decoded = APIHelper.json_deserialize(_response.raw_body)
77
+ _errors = APIHelper.map_response(decoded, ['errors'])
78
+ ApiResponse.new(_response, data: decoded, errors: _errors)
79
+ end
80
+
81
+ # Charges a payment source, for example, a card
82
+ # represented by customer's card on file or a card nonce. In addition
83
+ # to the payment source, the request must also include the
84
+ # amount to accept for the payment.
85
+ # There are several optional parameters that you can include in the request.
86
+ # For example, tip money, whether to autocomplete the payment, or a
87
+ # reference ID
88
+ # to correlate this payment with another system.
89
+ # For more information about these
90
+ # payment options, see [Take
91
+ # Payments](https://developer.squareup.com/docs/payments-api/take-payments).
92
+ # The `PAYMENTS_WRITE_ADDITIONAL_RECIPIENTS` OAuth permission is required
93
+ # to enable application fees.
94
+ # @param [CreatePaymentRequest] body Required parameter: An object
95
+ # containing the fields to POST for the request. See the corresponding
96
+ # object definition for field details.
97
+ # @return [CreatePaymentResponse Hash] response from the API call
98
+ def create_payment(body:)
99
+ # Prepare query url.
100
+ _query_builder = config.get_base_uri
101
+ _query_builder << '/v2/payments'
102
+ _query_url = APIHelper.clean_url _query_builder
103
+
104
+ # Prepare headers.
105
+ _headers = {
106
+ 'accept' => 'application/json',
107
+ 'content-type' => 'application/json; charset=utf-8'
108
+ }
109
+
110
+ # Prepare and execute HttpRequest.
111
+ _request = config.http_client.post(
112
+ _query_url,
113
+ headers: _headers,
114
+ parameters: body.to_json
115
+ )
116
+ OAuth2.apply(config, _request)
117
+ _response = execute_request(_request)
118
+
119
+ # Return appropriate response type.
120
+ decoded = APIHelper.json_deserialize(_response.raw_body)
121
+ _errors = APIHelper.map_response(decoded, ['errors'])
122
+ ApiResponse.new(_response, data: decoded, errors: _errors)
123
+ end
124
+
125
+ # Cancels a payment identified by the idenpotency key that is specified the
126
+ # request.
127
+ # Use this method when status of a CreatePayment request is unknown.
128
+ # For example, after you send a CreatePayment
129
+ # request a network error occurs and you don't get a response. In this case,
130
+ # you can direct
131
+ # Square to cancel the payment using this endpoint. In the request, you
132
+ # provide the same idempotency
133
+ # key that you provided in your CreatePayment request you want to cancel.
134
+ # After cancelling the
135
+ # payment, you can submit your CreatePayment request again.
136
+ # Note that if no payment with the specified idempotency key is found, no
137
+ # action is taken, the end
138
+ # point returns successfully.
139
+ # @param [CancelPaymentByIdempotencyKeyRequest] body Required parameter: An
140
+ # object containing the fields to POST for the request. See the
141
+ # corresponding object definition for field details.
142
+ # @return [CancelPaymentByIdempotencyKeyResponse Hash] response from the API call
143
+ def cancel_payment_by_idempotency_key(body:)
144
+ # Prepare query url.
145
+ _query_builder = config.get_base_uri
146
+ _query_builder << '/v2/payments/cancel'
147
+ _query_url = APIHelper.clean_url _query_builder
148
+
149
+ # Prepare headers.
150
+ _headers = {
151
+ 'accept' => 'application/json',
152
+ 'content-type' => 'application/json; charset=utf-8'
153
+ }
154
+
155
+ # Prepare and execute HttpRequest.
156
+ _request = config.http_client.post(
157
+ _query_url,
158
+ headers: _headers,
159
+ parameters: body.to_json
160
+ )
161
+ OAuth2.apply(config, _request)
162
+ _response = execute_request(_request)
163
+
164
+ # Return appropriate response type.
165
+ decoded = APIHelper.json_deserialize(_response.raw_body)
166
+ _errors = APIHelper.map_response(decoded, ['errors'])
167
+ ApiResponse.new(_response, data: decoded, errors: _errors)
168
+ end
169
+
170
+ # Retrieves details for a specific Payment.
171
+ # @param [String] payment_id Required parameter: Unique ID for the desired
172
+ # `Payment`.
173
+ # @return [GetPaymentResponse Hash] response from the API call
174
+ def get_payment(payment_id:)
175
+ # Prepare query url.
176
+ _query_builder = config.get_base_uri
177
+ _query_builder << '/v2/payments/{payment_id}'
178
+ _query_builder = APIHelper.append_url_with_template_parameters(
179
+ _query_builder,
180
+ 'payment_id' => payment_id
181
+ )
182
+ _query_url = APIHelper.clean_url _query_builder
183
+
184
+ # Prepare headers.
185
+ _headers = {
186
+ 'accept' => 'application/json'
187
+ }
188
+
189
+ # Prepare and execute HttpRequest.
190
+ _request = config.http_client.get(
191
+ _query_url,
192
+ headers: _headers
193
+ )
194
+ OAuth2.apply(config, _request)
195
+ _response = execute_request(_request)
196
+
197
+ # Return appropriate response type.
198
+ decoded = APIHelper.json_deserialize(_response.raw_body)
199
+ _errors = APIHelper.map_response(decoded, ['errors'])
200
+ ApiResponse.new(_response, data: decoded, errors: _errors)
201
+ end
202
+
203
+ # Cancels a payment. If you set `autocomplete` to false when creating a
204
+ # payment,
205
+ # you can cancel the payment using this endpoint. For more information, see
206
+ # [Delayed
207
+ # Payments](https://developer.squareup.com/docs/payments-api/take-payments#d
208
+ # elayed-payments).
209
+ # @param [String] payment_id Required parameter: `payment_id` identifying
210
+ # the payment to be canceled.
211
+ # @return [CancelPaymentResponse Hash] response from the API call
212
+ def cancel_payment(payment_id:)
213
+ # Prepare query url.
214
+ _query_builder = config.get_base_uri
215
+ _query_builder << '/v2/payments/{payment_id}/cancel'
216
+ _query_builder = APIHelper.append_url_with_template_parameters(
217
+ _query_builder,
218
+ 'payment_id' => payment_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.post(
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
+ # Completes a payment.
242
+ # By default, payments are set to complete immediately after they are
243
+ # created.
244
+ # If you set autocomplete to false when creating a payment,
245
+ # you can complete the payment using this endpoint. For more information,
246
+ # see
247
+ # [Delayed
248
+ # Payments](https://developer.squareup.com/docs/payments-api/take-payments#d
249
+ # elayed-payments).
250
+ # @param [String] payment_id Required parameter: Unique ID identifying the
251
+ # payment to be completed.
252
+ # @return [CompletePaymentResponse Hash] response from the API call
253
+ def complete_payment(payment_id:)
254
+ # Prepare query url.
255
+ _query_builder = config.get_base_uri
256
+ _query_builder << '/v2/payments/{payment_id}/complete'
257
+ _query_builder = APIHelper.append_url_with_template_parameters(
258
+ _query_builder,
259
+ 'payment_id' => payment_id
260
+ )
261
+ _query_url = APIHelper.clean_url _query_builder
262
+
263
+ # Prepare headers.
264
+ _headers = {
265
+ 'accept' => 'application/json'
266
+ }
267
+
268
+ # Prepare and execute HttpRequest.
269
+ _request = config.http_client.post(
270
+ _query_url,
271
+ headers: _headers
272
+ )
273
+ OAuth2.apply(config, _request)
274
+ _response = execute_request(_request)
275
+
276
+ # Return appropriate response type.
277
+ decoded = APIHelper.json_deserialize(_response.raw_body)
278
+ _errors = APIHelper.map_response(decoded, ['errors'])
279
+ ApiResponse.new(_response, data: decoded, errors: _errors)
280
+ end
281
+ end
282
+ end
@@ -0,0 +1,149 @@
1
+ # square
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Square
7
+ # RefundsApi
8
+ class RefundsApi < BaseApi
9
+ def initialize(config, http_call_back: nil)
10
+ super(config, http_call_back: http_call_back)
11
+ end
12
+
13
+ # Retrieves a list of refunds for the account making the request.
14
+ # Max results per page: 100
15
+ # @param [String] begin_time Optional parameter: Timestamp for the beginning
16
+ # of the requested reporting period, in RFC 3339 format. Default: The
17
+ # current time minus one year.
18
+ # @param [String] end_time Optional parameter: Timestamp for the end of the
19
+ # requested reporting period, in RFC 3339 format. Default: The current
20
+ # time.
21
+ # @param [String] sort_order Optional parameter: The order in which results
22
+ # are listed. - `ASC` - oldest to newest - `DESC` - newest to oldest
23
+ # (default).
24
+ # @param [String] cursor Optional parameter: A pagination cursor returned by
25
+ # a previous call to this endpoint. Provide this to retrieve the next set of
26
+ # results for the original query. See
27
+ # [Pagination](https://developer.squareup.com/docs/basics/api101/pagination)
28
+ # for more information.
29
+ # @param [String] location_id Optional parameter: ID of location associated
30
+ # with payment.
31
+ # @param [String] status Optional parameter: If provided, only refunds with
32
+ # the given status are returned. For a list of refund status values, see
33
+ # [PaymentRefund](#type-paymentrefund). Default: If omitted refunds are
34
+ # returned regardless of status.
35
+ # @param [String] source_type Optional parameter: If provided, only refunds
36
+ # with the given source type are returned. - `CARD` - List refunds only for
37
+ # payments where card was specified as payment source. Default: If omitted
38
+ # refunds are returned regardless of source type.
39
+ # @return [ListPaymentRefundsResponse Hash] response from the API call
40
+ def list_payment_refunds(begin_time: nil,
41
+ end_time: nil,
42
+ sort_order: nil,
43
+ cursor: nil,
44
+ location_id: nil,
45
+ status: nil,
46
+ source_type: nil)
47
+ # Prepare query url.
48
+ _query_builder = config.get_base_uri
49
+ _query_builder << '/v2/refunds'
50
+ _query_builder = APIHelper.append_url_with_query_parameters(
51
+ _query_builder,
52
+ 'begin_time' => begin_time,
53
+ 'end_time' => end_time,
54
+ 'sort_order' => sort_order,
55
+ 'cursor' => cursor,
56
+ 'location_id' => location_id,
57
+ 'status' => status,
58
+ 'source_type' => source_type
59
+ )
60
+ _query_url = APIHelper.clean_url _query_builder
61
+
62
+ # Prepare headers.
63
+ _headers = {
64
+ 'accept' => 'application/json'
65
+ }
66
+
67
+ # Prepare and execute HttpRequest.
68
+ _request = config.http_client.get(
69
+ _query_url,
70
+ headers: _headers
71
+ )
72
+ OAuth2.apply(config, _request)
73
+ _response = execute_request(_request)
74
+
75
+ # Return appropriate response type.
76
+ decoded = APIHelper.json_deserialize(_response.raw_body)
77
+ _errors = APIHelper.map_response(decoded, ['errors'])
78
+ ApiResponse.new(_response, data: decoded, errors: _errors)
79
+ end
80
+
81
+ # Refunds a payment. You can refund the entire payment amount or a
82
+ # portion of it. For more information, see
83
+ # [Payments and Refunds
84
+ # Overview](https://developer.squareup.com/docs/payments-api/overview).
85
+ # @param [RefundPaymentRequest] body Required parameter: An object
86
+ # containing the fields to POST for the request. See the corresponding
87
+ # object definition for field details.
88
+ # @return [RefundPaymentResponse Hash] response from the API call
89
+ def refund_payment(body:)
90
+ # Prepare query url.
91
+ _query_builder = config.get_base_uri
92
+ _query_builder << '/v2/refunds'
93
+ _query_url = APIHelper.clean_url _query_builder
94
+
95
+ # Prepare headers.
96
+ _headers = {
97
+ 'accept' => 'application/json',
98
+ 'content-type' => 'application/json; charset=utf-8'
99
+ }
100
+
101
+ # Prepare and execute HttpRequest.
102
+ _request = config.http_client.post(
103
+ _query_url,
104
+ headers: _headers,
105
+ parameters: body.to_json
106
+ )
107
+ OAuth2.apply(config, _request)
108
+ _response = execute_request(_request)
109
+
110
+ # Return appropriate response type.
111
+ decoded = APIHelper.json_deserialize(_response.raw_body)
112
+ _errors = APIHelper.map_response(decoded, ['errors'])
113
+ ApiResponse.new(_response, data: decoded, errors: _errors)
114
+ end
115
+
116
+ # Retrieves a specific `Refund` using the `refund_id`.
117
+ # @param [String] refund_id Required parameter: Unique ID for the desired
118
+ # `PaymentRefund`.
119
+ # @return [GetPaymentRefundResponse Hash] response from the API call
120
+ def get_payment_refund(refund_id:)
121
+ # Prepare query url.
122
+ _query_builder = config.get_base_uri
123
+ _query_builder << '/v2/refunds/{refund_id}'
124
+ _query_builder = APIHelper.append_url_with_template_parameters(
125
+ _query_builder,
126
+ 'refund_id' => refund_id
127
+ )
128
+ _query_url = APIHelper.clean_url _query_builder
129
+
130
+ # Prepare headers.
131
+ _headers = {
132
+ 'accept' => 'application/json'
133
+ }
134
+
135
+ # Prepare and execute HttpRequest.
136
+ _request = config.http_client.get(
137
+ _query_url,
138
+ headers: _headers
139
+ )
140
+ OAuth2.apply(config, _request)
141
+ _response = execute_request(_request)
142
+
143
+ # Return appropriate response type.
144
+ decoded = APIHelper.json_deserialize(_response.raw_body)
145
+ _errors = APIHelper.map_response(decoded, ['errors'])
146
+ ApiResponse.new(_response, data: decoded, errors: _errors)
147
+ end
148
+ end
149
+ end