fangkuai.rb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +10 -0
  3. data/README.md +1 -0
  4. data/lib/square.rb +61 -0
  5. data/lib/square/api/apple_pay_api.rb +50 -0
  6. data/lib/square/api/bank_accounts_api.rb +136 -0
  7. data/lib/square/api/base_api.rb +43 -0
  8. data/lib/square/api/cash_drawers_api.rb +150 -0
  9. data/lib/square/api/catalog_api.rb +572 -0
  10. data/lib/square/api/checkout_api.rb +49 -0
  11. data/lib/square/api/customer_groups_api.rb +182 -0
  12. data/lib/square/api/customer_segments_api.rb +78 -0
  13. data/lib/square/api/customers_api.rb +418 -0
  14. data/lib/square/api/devices_api.rb +120 -0
  15. data/lib/square/api/disputes_api.rb +398 -0
  16. data/lib/square/api/employees_api.rb +87 -0
  17. data/lib/square/api/inventory_api.rb +296 -0
  18. data/lib/square/api/invoices_api.rb +358 -0
  19. data/lib/square/api/labor_api.rb +630 -0
  20. data/lib/square/api/locations_api.rb +151 -0
  21. data/lib/square/api/loyalty_api.rb +543 -0
  22. data/lib/square/api/merchants_api.rb +83 -0
  23. data/lib/square/api/mobile_authorization_api.rb +52 -0
  24. data/lib/square/api/o_auth_api.rb +163 -0
  25. data/lib/square/api/orders_api.rb +280 -0
  26. data/lib/square/api/payments_api.rb +279 -0
  27. data/lib/square/api/refunds_api.rb +145 -0
  28. data/lib/square/api/subscriptions_api.rb +251 -0
  29. data/lib/square/api/team_api.rb +326 -0
  30. data/lib/square/api/terminal_api.rb +141 -0
  31. data/lib/square/api/transactions_api.rb +369 -0
  32. data/lib/square/api/v1_employees_api.rb +723 -0
  33. data/lib/square/api/v1_items_api.rb +1686 -0
  34. data/lib/square/api/v1_locations_api.rb +65 -0
  35. data/lib/square/api/v1_transactions_api.rb +572 -0
  36. data/lib/square/api_helper.rb +276 -0
  37. data/lib/square/client.rb +211 -0
  38. data/lib/square/configuration.rb +101 -0
  39. data/lib/square/exceptions/api_exception.rb +15 -0
  40. data/lib/square/http/api_response.rb +45 -0
  41. data/lib/square/http/auth/o_auth2.rb +12 -0
  42. data/lib/square/http/faraday_client.rb +55 -0
  43. data/lib/square/http/http_call_back.rb +19 -0
  44. data/lib/square/http/http_client.rb +99 -0
  45. data/lib/square/http/http_method_enum.rb +8 -0
  46. data/lib/square/http/http_request.rb +45 -0
  47. data/lib/square/http/http_response.rb +24 -0
  48. data/lib/square/utilities/file_wrapper.rb +12 -0
  49. data/spec/user_journey_spec.rb +148 -0
  50. data/test/api/api_test_base.rb +24 -0
  51. data/test/api/test_catalog_api.rb +59 -0
  52. data/test/api/test_customers_api.rb +45 -0
  53. data/test/api/test_employees_api.rb +36 -0
  54. data/test/api/test_labor_api.rb +74 -0
  55. data/test/api/test_locations_api.rb +35 -0
  56. data/test/api/test_merchants_api.rb +40 -0
  57. data/test/api/test_payments_api.rb +42 -0
  58. data/test/api/test_refunds_api.rb +41 -0
  59. data/test/http_response_catcher.rb +19 -0
  60. data/test/test_helper.rb +94 -0
  61. metadata +199 -0
