square.rb 26.1.0.20230119 → 27.0.0.20230419
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/square/api/apple_pay_api.rb +14 -30
- data/lib/square/api/bank_accounts_api.rb +40 -90
- data/lib/square/api/base_api.rb +42 -42
- data/lib/square/api/booking_custom_attributes_api.rb +171 -336
- data/lib/square/api/bookings_api.rb +140 -263
- data/lib/square/api/cards_api.rb +58 -120
- data/lib/square/api/cash_drawers_api.rb +47 -103
- data/lib/square/api/catalog_api.rb +200 -426
- data/lib/square/api/checkout_api.rb +86 -176
- data/lib/square/api/customer_custom_attributes_api.rb +157 -310
- data/lib/square/api/customer_groups_api.rb +69 -145
- data/lib/square/api/customer_segments_api.rb +26 -61
- data/lib/square/api/customers_api.rb +147 -294
- data/lib/square/api/devices_api.rb +42 -89
- data/lib/square/api/disputes_api.rb +132 -290
- data/lib/square/api/employees_api.rb +28 -63
- data/lib/square/api/gift_card_activities_api.rb +34 -66
- data/lib/square/api/gift_cards_api.rb +109 -207
- data/lib/square/api/inventory_api.rb +204 -391
- data/lib/square/api/invoices_api.rb +121 -240
- data/lib/square/api/labor_api.rb +223 -459
- data/lib/square/api/location_custom_attributes_api.rb +173 -338
- data/lib/square/api/locations_api.rb +54 -112
- data/lib/square/api/loyalty_api.rb +283 -535
- data/lib/square/api/merchants_api.rb +25 -60
- data/lib/square/api/mobile_authorization_api.rb +14 -30
- data/lib/square/api/o_auth_api.rb +54 -109
- data/lib/square/api/order_custom_attributes_api.rb +174 -339
- data/lib/square/api/orders_api.rb +115 -222
- data/lib/square/api/payments_api.rb +118 -217
- data/lib/square/api/payouts_api.rb +54 -107
- data/lib/square/api/refunds_api.rb +59 -104
- data/lib/square/api/sites_api.rb +11 -28
- data/lib/square/api/snippets_api.rb +42 -90
- data/lib/square/api/subscriptions_api.rb +150 -299
- data/lib/square/api/team_api.rb +114 -224
- data/lib/square/api/terminal_api.rb +162 -328
- data/lib/square/api/transactions_api.rb +64 -128
- data/lib/square/api/v1_transactions_api.rb +155 -296
- data/lib/square/api/vendors_api.rb +100 -193
- data/lib/square/api/webhook_subscriptions_api.rb +124 -244
- data/lib/square/api_helper.rb +1 -437
- data/lib/square/client.rb +77 -47
- data/lib/square/configuration.rb +28 -53
- data/lib/square/exceptions/api_exception.rb +1 -11
- data/lib/square/http/api_response.rb +13 -19
- data/lib/square/http/auth/o_auth2.rb +14 -7
- data/lib/square/http/http_call_back.rb +1 -15
- data/lib/square/http/http_method_enum.rb +1 -4
- data/lib/square/http/http_request.rb +1 -45
- data/lib/square/http/http_response.rb +1 -20
- data/lib/square/utilities/date_time_helper.rb +1 -146
- data/lib/square/utilities/file_wrapper.rb +5 -5
- data/lib/square.rb +6 -6
- data/spec/user_journey_spec.rb +2 -2
- data/test/api/api_test_base.rb +13 -5
- data/test/api/test_catalog_api.rb +5 -4
- data/test/api/test_customers_api.rb +3 -2
- data/test/api/test_employees_api.rb +4 -3
- data/test/api/test_labor_api.rb +6 -5
- data/test/api/test_locations_api.rb +3 -2
- data/test/api/test_merchants_api.rb +4 -3
- data/test/api/test_payments_api.rb +4 -3
- data/test/api/test_refunds_api.rb +4 -3
- metadata +11 -111
- data/lib/square/exceptions/validation_exception.rb +0 -13
- data/lib/square/http/faraday_client.rb +0 -93
- data/lib/square/http/http_client.rb +0 -118
- data/test/test_helper.rb +0 -89
@@ -1,10 +1,6 @@
|
|
1
1
|
module Square
|
2
2
|
# LoyaltyApi
|
3
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
4
|
# Creates a loyalty account. To create a loyalty account, you must provide
|
9
5
|
# the `program_id` and a `mapping` with the `phone_number` of the buyer.
|
10
6
|
# @param [CreateLoyaltyAccountRequest] body Required parameter: An object
|
@@ -12,32 +8,20 @@ module Square
|
|
12
8
|
# object definition for field details.
|
13
9
|
# @return [CreateLoyaltyAccountResponse Hash] response from the API call
|
14
10
|
def create_loyalty_account(body:)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
headers: _headers,
|
30
|
-
parameters: body.to_json
|
31
|
-
)
|
32
|
-
OAuth2.apply(config, _request)
|
33
|
-
_response = execute_request(_request)
|
34
|
-
|
35
|
-
# Return appropriate response type.
|
36
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
37
|
-
_errors = APIHelper.map_response(decoded, ['errors'])
|
38
|
-
ApiResponse.new(
|
39
|
-
_response, data: decoded, errors: _errors
|
40
|
-
)
|
11
|
+
new_api_call_builder
|
12
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
13
|
+
'/v2/loyalty/accounts',
|
14
|
+
'default')
|
15
|
+
.header_param(new_parameter('application/json', key: 'Content-Type'))
|
16
|
+
.body_param(new_parameter(body))
|
17
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
18
|
+
.body_serializer(proc do |param| param.to_json unless param.nil? end)
|
19
|
+
.auth(Single.new('global')))
|
20
|
+
.response(new_response_handler
|
21
|
+
.deserializer(APIHelper.method(:json_deserialize))
|
22
|
+
.is_api_response(true)
|
23
|
+
.convertor(ApiResponse.method(:create)))
|
24
|
+
.execute
|
41
25
|
end
|
42
26
|
|
43
27
|
# Searches for loyalty accounts in a loyalty program.
|
@@ -50,67 +34,40 @@ module Square
|
|
50
34
|
# object definition for field details.
|
51
35
|
# @return [SearchLoyaltyAccountsResponse Hash] response from the API call
|
52
36
|
def search_loyalty_accounts(body:)
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
headers: _headers,
|
68
|
-
parameters: body.to_json
|
69
|
-
)
|
70
|
-
OAuth2.apply(config, _request)
|
71
|
-
_response = execute_request(_request)
|
72
|
-
|
73
|
-
# Return appropriate response type.
|
74
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
75
|
-
_errors = APIHelper.map_response(decoded, ['errors'])
|
76
|
-
ApiResponse.new(
|
77
|
-
_response, data: decoded, errors: _errors
|
78
|
-
)
|
37
|
+
new_api_call_builder
|
38
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
39
|
+
'/v2/loyalty/accounts/search',
|
40
|
+
'default')
|
41
|
+
.header_param(new_parameter('application/json', key: 'Content-Type'))
|
42
|
+
.body_param(new_parameter(body))
|
43
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
44
|
+
.body_serializer(proc do |param| param.to_json unless param.nil? end)
|
45
|
+
.auth(Single.new('global')))
|
46
|
+
.response(new_response_handler
|
47
|
+
.deserializer(APIHelper.method(:json_deserialize))
|
48
|
+
.is_api_response(true)
|
49
|
+
.convertor(ApiResponse.method(:create)))
|
50
|
+
.execute
|
79
51
|
end
|
80
52
|
|
81
53
|
# Retrieves a loyalty account.
|
82
54
|
# @param [String] account_id Required parameter: The ID of the [loyalty
|
83
|
-
# account](
|
55
|
+
# account](entity:LoyaltyAccount) to retrieve.
|
84
56
|
# @return [RetrieveLoyaltyAccountResponse Hash] response from the API call
|
85
57
|
def retrieve_loyalty_account(account_id:)
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
# Prepare and execute HttpRequest.
|
101
|
-
_request = config.http_client.get(
|
102
|
-
_query_url,
|
103
|
-
headers: _headers
|
104
|
-
)
|
105
|
-
OAuth2.apply(config, _request)
|
106
|
-
_response = execute_request(_request)
|
107
|
-
|
108
|
-
# Return appropriate response type.
|
109
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
110
|
-
_errors = APIHelper.map_response(decoded, ['errors'])
|
111
|
-
ApiResponse.new(
|
112
|
-
_response, data: decoded, errors: _errors
|
113
|
-
)
|
58
|
+
new_api_call_builder
|
59
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
60
|
+
'/v2/loyalty/accounts/{account_id}',
|
61
|
+
'default')
|
62
|
+
.template_param(new_parameter(account_id, key: 'account_id')
|
63
|
+
.should_encode(true))
|
64
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
65
|
+
.auth(Single.new('global')))
|
66
|
+
.response(new_response_handler
|
67
|
+
.deserializer(APIHelper.method(:json_deserialize))
|
68
|
+
.is_api_response(true)
|
69
|
+
.convertor(ApiResponse.method(:create)))
|
70
|
+
.execute
|
114
71
|
end
|
115
72
|
|
116
73
|
# Adds points earned from a purchase to a [loyalty
|
@@ -139,43 +96,29 @@ module Square
|
|
139
96
|
# points](https://developer.squareup.com/docs/loyalty-api/loyalty-promotions
|
140
97
|
# #calculate-promotion-points).
|
141
98
|
# @param [String] account_id Required parameter: The ID of the target
|
142
|
-
# [loyalty account](
|
99
|
+
# [loyalty account](entity:LoyaltyAccount).
|
143
100
|
# @param [AccumulateLoyaltyPointsRequest] body Required parameter: An object
|
144
101
|
# containing the fields to POST for the request. See the corresponding
|
145
102
|
# object definition for field details.
|
146
103
|
# @return [AccumulateLoyaltyPointsResponse Hash] response from the API call
|
147
104
|
def accumulate_loyalty_points(account_id:,
|
148
105
|
body:)
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
_request = config.http_client.post(
|
166
|
-
_query_url,
|
167
|
-
headers: _headers,
|
168
|
-
parameters: body.to_json
|
169
|
-
)
|
170
|
-
OAuth2.apply(config, _request)
|
171
|
-
_response = execute_request(_request)
|
172
|
-
|
173
|
-
# Return appropriate response type.
|
174
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
175
|
-
_errors = APIHelper.map_response(decoded, ['errors'])
|
176
|
-
ApiResponse.new(
|
177
|
-
_response, data: decoded, errors: _errors
|
178
|
-
)
|
106
|
+
new_api_call_builder
|
107
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
108
|
+
'/v2/loyalty/accounts/{account_id}/accumulate',
|
109
|
+
'default')
|
110
|
+
.template_param(new_parameter(account_id, key: 'account_id')
|
111
|
+
.should_encode(true))
|
112
|
+
.header_param(new_parameter('application/json', key: 'Content-Type'))
|
113
|
+
.body_param(new_parameter(body))
|
114
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
115
|
+
.body_serializer(proc do |param| param.to_json unless param.nil? end)
|
116
|
+
.auth(Single.new('global')))
|
117
|
+
.response(new_response_handler
|
118
|
+
.deserializer(APIHelper.method(:json_deserialize))
|
119
|
+
.is_api_response(true)
|
120
|
+
.convertor(ApiResponse.method(:create)))
|
121
|
+
.execute
|
179
122
|
end
|
180
123
|
|
181
124
|
# Adds points to or subtracts points from a buyer's account.
|
@@ -184,43 +127,29 @@ module Square
|
|
184
127
|
# [AccumulateLoyaltyPoints]($e/Loyalty/AccumulateLoyaltyPoints)
|
185
128
|
# to add points when a buyer pays for the purchase.
|
186
129
|
# @param [String] account_id Required parameter: The ID of the target
|
187
|
-
# [loyalty account](
|
130
|
+
# [loyalty account](entity:LoyaltyAccount).
|
188
131
|
# @param [AdjustLoyaltyPointsRequest] body Required parameter: An object
|
189
132
|
# containing the fields to POST for the request. See the corresponding
|
190
133
|
# object definition for field details.
|
191
134
|
# @return [AdjustLoyaltyPointsResponse Hash] response from the API call
|
192
135
|
def adjust_loyalty_points(account_id:,
|
193
136
|
body:)
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
_request = config.http_client.post(
|
211
|
-
_query_url,
|
212
|
-
headers: _headers,
|
213
|
-
parameters: body.to_json
|
214
|
-
)
|
215
|
-
OAuth2.apply(config, _request)
|
216
|
-
_response = execute_request(_request)
|
217
|
-
|
218
|
-
# Return appropriate response type.
|
219
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
220
|
-
_errors = APIHelper.map_response(decoded, ['errors'])
|
221
|
-
ApiResponse.new(
|
222
|
-
_response, data: decoded, errors: _errors
|
223
|
-
)
|
137
|
+
new_api_call_builder
|
138
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
139
|
+
'/v2/loyalty/accounts/{account_id}/adjust',
|
140
|
+
'default')
|
141
|
+
.template_param(new_parameter(account_id, key: 'account_id')
|
142
|
+
.should_encode(true))
|
143
|
+
.header_param(new_parameter('application/json', key: 'Content-Type'))
|
144
|
+
.body_param(new_parameter(body))
|
145
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
146
|
+
.body_serializer(proc do |param| param.to_json unless param.nil? end)
|
147
|
+
.auth(Single.new('global')))
|
148
|
+
.response(new_response_handler
|
149
|
+
.deserializer(APIHelper.method(:json_deserialize))
|
150
|
+
.is_api_response(true)
|
151
|
+
.convertor(ApiResponse.method(:create)))
|
152
|
+
.execute
|
224
153
|
end
|
225
154
|
|
226
155
|
# Searches for loyalty events.
|
@@ -236,32 +165,20 @@ module Square
|
|
236
165
|
# object definition for field details.
|
237
166
|
# @return [SearchLoyaltyEventsResponse Hash] response from the API call
|
238
167
|
def search_loyalty_events(body:)
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
headers: _headers,
|
254
|
-
parameters: body.to_json
|
255
|
-
)
|
256
|
-
OAuth2.apply(config, _request)
|
257
|
-
_response = execute_request(_request)
|
258
|
-
|
259
|
-
# Return appropriate response type.
|
260
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
261
|
-
_errors = APIHelper.map_response(decoded, ['errors'])
|
262
|
-
ApiResponse.new(
|
263
|
-
_response, data: decoded, errors: _errors
|
264
|
-
)
|
168
|
+
new_api_call_builder
|
169
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
170
|
+
'/v2/loyalty/events/search',
|
171
|
+
'default')
|
172
|
+
.header_param(new_parameter('application/json', key: 'Content-Type'))
|
173
|
+
.body_param(new_parameter(body))
|
174
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
175
|
+
.body_serializer(proc do |param| param.to_json unless param.nil? end)
|
176
|
+
.auth(Single.new('global')))
|
177
|
+
.response(new_response_handler
|
178
|
+
.deserializer(APIHelper.method(:json_deserialize))
|
179
|
+
.is_api_response(true)
|
180
|
+
.convertor(ApiResponse.method(:create)))
|
181
|
+
.execute
|
265
182
|
end
|
266
183
|
|
267
184
|
# Returns a list of loyalty programs in the seller's account.
|
@@ -270,35 +187,23 @@ module Square
|
|
270
187
|
# created and managed from the Seller Dashboard. For more information, see
|
271
188
|
# [Loyalty Program
|
272
189
|
# Overview](https://developer.squareup.com/docs/loyalty/overview).
|
273
|
-
# Replaced with
|
274
|
-
# when
|
190
|
+
# Replaced with
|
191
|
+
# [RetrieveLoyaltyProgram](api-endpoint:Loyalty-RetrieveLoyaltyProgram) when
|
192
|
+
# used with the keyword `main`.
|
275
193
|
# @return [ListLoyaltyProgramsResponse Hash] response from the API call
|
276
194
|
def list_loyalty_programs
|
277
195
|
warn 'Endpoint list_loyalty_programs in LoyaltyApi is deprecated'
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
_request = config.http_client.get(
|
290
|
-
_query_url,
|
291
|
-
headers: _headers
|
292
|
-
)
|
293
|
-
OAuth2.apply(config, _request)
|
294
|
-
_response = execute_request(_request)
|
295
|
-
|
296
|
-
# Return appropriate response type.
|
297
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
298
|
-
_errors = APIHelper.map_response(decoded, ['errors'])
|
299
|
-
ApiResponse.new(
|
300
|
-
_response, data: decoded, errors: _errors
|
301
|
-
)
|
196
|
+
new_api_call_builder
|
197
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
198
|
+
'/v2/loyalty/programs',
|
199
|
+
'default')
|
200
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
201
|
+
.auth(Single.new('global')))
|
202
|
+
.response(new_response_handler
|
203
|
+
.deserializer(APIHelper.method(:json_deserialize))
|
204
|
+
.is_api_response(true)
|
205
|
+
.convertor(ApiResponse.method(:create)))
|
206
|
+
.execute
|
302
207
|
end
|
303
208
|
|
304
209
|
# Retrieves the loyalty program in a seller's account, specified by the
|
@@ -313,34 +218,19 @@ module Square
|
|
313
218
|
# single loyalty program that belongs to the seller.
|
314
219
|
# @return [RetrieveLoyaltyProgramResponse Hash] response from the API call
|
315
220
|
def retrieve_loyalty_program(program_id:)
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
# Prepare and execute HttpRequest.
|
331
|
-
_request = config.http_client.get(
|
332
|
-
_query_url,
|
333
|
-
headers: _headers
|
334
|
-
)
|
335
|
-
OAuth2.apply(config, _request)
|
336
|
-
_response = execute_request(_request)
|
337
|
-
|
338
|
-
# Return appropriate response type.
|
339
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
340
|
-
_errors = APIHelper.map_response(decoded, ['errors'])
|
341
|
-
ApiResponse.new(
|
342
|
-
_response, data: decoded, errors: _errors
|
343
|
-
)
|
221
|
+
new_api_call_builder
|
222
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
223
|
+
'/v2/loyalty/programs/{program_id}',
|
224
|
+
'default')
|
225
|
+
.template_param(new_parameter(program_id, key: 'program_id')
|
226
|
+
.should_encode(true))
|
227
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
228
|
+
.auth(Single.new('global')))
|
229
|
+
.response(new_response_handler
|
230
|
+
.deserializer(APIHelper.method(:json_deserialize))
|
231
|
+
.is_api_response(true)
|
232
|
+
.convertor(ApiResponse.method(:create)))
|
233
|
+
.execute
|
344
234
|
end
|
345
235
|
|
346
236
|
# Calculates the number of points a buyer can earn from a purchase.
|
@@ -368,7 +258,7 @@ module Square
|
|
368
258
|
# points](https://developer.squareup.com/docs/loyalty-api/loyalty-promotions
|
369
259
|
# #calculate-promotion-points).
|
370
260
|
# @param [String] program_id Required parameter: The ID of the [loyalty
|
371
|
-
# program](
|
261
|
+
# program](entity:LoyaltyProgram), which defines the rules for accruing
|
372
262
|
# points.
|
373
263
|
# @param [CalculateLoyaltyPointsRequest] body Required parameter: An object
|
374
264
|
# containing the fields to POST for the request. See the corresponding
|
@@ -376,36 +266,22 @@ module Square
|
|
376
266
|
# @return [CalculateLoyaltyPointsResponse Hash] response from the API call
|
377
267
|
def calculate_loyalty_points(program_id:,
|
378
268
|
body:)
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
_request = config.http_client.post(
|
396
|
-
_query_url,
|
397
|
-
headers: _headers,
|
398
|
-
parameters: body.to_json
|
399
|
-
)
|
400
|
-
OAuth2.apply(config, _request)
|
401
|
-
_response = execute_request(_request)
|
402
|
-
|
403
|
-
# Return appropriate response type.
|
404
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
405
|
-
_errors = APIHelper.map_response(decoded, ['errors'])
|
406
|
-
ApiResponse.new(
|
407
|
-
_response, data: decoded, errors: _errors
|
408
|
-
)
|
269
|
+
new_api_call_builder
|
270
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
271
|
+
'/v2/loyalty/programs/{program_id}/calculate',
|
272
|
+
'default')
|
273
|
+
.template_param(new_parameter(program_id, key: 'program_id')
|
274
|
+
.should_encode(true))
|
275
|
+
.header_param(new_parameter('application/json', key: 'Content-Type'))
|
276
|
+
.body_param(new_parameter(body))
|
277
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
278
|
+
.body_serializer(proc do |param| param.to_json unless param.nil? end)
|
279
|
+
.auth(Single.new('global')))
|
280
|
+
.response(new_response_handler
|
281
|
+
.deserializer(APIHelper.method(:json_deserialize))
|
282
|
+
.is_api_response(true)
|
283
|
+
.convertor(ApiResponse.method(:create)))
|
284
|
+
.execute
|
409
285
|
end
|
410
286
|
|
411
287
|
# Lists the loyalty promotions associated with a [loyalty
|
@@ -413,9 +289,9 @@ module Square
|
|
413
289
|
# Results are sorted by the `created_at` date in descending order (newest to
|
414
290
|
# oldest).
|
415
291
|
# @param [String] program_id Required parameter: The ID of the base [loyalty
|
416
|
-
# program](
|
417
|
-
# [RetrieveLoyaltyProgram](
|
418
|
-
# `main` keyword.
|
292
|
+
# program](entity:LoyaltyProgram). To get the program ID, call
|
293
|
+
# [RetrieveLoyaltyProgram](api-endpoint:Loyalty-RetrieveLoyaltyProgram)
|
294
|
+
# using the `main` keyword.
|
419
295
|
# @param [LoyaltyPromotionStatus] status Optional parameter: The status to
|
420
296
|
# filter the results by. If a status is provided, only loyalty promotions
|
421
297
|
# with the specified status are returned. Otherwise, all loyalty promotions
|
@@ -436,40 +312,22 @@ module Square
|
|
436
312
|
status: nil,
|
437
313
|
cursor: nil,
|
438
314
|
limit: nil)
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
_headers = {
|
456
|
-
'accept' => 'application/json'
|
457
|
-
}
|
458
|
-
|
459
|
-
# Prepare and execute HttpRequest.
|
460
|
-
_request = config.http_client.get(
|
461
|
-
_query_url,
|
462
|
-
headers: _headers
|
463
|
-
)
|
464
|
-
OAuth2.apply(config, _request)
|
465
|
-
_response = execute_request(_request)
|
466
|
-
|
467
|
-
# Return appropriate response type.
|
468
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
469
|
-
_errors = APIHelper.map_response(decoded, ['errors'])
|
470
|
-
ApiResponse.new(
|
471
|
-
_response, data: decoded, errors: _errors
|
472
|
-
)
|
315
|
+
new_api_call_builder
|
316
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
317
|
+
'/v2/loyalty/programs/{program_id}/promotions',
|
318
|
+
'default')
|
319
|
+
.template_param(new_parameter(program_id, key: 'program_id')
|
320
|
+
.should_encode(true))
|
321
|
+
.query_param(new_parameter(status, key: 'status'))
|
322
|
+
.query_param(new_parameter(cursor, key: 'cursor'))
|
323
|
+
.query_param(new_parameter(limit, key: 'limit'))
|
324
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
325
|
+
.auth(Single.new('global')))
|
326
|
+
.response(new_response_handler
|
327
|
+
.deserializer(APIHelper.method(:json_deserialize))
|
328
|
+
.is_api_response(true)
|
329
|
+
.convertor(ApiResponse.method(:create)))
|
330
|
+
.execute
|
473
331
|
end
|
474
332
|
|
475
333
|
# Creates a loyalty promotion for a [loyalty program]($m/LoyaltyProgram). A
|
@@ -482,87 +340,59 @@ module Square
|
|
482
340
|
# loyalty promotions with an
|
483
341
|
# `ACTIVE` or `SCHEDULED` status.
|
484
342
|
# @param [String] program_id Required parameter: The ID of the [loyalty
|
485
|
-
# program](
|
486
|
-
# program ID, call
|
487
|
-
# [RetrieveLoyaltyProgram](
|
488
|
-
# `main` keyword.
|
343
|
+
# program](entity:LoyaltyProgram) to associate with the promotion. To get
|
344
|
+
# the program ID, call
|
345
|
+
# [RetrieveLoyaltyProgram](api-endpoint:Loyalty-RetrieveLoyaltyProgram)
|
346
|
+
# using the `main` keyword.
|
489
347
|
# @param [CreateLoyaltyPromotionRequest] body Required parameter: An object
|
490
348
|
# containing the fields to POST for the request. See the corresponding
|
491
349
|
# object definition for field details.
|
492
350
|
# @return [CreateLoyaltyPromotionResponse Hash] response from the API call
|
493
351
|
def create_loyalty_promotion(program_id:,
|
494
352
|
body:)
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
_request = config.http_client.post(
|
512
|
-
_query_url,
|
513
|
-
headers: _headers,
|
514
|
-
parameters: body.to_json
|
515
|
-
)
|
516
|
-
OAuth2.apply(config, _request)
|
517
|
-
_response = execute_request(_request)
|
518
|
-
|
519
|
-
# Return appropriate response type.
|
520
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
521
|
-
_errors = APIHelper.map_response(decoded, ['errors'])
|
522
|
-
ApiResponse.new(
|
523
|
-
_response, data: decoded, errors: _errors
|
524
|
-
)
|
353
|
+
new_api_call_builder
|
354
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
355
|
+
'/v2/loyalty/programs/{program_id}/promotions',
|
356
|
+
'default')
|
357
|
+
.template_param(new_parameter(program_id, key: 'program_id')
|
358
|
+
.should_encode(true))
|
359
|
+
.header_param(new_parameter('application/json', key: 'Content-Type'))
|
360
|
+
.body_param(new_parameter(body))
|
361
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
362
|
+
.body_serializer(proc do |param| param.to_json unless param.nil? end)
|
363
|
+
.auth(Single.new('global')))
|
364
|
+
.response(new_response_handler
|
365
|
+
.deserializer(APIHelper.method(:json_deserialize))
|
366
|
+
.is_api_response(true)
|
367
|
+
.convertor(ApiResponse.method(:create)))
|
368
|
+
.execute
|
525
369
|
end
|
526
370
|
|
527
371
|
# Retrieves a loyalty promotion.
|
528
372
|
# @param [String] promotion_id Required parameter: The ID of the [loyalty
|
529
|
-
# promotion](
|
373
|
+
# promotion](entity:LoyaltyPromotion) to retrieve.
|
530
374
|
# @param [String] program_id Required parameter: The ID of the base [loyalty
|
531
|
-
# program](
|
532
|
-
# [RetrieveLoyaltyProgram](
|
533
|
-
# `main` keyword.
|
375
|
+
# program](entity:LoyaltyProgram). To get the program ID, call
|
376
|
+
# [RetrieveLoyaltyProgram](api-endpoint:Loyalty-RetrieveLoyaltyProgram)
|
377
|
+
# using the `main` keyword.
|
534
378
|
# @return [RetrieveLoyaltyPromotionResponse Hash] response from the API call
|
535
379
|
def retrieve_loyalty_promotion(promotion_id:,
|
536
380
|
program_id:)
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
# Prepare and execute HttpRequest.
|
553
|
-
_request = config.http_client.get(
|
554
|
-
_query_url,
|
555
|
-
headers: _headers
|
556
|
-
)
|
557
|
-
OAuth2.apply(config, _request)
|
558
|
-
_response = execute_request(_request)
|
559
|
-
|
560
|
-
# Return appropriate response type.
|
561
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
562
|
-
_errors = APIHelper.map_response(decoded, ['errors'])
|
563
|
-
ApiResponse.new(
|
564
|
-
_response, data: decoded, errors: _errors
|
565
|
-
)
|
381
|
+
new_api_call_builder
|
382
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
383
|
+
'/v2/loyalty/programs/{program_id}/promotions/{promotion_id}',
|
384
|
+
'default')
|
385
|
+
.template_param(new_parameter(promotion_id, key: 'promotion_id')
|
386
|
+
.should_encode(true))
|
387
|
+
.template_param(new_parameter(program_id, key: 'program_id')
|
388
|
+
.should_encode(true))
|
389
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
390
|
+
.auth(Single.new('global')))
|
391
|
+
.response(new_response_handler
|
392
|
+
.deserializer(APIHelper.method(:json_deserialize))
|
393
|
+
.is_api_response(true)
|
394
|
+
.convertor(ApiResponse.method(:create)))
|
395
|
+
.execute
|
566
396
|
end
|
567
397
|
|
568
398
|
# Cancels a loyalty promotion. Use this endpoint to cancel an `ACTIVE`
|
@@ -574,42 +404,28 @@ module Square
|
|
574
404
|
# you create a new one.
|
575
405
|
# This endpoint sets the loyalty promotion to the `CANCELED` state
|
576
406
|
# @param [String] promotion_id Required parameter: The ID of the [loyalty
|
577
|
-
# promotion](
|
578
|
-
# has an `ACTIVE` or `SCHEDULED` status.
|
407
|
+
# promotion](entity:LoyaltyPromotion) to cancel. You can cancel a promotion
|
408
|
+
# that has an `ACTIVE` or `SCHEDULED` status.
|
579
409
|
# @param [String] program_id Required parameter: The ID of the base [loyalty
|
580
|
-
# program](
|
410
|
+
# program](entity:LoyaltyProgram).
|
581
411
|
# @return [CancelLoyaltyPromotionResponse Hash] response from the API call
|
582
412
|
def cancel_loyalty_promotion(promotion_id:,
|
583
413
|
program_id:)
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
# Prepare and execute HttpRequest.
|
600
|
-
_request = config.http_client.post(
|
601
|
-
_query_url,
|
602
|
-
headers: _headers
|
603
|
-
)
|
604
|
-
OAuth2.apply(config, _request)
|
605
|
-
_response = execute_request(_request)
|
606
|
-
|
607
|
-
# Return appropriate response type.
|
608
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
609
|
-
_errors = APIHelper.map_response(decoded, ['errors'])
|
610
|
-
ApiResponse.new(
|
611
|
-
_response, data: decoded, errors: _errors
|
612
|
-
)
|
414
|
+
new_api_call_builder
|
415
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
416
|
+
'/v2/loyalty/programs/{program_id}/promotions/{promotion_id}/cancel',
|
417
|
+
'default')
|
418
|
+
.template_param(new_parameter(promotion_id, key: 'promotion_id')
|
419
|
+
.should_encode(true))
|
420
|
+
.template_param(new_parameter(program_id, key: 'program_id')
|
421
|
+
.should_encode(true))
|
422
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
423
|
+
.auth(Single.new('global')))
|
424
|
+
.response(new_response_handler
|
425
|
+
.deserializer(APIHelper.method(:json_deserialize))
|
426
|
+
.is_api_response(true)
|
427
|
+
.convertor(ApiResponse.method(:create)))
|
428
|
+
.execute
|
613
429
|
end
|
614
430
|
|
615
431
|
# Creates a loyalty reward. In the process, the endpoint does following:
|
@@ -625,32 +441,20 @@ module Square
|
|
625
441
|
# object definition for field details.
|
626
442
|
# @return [CreateLoyaltyRewardResponse Hash] response from the API call
|
627
443
|
def create_loyalty_reward(body:)
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
headers: _headers,
|
643
|
-
parameters: body.to_json
|
644
|
-
)
|
645
|
-
OAuth2.apply(config, _request)
|
646
|
-
_response = execute_request(_request)
|
647
|
-
|
648
|
-
# Return appropriate response type.
|
649
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
650
|
-
_errors = APIHelper.map_response(decoded, ['errors'])
|
651
|
-
ApiResponse.new(
|
652
|
-
_response, data: decoded, errors: _errors
|
653
|
-
)
|
444
|
+
new_api_call_builder
|
445
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
446
|
+
'/v2/loyalty/rewards',
|
447
|
+
'default')
|
448
|
+
.header_param(new_parameter('application/json', key: 'Content-Type'))
|
449
|
+
.body_param(new_parameter(body))
|
450
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
451
|
+
.body_serializer(proc do |param| param.to_json unless param.nil? end)
|
452
|
+
.auth(Single.new('global')))
|
453
|
+
.response(new_response_handler
|
454
|
+
.deserializer(APIHelper.method(:json_deserialize))
|
455
|
+
.is_api_response(true)
|
456
|
+
.convertor(ApiResponse.method(:create)))
|
457
|
+
.execute
|
654
458
|
end
|
655
459
|
|
656
460
|
# Searches for loyalty rewards. This endpoint accepts a request with no
|
@@ -665,32 +469,20 @@ module Square
|
|
665
469
|
# object definition for field details.
|
666
470
|
# @return [SearchLoyaltyRewardsResponse Hash] response from the API call
|
667
471
|
def search_loyalty_rewards(body:)
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
headers: _headers,
|
683
|
-
parameters: body.to_json
|
684
|
-
)
|
685
|
-
OAuth2.apply(config, _request)
|
686
|
-
_response = execute_request(_request)
|
687
|
-
|
688
|
-
# Return appropriate response type.
|
689
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
690
|
-
_errors = APIHelper.map_response(decoded, ['errors'])
|
691
|
-
ApiResponse.new(
|
692
|
-
_response, data: decoded, errors: _errors
|
693
|
-
)
|
472
|
+
new_api_call_builder
|
473
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
474
|
+
'/v2/loyalty/rewards/search',
|
475
|
+
'default')
|
476
|
+
.header_param(new_parameter('application/json', key: 'Content-Type'))
|
477
|
+
.body_param(new_parameter(body))
|
478
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
479
|
+
.body_serializer(proc do |param| param.to_json unless param.nil? end)
|
480
|
+
.auth(Single.new('global')))
|
481
|
+
.response(new_response_handler
|
482
|
+
.deserializer(APIHelper.method(:json_deserialize))
|
483
|
+
.is_api_response(true)
|
484
|
+
.convertor(ApiResponse.method(:create)))
|
485
|
+
.execute
|
694
486
|
end
|
695
487
|
|
696
488
|
# Deletes a loyalty reward by doing the following:
|
@@ -701,72 +493,42 @@ module Square
|
|
701
493
|
# discounts.
|
702
494
|
# You cannot delete a reward that has reached the terminal state (REDEEMED).
|
703
495
|
# @param [String] reward_id Required parameter: The ID of the [loyalty
|
704
|
-
# reward](
|
496
|
+
# reward](entity:LoyaltyReward) to delete.
|
705
497
|
# @return [DeleteLoyaltyRewardResponse Hash] response from the API call
|
706
498
|
def delete_loyalty_reward(reward_id:)
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
# Prepare and execute HttpRequest.
|
722
|
-
_request = config.http_client.delete(
|
723
|
-
_query_url,
|
724
|
-
headers: _headers
|
725
|
-
)
|
726
|
-
OAuth2.apply(config, _request)
|
727
|
-
_response = execute_request(_request)
|
728
|
-
|
729
|
-
# Return appropriate response type.
|
730
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
731
|
-
_errors = APIHelper.map_response(decoded, ['errors'])
|
732
|
-
ApiResponse.new(
|
733
|
-
_response, data: decoded, errors: _errors
|
734
|
-
)
|
499
|
+
new_api_call_builder
|
500
|
+
.request(new_request_builder(HttpMethodEnum::DELETE,
|
501
|
+
'/v2/loyalty/rewards/{reward_id}',
|
502
|
+
'default')
|
503
|
+
.template_param(new_parameter(reward_id, key: 'reward_id')
|
504
|
+
.should_encode(true))
|
505
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
506
|
+
.auth(Single.new('global')))
|
507
|
+
.response(new_response_handler
|
508
|
+
.deserializer(APIHelper.method(:json_deserialize))
|
509
|
+
.is_api_response(true)
|
510
|
+
.convertor(ApiResponse.method(:create)))
|
511
|
+
.execute
|
735
512
|
end
|
736
513
|
|
737
514
|
# Retrieves a loyalty reward.
|
738
515
|
# @param [String] reward_id Required parameter: The ID of the [loyalty
|
739
|
-
# reward](
|
516
|
+
# reward](entity:LoyaltyReward) to retrieve.
|
740
517
|
# @return [RetrieveLoyaltyRewardResponse Hash] response from the API call
|
741
518
|
def retrieve_loyalty_reward(reward_id:)
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
# Prepare and execute HttpRequest.
|
757
|
-
_request = config.http_client.get(
|
758
|
-
_query_url,
|
759
|
-
headers: _headers
|
760
|
-
)
|
761
|
-
OAuth2.apply(config, _request)
|
762
|
-
_response = execute_request(_request)
|
763
|
-
|
764
|
-
# Return appropriate response type.
|
765
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
766
|
-
_errors = APIHelper.map_response(decoded, ['errors'])
|
767
|
-
ApiResponse.new(
|
768
|
-
_response, data: decoded, errors: _errors
|
769
|
-
)
|
519
|
+
new_api_call_builder
|
520
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
521
|
+
'/v2/loyalty/rewards/{reward_id}',
|
522
|
+
'default')
|
523
|
+
.template_param(new_parameter(reward_id, key: 'reward_id')
|
524
|
+
.should_encode(true))
|
525
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
526
|
+
.auth(Single.new('global')))
|
527
|
+
.response(new_response_handler
|
528
|
+
.deserializer(APIHelper.method(:json_deserialize))
|
529
|
+
.is_api_response(true)
|
530
|
+
.convertor(ApiResponse.method(:create)))
|
531
|
+
.execute
|
770
532
|
end
|
771
533
|
|
772
534
|
# Redeems a loyalty reward.
|
@@ -778,43 +540,29 @@ module Square
|
|
778
540
|
# In other words, points used for the reward cannot be returned
|
779
541
|
# to the account.
|
780
542
|
# @param [String] reward_id Required parameter: The ID of the [loyalty
|
781
|
-
# reward](
|
543
|
+
# reward](entity:LoyaltyReward) to redeem.
|
782
544
|
# @param [RedeemLoyaltyRewardRequest] body Required parameter: An object
|
783
545
|
# containing the fields to POST for the request. See the corresponding
|
784
546
|
# object definition for field details.
|
785
547
|
# @return [RedeemLoyaltyRewardResponse Hash] response from the API call
|
786
548
|
def redeem_loyalty_reward(reward_id:,
|
787
549
|
body:)
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
_request = config.http_client.post(
|
805
|
-
_query_url,
|
806
|
-
headers: _headers,
|
807
|
-
parameters: body.to_json
|
808
|
-
)
|
809
|
-
OAuth2.apply(config, _request)
|
810
|
-
_response = execute_request(_request)
|
811
|
-
|
812
|
-
# Return appropriate response type.
|
813
|
-
decoded = APIHelper.json_deserialize(_response.raw_body)
|
814
|
-
_errors = APIHelper.map_response(decoded, ['errors'])
|
815
|
-
ApiResponse.new(
|
816
|
-
_response, data: decoded, errors: _errors
|
817
|
-
)
|
550
|
+
new_api_call_builder
|
551
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
552
|
+
'/v2/loyalty/rewards/{reward_id}/redeem',
|
553
|
+
'default')
|
554
|
+
.template_param(new_parameter(reward_id, key: 'reward_id')
|
555
|
+
.should_encode(true))
|
556
|
+
.header_param(new_parameter('application/json', key: 'Content-Type'))
|
557
|
+
.body_param(new_parameter(body))
|
558
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
559
|
+
.body_serializer(proc do |param| param.to_json unless param.nil? end)
|
560
|
+
.auth(Single.new('global')))
|
561
|
+
.response(new_response_handler
|
562
|
+
.deserializer(APIHelper.method(:json_deserialize))
|
563
|
+
.is_api_response(true)
|
564
|
+
.convertor(ApiResponse.method(:create)))
|
565
|
+
.execute
|
818
566
|
end
|
819
567
|
end
|
820
568
|
end
|