@@ -0,0 +1,151 @@
1
+ module Square
2
+ # LocationsApi
3
+ class LocationsApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Provides information of all locations of a business.
9
+ # Most other Connect API endpoints have a required `location_id` path
10
+ # parameter.
11
+ # The `id` field of the [`Location`](#type-location) objects returned by
12
+ # this
13
+ # endpoint correspond to that `location_id` parameter.
14
+ # @return [ListLocationsResponse Hash] response from the API call
15
+ def list_locations
16
+ # Prepare query url.
17
+ _query_builder = config.get_base_uri
18
+ _query_builder << '/v2/locations'
19
+ _query_url = APIHelper.clean_url _query_builder
20
+
21
+ # Prepare headers.
22
+ _headers = {
23
+ 'accept' => 'application/json'
24
+ }
25
+
26
+ # Prepare and execute HttpRequest.
27
+ _request = config.http_client.get(
28
+ _query_url,
29
+ headers: _headers
30
+ )
31
+ OAuth2.apply(config, _request)
32
+ _response = execute_request(_request)
33
+
34
+ # Return appropriate response type.
35
+ decoded = APIHelper.json_deserialize(_response.raw_body)
36
+ _errors = APIHelper.map_response(decoded, ['errors'])
37
+ ApiResponse.new(_response, data: decoded, errors: _errors)
38
+ end
39
+
40
+ # Creates a location.
41
+ # For more information about locations, see [Locations API
42
+ # Overview](https://developer.squareup.com/docs/locations-api).
43
+ # @param [CreateLocationRequest] body Required parameter: An object
44
+ # containing the fields to POST for the request. See the corresponding
45
+ # object definition for field details.
46
+ # @return [CreateLocationResponse Hash] response from the API call
47
+ def create_location(body:)
48
+ # Prepare query url.
49
+ _query_builder = config.get_base_uri
50
+ _query_builder << '/v2/locations'
51
+ _query_url = APIHelper.clean_url _query_builder
52
+
53
+ # Prepare headers.
54
+ _headers = {
55
+ 'accept' => 'application/json',
56
+ 'content-type' => 'application/json; charset=utf-8'
57
+ }
58
+
59
+ # Prepare and execute HttpRequest.
60
+ _request = config.http_client.post(
61
+ _query_url,
62
+ headers: _headers,
63
+ parameters: body.to_json
64
+ )
65
+ OAuth2.apply(config, _request)
66
+ _response = execute_request(_request)
67
+
68
+ # Return appropriate response type.
69
+ decoded = APIHelper.json_deserialize(_response.raw_body)
70
+ _errors = APIHelper.map_response(decoded, ['errors'])
71
+ ApiResponse.new(_response, data: decoded, errors: _errors)
72
+ end
73
+
74
+ # Retrieves details of a location. You can specify "main"
75
+ # as the location ID to retrieve details of the
76
+ # main location. For more information,
77
+ # see [Locations API
78
+ # Overview](https://developer.squareup.com/docs/docs/locations-api).
79
+ # @param [String] location_id Required parameter: The ID of the location to
80
+ # retrieve. If you specify the string "main", then the endpoint returns the
81
+ # main location.
82
+ # @return [RetrieveLocationResponse Hash] response from the API call
83
+ def retrieve_location(location_id:)
84
+ # Prepare query url.
85
+ _query_builder = config.get_base_uri
86
+ _query_builder << '/v2/locations/{location_id}'
87
+ _query_builder = APIHelper.append_url_with_template_parameters(
88
+ _query_builder,
89
+ 'location_id' => location_id
90
+ )
91
+ _query_url = APIHelper.clean_url _query_builder
92
+
93
+ # Prepare headers.
94
+ _headers = {
95
+ 'accept' => 'application/json'
96
+ }
97
+
98
+ # Prepare and execute HttpRequest.
99
+ _request = config.http_client.get(
100
+ _query_url,
101
+ headers: _headers
102
+ )
103
+ OAuth2.apply(config, _request)
104
+ _response = execute_request(_request)
105
+
106
+ # Return appropriate response type.
107
+ decoded = APIHelper.json_deserialize(_response.raw_body)
108
+ _errors = APIHelper.map_response(decoded, ['errors'])
109
+ ApiResponse.new(_response, data: decoded, errors: _errors)
110
+ end
111
+
112
+ # Updates a location.
113
+ # @param [String] location_id Required parameter: The ID of the location to
114
+ # update.
115
+ # @param [UpdateLocationRequest] body Required parameter: An object
116
+ # containing the fields to POST for the request. See the corresponding
117
+ # object definition for field details.
118
+ # @return [UpdateLocationResponse Hash] response from the API call
119
+ def update_location(location_id:,
120
+ body:)
121
+ # Prepare query url.
122
+ _query_builder = config.get_base_uri
123
+ _query_builder << '/v2/locations/{location_id}'
124
+ _query_builder = APIHelper.append_url_with_template_parameters(
125
+ _query_builder,
126
+ 'location_id' => location_id
127
+ )
128
+ _query_url = APIHelper.clean_url _query_builder
129
+
130
+ # Prepare headers.
131
+ _headers = {
132
+ 'accept' => 'application/json',
133
+ 'content-type' => 'application/json; charset=utf-8'
134
+ }
135
+
136
+ # Prepare and execute HttpRequest.
137
+ _request = config.http_client.put(
138
+ _query_url,
139
+ headers: _headers,
140
+ parameters: body.to_json
141
+ )
142
+ OAuth2.apply(config, _request)
143
+ _response = execute_request(_request)
144
+
145
+ # Return appropriate response type.
146
+ decoded = APIHelper.json_deserialize(_response.raw_body)
147
+ _errors = APIHelper.map_response(decoded, ['errors'])
148
+ ApiResponse.new(_response, data: decoded, errors: _errors)
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,543 @@
1
+ module Square
2
+ # LoyaltyApi
3
+ class LoyaltyApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Creates a loyalty account. For more information, see
9
+ # [Create a loyalty
10
+ # account](https://developer.squareup.com/docs/docs/loyalty-api/overview/#lo
11
+ # yalty-overview-create-account).
12
+ # @param [CreateLoyaltyAccountRequest] body Required parameter: An object
13
+ # containing the fields to POST for the request. See the corresponding
14
+ # object definition for field details.
15
+ # @return [CreateLoyaltyAccountResponse Hash] response from the API call
16
+ def create_loyalty_account(body:)
17
+ # Prepare query url.
18
+ _query_builder = config.get_base_uri
19
+ _query_builder << '/v2/loyalty/accounts'
20
+ _query_url = APIHelper.clean_url _query_builder
21
+
22
+ # Prepare headers.
23
+ _headers = {
24
+ 'accept' => 'application/json',
25
+ 'content-type' => 'application/json; charset=utf-8'
26
+ }
27
+
28
+ # Prepare and execute HttpRequest.
29
+ _request = config.http_client.post(
30
+ _query_url,
31
+ headers: _headers,
32
+ parameters: body.to_json
33
+ )
34
+ OAuth2.apply(config, _request)
35
+ _response = execute_request(_request)
36
+
37
+ # Return appropriate response type.
38
+ decoded = APIHelper.json_deserialize(_response.raw_body)
39
+ _errors = APIHelper.map_response(decoded, ['errors'])
40
+ ApiResponse.new(_response, data: decoded, errors: _errors)
41
+ end
42
+
43
+ # Searches for loyalty accounts.
44
+ # In the current implementation, you can search for a loyalty account using
45
+ # the phone number associated with the account.
46
+ # If no phone number is provided, all loyalty accounts are returned.
47
+ # @param [SearchLoyaltyAccountsRequest] body Required parameter: An object
48
+ # containing the fields to POST for the request. See the corresponding
49
+ # object definition for field details.
50
+ # @return [SearchLoyaltyAccountsResponse Hash] response from the API call
51
+ def search_loyalty_accounts(body:)
52
+ # Prepare query url.
53
+ _query_builder = config.get_base_uri
54
+ _query_builder << '/v2/loyalty/accounts/search'
55
+ _query_url = APIHelper.clean_url _query_builder
56
+
57
+ # Prepare headers.
58
+ _headers = {
59
+ 'accept' => 'application/json',
60
+ 'content-type' => 'application/json; charset=utf-8'
61
+ }
62
+
63
+ # Prepare and execute HttpRequest.
64
+ _request = config.http_client.post(
65
+ _query_url,
66
+ headers: _headers,
67
+ parameters: body.to_json
68
+ )
69
+ OAuth2.apply(config, _request)
70
+ _response = execute_request(_request)
71
+
72
+ # Return appropriate response type.
73
+ decoded = APIHelper.json_deserialize(_response.raw_body)
74
+ _errors = APIHelper.map_response(decoded, ['errors'])
75
+ ApiResponse.new(_response, data: decoded, errors: _errors)
76
+ end
77
+
78
+ # Retrieves a loyalty account.
79
+ # @param [String] account_id Required parameter: The ID of the [loyalty
80
+ # account](#type-LoyaltyAccount) to retrieve.
81
+ # @return [RetrieveLoyaltyAccountResponse Hash] response from the API call
82
+ def retrieve_loyalty_account(account_id:)
83
+ # Prepare query url.
84
+ _query_builder = config.get_base_uri
85
+ _query_builder << '/v2/loyalty/accounts/{account_id}'
86
+ _query_builder = APIHelper.append_url_with_template_parameters(
87
+ _query_builder,
88
+ 'account_id' => account_id
89
+ )
90
+ _query_url = APIHelper.clean_url _query_builder
91
+
92
+ # Prepare headers.
93
+ _headers = {
94
+ 'accept' => 'application/json'
95
+ }
96
+
97
+ # Prepare and execute HttpRequest.
98
+ _request = config.http_client.get(
99
+ _query_url,
100
+ headers: _headers
101
+ )
102
+ OAuth2.apply(config, _request)
103
+ _response = execute_request(_request)
104
+
105
+ # Return appropriate response type.
106
+ decoded = APIHelper.json_deserialize(_response.raw_body)
107
+ _errors = APIHelper.map_response(decoded, ['errors'])
108
+ ApiResponse.new(_response, data: decoded, errors: _errors)
109
+ end
110
+
111
+ # Adds points to a loyalty account.
112
+ # - If you are using the Orders API to manage orders, you only provide the
113
+ # `order_id`.
114
+ # The endpoint reads the order to compute points to add to the buyer's
115
+ # account.
116
+ # - If you are not using the Orders API to manage orders,
117
+ # you first perform a client-side computation to compute the points.
118
+ # For spend-based and visit-based programs, you can call
119
+ # `CalculateLoyaltyPoints` to compute the points. For more information,
120
+ # see [Loyalty Program
121
+ # Overview](https://developer.squareup.com/docs/docs/loyalty/overview).
122
+ # You then provide the points in a request to this endpoint.
123
+ # For more information, see [Accumulate
124
+ # points](https://developer.squareup.com/docs/docs/loyalty-api/overview/#acc
125
+ # umulate-points).
126
+ # @param [String] account_id Required parameter: The [loyalty
127
+ # account](#type-LoyaltyAccount) ID to which to add the points.
128
+ # @param [AccumulateLoyaltyPointsRequest] body Required parameter: An object
129
+ # containing the fields to POST for the request. See the corresponding
130
+ # object definition for field details.
131
+ # @return [AccumulateLoyaltyPointsResponse Hash] response from the API call
132
+ def accumulate_loyalty_points(account_id:,
133
+ body:)
134
+ # Prepare query url.
135
+ _query_builder = config.get_base_uri
136
+ _query_builder << '/v2/loyalty/accounts/{account_id}/accumulate'
137
+ _query_builder = APIHelper.append_url_with_template_parameters(
138
+ _query_builder,
139
+ 'account_id' => account_id
140
+ )
141
+ _query_url = APIHelper.clean_url _query_builder
142
+
143
+ # Prepare headers.
144
+ _headers = {
145
+ 'accept' => 'application/json',
146
+ 'content-type' => 'application/json; charset=utf-8'
147
+ }
148
+
149
+ # Prepare and execute HttpRequest.
150
+ _request = config.http_client.post(
151
+ _query_url,
152
+ headers: _headers,
153
+ parameters: body.to_json
154
+ )
155
+ OAuth2.apply(config, _request)
156
+ _response = execute_request(_request)
157
+
158
+ # Return appropriate response type.
159
+ decoded = APIHelper.json_deserialize(_response.raw_body)
160
+ _errors = APIHelper.map_response(decoded, ['errors'])
161
+ ApiResponse.new(_response, data: decoded, errors: _errors)
162
+ end
163
+
164
+ # Adds points to or subtracts points from a buyer's account.
165
+ # Use this endpoint only when you need to manually adjust points. Otherwise,
166
+ # in your application flow, you call
167
+ # [AccumulateLoyaltyPoints](https://developer.squareup.com/docs/reference/sq
168
+ # uare/loyalty-api/accumulate-loyalty-points)
169
+ # to add points when a buyer pays for the purchase.
170
+ # @param [String] account_id Required parameter: The ID of the [loyalty
171
+ # account](#type-LoyaltyAccount) in which to adjust the points.
172
+ # @param [AdjustLoyaltyPointsRequest] body Required parameter: An object
173
+ # containing the fields to POST for the request. See the corresponding
174
+ # object definition for field details.
175
+ # @return [AdjustLoyaltyPointsResponse Hash] response from the API call
176
+ def adjust_loyalty_points(account_id:,
177
+ body:)
178
+ # Prepare query url.
179
+ _query_builder = config.get_base_uri
180
+ _query_builder << '/v2/loyalty/accounts/{account_id}/adjust'
181
+ _query_builder = APIHelper.append_url_with_template_parameters(
182
+ _query_builder,
183
+ 'account_id' => account_id
184
+ )
185
+ _query_url = APIHelper.clean_url _query_builder
186
+
187
+ # Prepare headers.
188
+ _headers = {
189
+ 'accept' => 'application/json',
190
+ 'content-type' => 'application/json; charset=utf-8'
191
+ }
192
+
193
+ # Prepare and execute HttpRequest.
194
+ _request = config.http_client.post(
195
+ _query_url,
196
+ headers: _headers,
197
+ parameters: body.to_json
198
+ )
199
+ OAuth2.apply(config, _request)
200
+ _response = execute_request(_request)
201
+
202
+ # Return appropriate response type.
203
+ decoded = APIHelper.json_deserialize(_response.raw_body)
204
+ _errors = APIHelper.map_response(decoded, ['errors'])
205
+ ApiResponse.new(_response, data: decoded, errors: _errors)
206
+ end
207
+
208
+ # Searches for loyalty events.
209
+ # A Square loyalty program maintains a ledger of events that occur during
210
+ # the lifetime of a
211
+ # buyer's loyalty account. Each change in the point balance
212
+ # (for example, points earned, points redeemed, and points expired) is
213
+ # recorded in the ledger. Using this endpoint, you can search the ledger for
214
+ # events.
215
+ # For more information, see
216
+ # [Loyalty
217
+ # events](https://developer.squareup.com/docs/docs/loyalty-api/overview/#loy
218
+ # alty-events).
219
+ # @param [SearchLoyaltyEventsRequest] body Required parameter: An object
220
+ # containing the fields to POST for the request. See the corresponding
221
+ # object definition for field details.
222
+ # @return [SearchLoyaltyEventsResponse Hash] response from the API call
223
+ def search_loyalty_events(body:)
224
+ # Prepare query url.
225
+ _query_builder = config.get_base_uri
226
+ _query_builder << '/v2/loyalty/events/search'
227
+ _query_url = APIHelper.clean_url _query_builder
228
+
229
+ # Prepare headers.
230
+ _headers = {
231
+ 'accept' => 'application/json',
232
+ 'content-type' => 'application/json; charset=utf-8'
233
+ }
234
+
235
+ # Prepare and execute HttpRequest.
236
+ _request = config.http_client.post(
237
+ _query_url,
238
+ headers: _headers,
239
+ parameters: body.to_json
240
+ )
241
+ OAuth2.apply(config, _request)
242
+ _response = execute_request(_request)
243
+
244
+ # Return appropriate response type.
245
+ decoded = APIHelper.json_deserialize(_response.raw_body)
246
+ _errors = APIHelper.map_response(decoded, ['errors'])
247
+ ApiResponse.new(_response, data: decoded, errors: _errors)
248
+ end
249
+
250
+ # Returns a list of loyalty programs in the seller's account.
251
+ # Currently, a seller can only have one loyalty program. For more
252
+ # information, see
253
+ # [Loyalty
254
+ # Overview](https://developer.squareup.com/docs/docs/loyalty/overview).
255
+ # .
256
+ # @return [ListLoyaltyProgramsResponse Hash] response from the API call
257
+ def list_loyalty_programs
258
+ # Prepare query url.
259
+ _query_builder = config.get_base_uri
260
+ _query_builder << '/v2/loyalty/programs'
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.get(
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
+
282
+ # Calculates the points a purchase earns.
283
+ # - If you are using the Orders API to manage orders, you provide `order_id`
284
+ # in the request. The
285
+ # endpoint calculates the points by reading the order.
286
+ # - If you are not using the Orders API to manage orders, you provide the
287
+ # purchase amount in
288
+ # the request for the endpoint to calculate the points.
289
+ # An application might call this endpoint to show the points that a buyer
290
+ # can earn with the
291
+ # specific purchase.
292
+ # @param [String] program_id Required parameter: The [loyalty
293
+ # program](#type-LoyaltyProgram) ID, which defines the rules for accruing
294
+ # points.
295
+ # @param [CalculateLoyaltyPointsRequest] body Required parameter: An object
296
+ # containing the fields to POST for the request. See the corresponding
297
+ # object definition for field details.
298
+ # @return [CalculateLoyaltyPointsResponse Hash] response from the API call
299
+ def calculate_loyalty_points(program_id:,
300
+ body:)
301
+ # Prepare query url.
302
+ _query_builder = config.get_base_uri
303
+ _query_builder << '/v2/loyalty/programs/{program_id}/calculate'
304
+ _query_builder = APIHelper.append_url_with_template_parameters(
305
+ _query_builder,
306
+ 'program_id' => program_id
307
+ )
308
+ _query_url = APIHelper.clean_url _query_builder
309
+
310
+ # Prepare headers.
311
+ _headers = {
312
+ 'accept' => 'application/json',
313
+ 'content-type' => 'application/json; charset=utf-8'
314
+ }
315
+
316
+ # Prepare and execute HttpRequest.
317
+ _request = config.http_client.post(
318
+ _query_url,
319
+ headers: _headers,
320
+ parameters: body.to_json
321
+ )
322
+ OAuth2.apply(config, _request)
323
+ _response = execute_request(_request)
324
+
325
+ # Return appropriate response type.
326
+ decoded = APIHelper.json_deserialize(_response.raw_body)
327
+ _errors = APIHelper.map_response(decoded, ['errors'])
328
+ ApiResponse.new(_response, data: decoded, errors: _errors)
329
+ end
330
+
331
+ # Creates a loyalty reward. In the process, the endpoint does following:
332
+ # - Uses the `reward_tier_id` in the request to determine the number of
333
+ # points
334
+ # to lock for this reward.
335
+ # - If the request includes `order_id`, it adds the reward and related
336
+ # discount to the order.
337
+ # After a reward is created, the points are locked and
338
+ # not available for the buyer to redeem another reward.
339
+ # For more information, see
340
+ # [Loyalty
341
+ # rewards](https://developer.squareup.com/docs/docs/loyalty-api/overview/#lo
342
+ # yalty-overview-loyalty-rewards).
343
+ # @param [CreateLoyaltyRewardRequest] body Required parameter: An object
344
+ # containing the fields to POST for the request. See the corresponding
345
+ # object definition for field details.
346
+ # @return [CreateLoyaltyRewardResponse Hash] response from the API call
347
+ def create_loyalty_reward(body:)
348
+ # Prepare query url.
349
+ _query_builder = config.get_base_uri
350
+ _query_builder << '/v2/loyalty/rewards'
351
+ _query_url = APIHelper.clean_url _query_builder
352
+
353
+ # Prepare headers.
354
+ _headers = {
355
+ 'accept' => 'application/json',
356
+ 'content-type' => 'application/json; charset=utf-8'
357
+ }
358
+
359
+ # Prepare and execute HttpRequest.
360
+ _request = config.http_client.post(
361
+ _query_url,
362
+ headers: _headers,
363
+ parameters: body.to_json
364
+ )
365
+ OAuth2.apply(config, _request)
366
+ _response = execute_request(_request)
367
+
368
+ # Return appropriate response type.
369
+ decoded = APIHelper.json_deserialize(_response.raw_body)
370
+ _errors = APIHelper.map_response(decoded, ['errors'])
371
+ ApiResponse.new(_response, data: decoded, errors: _errors)
372
+ end
373
+
374
+ # Searches for loyalty rewards in a loyalty account.
375
+ # In the current implementation, the endpoint supports search by the reward
376
+ # `status`.
377
+ # If you know a reward ID, use the
378
+ # [RetrieveLoyaltyReward](https://developer.squareup.com/docs/reference/squa
379
+ # re/loyalty-api/retrieve-loyalty-reward) endpoint.
380
+ # For more information about loyalty rewards, see
381
+ # [Loyalty
382
+ # Rewards](https://developer.squareup.com/docs/docs/loyalty-api/overview/#lo
383
+ # yalty-rewards).
384
+ # @param [SearchLoyaltyRewardsRequest] body Required parameter: An object
385
+ # containing the fields to POST for the request. See the corresponding
386
+ # object definition for field details.
387
+ # @return [SearchLoyaltyRewardsResponse Hash] response from the API call
388
+ def search_loyalty_rewards(body:)
389
+ # Prepare query url.
390
+ _query_builder = config.get_base_uri
391
+ _query_builder << '/v2/loyalty/rewards/search'
392
+ _query_url = APIHelper.clean_url _query_builder
393
+
394
+ # Prepare headers.
395
+ _headers = {
396
+ 'accept' => 'application/json',
397
+ 'content-type' => 'application/json; charset=utf-8'
398
+ }
399
+
400
+ # Prepare and execute HttpRequest.
401
+ _request = config.http_client.post(
402
+ _query_url,
403
+ headers: _headers,
404
+ parameters: body.to_json
405
+ )
406
+ OAuth2.apply(config, _request)
407
+ _response = execute_request(_request)
408
+
409
+ # Return appropriate response type.
410
+ decoded = APIHelper.json_deserialize(_response.raw_body)
411
+ _errors = APIHelper.map_response(decoded, ['errors'])
412
+ ApiResponse.new(_response, data: decoded, errors: _errors)
413
+ end
414
+
415
+ # Deletes a loyalty reward by doing the following:
416
+ # - Returns the loyalty points back to the loyalty account.
417
+ # - If an order ID was specified when the reward was created
418
+ # (see
419
+ # [CreateLoyaltyReward](https://developer.squareup.com/docs/reference/square
420
+ # /loyalty-api/create-loyalty-reward)),
421
+ # it updates the order by removing the reward and related
422
+ # discounts.
423
+ # You cannot delete a reward that has reached the terminal state (REDEEMED).
424
+ # For more information, see
425
+ # [Loyalty
426
+ # rewards](https://developer.squareup.com/docs/docs/loyalty-api/overview/#lo
427
+ # yalty-overview-loyalty-rewards).
428
+ # @param [String] reward_id Required parameter: The ID of the [loyalty
429
+ # reward](#type-LoyaltyReward) to delete.
430
+ # @return [DeleteLoyaltyRewardResponse Hash] response from the API call
431
+ def delete_loyalty_reward(reward_id:)
432
+ # Prepare query url.
433
+ _query_builder = config.get_base_uri
434
+ _query_builder << '/v2/loyalty/rewards/{reward_id}'
435
+ _query_builder = APIHelper.append_url_with_template_parameters(
436
+ _query_builder,
437
+ 'reward_id' => reward_id
438
+ )
439
+ _query_url = APIHelper.clean_url _query_builder
440
+
441
+ # Prepare headers.
442
+ _headers = {
443
+ 'accept' => 'application/json'
444
+ }
445
+
446
+ # Prepare and execute HttpRequest.
447
+ _request = config.http_client.delete(
448
+ _query_url,
449
+ headers: _headers
450
+ )
451
+ OAuth2.apply(config, _request)
452
+ _response = execute_request(_request)
453
+
454
+ # Return appropriate response type.
455
+ decoded = APIHelper.json_deserialize(_response.raw_body)
456
+ _errors = APIHelper.map_response(decoded, ['errors'])
457
+ ApiResponse.new(_response, data: decoded, errors: _errors)
458
+ end
459
+
460
+ # Retrieves a loyalty reward.
461
+ # @param [String] reward_id Required parameter: The ID of the [loyalty
462
+ # reward](#type-LoyaltyReward) to retrieve.
463
+ # @return [RetrieveLoyaltyRewardResponse Hash] response from the API call
464
+ def retrieve_loyalty_reward(reward_id:)
465
+ # Prepare query url.
466
+ _query_builder = config.get_base_uri
467
+ _query_builder << '/v2/loyalty/rewards/{reward_id}'
468
+ _query_builder = APIHelper.append_url_with_template_parameters(
469
+ _query_builder,
470
+ 'reward_id' => reward_id
471
+ )
472
+ _query_url = APIHelper.clean_url _query_builder
473
+
474
+ # Prepare headers.
475
+ _headers = {
476
+ 'accept' => 'application/json'
477
+ }
478
+
479
+ # Prepare and execute HttpRequest.
480
+ _request = config.http_client.get(
481
+ _query_url,
482
+ headers: _headers
483
+ )
484
+ OAuth2.apply(config, _request)
485
+ _response = execute_request(_request)
486
+
487
+ # Return appropriate response type.
488
+ decoded = APIHelper.json_deserialize(_response.raw_body)
489
+ _errors = APIHelper.map_response(decoded, ['errors'])
490
+ ApiResponse.new(_response, data: decoded, errors: _errors)
491
+ end
492
+
493
+ # Redeems a loyalty reward.
494
+ # The endpoint sets the reward to the terminal state (`REDEEMED`).
495
+ # If you are using your own order processing system (not using the
496
+ # Orders API), you call this endpoint after the buyer paid for the
497
+ # purchase.
498
+ # After the reward reaches the terminal state, it cannot be deleted.
499
+ # In other words, points used for the reward cannot be returned
500
+ # to the account.
501
+ # For more information, see
502
+ # [Loyalty
503
+ # rewards](https://developer.squareup.com/docs/docs/loyalty-api/overview/#lo
504
+ # yalty-overview-loyalty-rewards).
505
+ # @param [String] reward_id Required parameter: The ID of the [loyalty
506
+ # reward](#type-LoyaltyReward) to redeem.
507
+ # @param [RedeemLoyaltyRewardRequest] body Required parameter: An object
508
+ # containing the fields to POST for the request. See the corresponding
509
+ # object definition for field details.
510
+ # @return [RedeemLoyaltyRewardResponse Hash] response from the API call
511
+ def redeem_loyalty_reward(reward_id:,
512
+ body:)
513
+ # Prepare query url.
514
+ _query_builder = config.get_base_uri
515
+ _query_builder << '/v2/loyalty/rewards/{reward_id}/redeem'
516
+ _query_builder = APIHelper.append_url_with_template_parameters(
517
+ _query_builder,
518
+ 'reward_id' => reward_id
519
+ )
520
+ _query_url = APIHelper.clean_url _query_builder
521
+
522
+ # Prepare headers.
523
+ _headers = {
524
+ 'accept' => 'application/json',
525
+ 'content-type' => 'application/json; charset=utf-8'
526
+ }
527
+
528
+ # Prepare and execute HttpRequest.
529
+ _request = config.http_client.post(
530
+ _query_url,
531
+ headers: _headers,
532
+ parameters: body.to_json
533
+ )
534
+ OAuth2.apply(config, _request)
535
+ _response = execute_request(_request)
536
+
537
+ # Return appropriate response type.
538
+ decoded = APIHelper.json_deserialize(_response.raw_body)
539
+ _errors = APIHelper.map_response(decoded, ['errors'])
540
+ ApiResponse.new(_response, data: decoded, errors: _errors)
541
+ end
542
+ end
543
+ end