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
@@ -1,334 +1,335 @@
1
- # square
2
- #
3
- # This file was automatically generated by APIMATIC v2.0
4
- # ( https://apimatic.io ).
5
-
6
- module Square
7
- # CustomersApi
8
- class CustomersApi < BaseApi
9
- def initialize(config, http_call_back: nil)
10
- super(config, http_call_back: http_call_back)
11
- end
12
-
13
- # Lists a business's customers.
14
- # @param [String] cursor Optional parameter: A pagination cursor returned by
15
- # a previous call to this endpoint. Provide this to retrieve the next set of
16
- # results for your original query. See
17
- # [Pagination](/basics/api101/pagination) for more information.
18
- # @param [CustomerSortField] sort_field Optional parameter: Indicates how
19
- # Customers should be sorted. Default: `DEFAULT`.
20
- # @param [SortOrder] sort_order Optional parameter: Indicates whether
21
- # Customers should be sorted in ascending (`ASC`) or descending (`DESC`)
22
- # order. Default: `ASC`.
23
- # @return [ListCustomersResponse Hash] response from the API call
24
- def list_customers(cursor: nil,
25
- sort_field: nil,
26
- sort_order: nil)
27
- # Prepare query url.
28
- _query_builder = config.get_base_uri
29
- _query_builder << '/v2/customers'
30
- _query_builder = APIHelper.append_url_with_query_parameters(
31
- _query_builder,
32
- 'cursor' => cursor,
33
- 'sort_field' => sort_field,
34
- 'sort_order' => sort_order
35
- )
36
- _query_url = APIHelper.clean_url _query_builder
37
-
38
- # Prepare headers.
39
- _headers = {
40
- 'accept' => 'application/json'
41
- }
42
-
43
- # Prepare and execute HttpRequest.
44
- _request = config.http_client.get(
45
- _query_url,
46
- headers: _headers
47
- )
48
- OAuth2.apply(config, _request)
49
- _response = execute_request(_request)
50
-
51
- # Return appropriate response type.
52
- decoded = APIHelper.json_deserialize(_response.raw_body)
53
- _errors = APIHelper.map_response(decoded, ['errors'])
54
- ApiResponse.new(_response, data: decoded, errors: _errors)
55
- end
56
-
57
- # Creates a new customer for a business, which can have associated cards on
58
- # file.
59
- # You must provide __at least one__ of the following values in your request
60
- # to this
61
- # endpoint:
62
- # - `given_name`
63
- # - `family_name`
64
- # - `company_name`
65
- # - `email_address`
66
- # - `phone_number`
67
- # @param [CreateCustomerRequest] body Required parameter: An object
68
- # containing the fields to POST for the request. See the corresponding
69
- # object definition for field details.
70
- # @return [CreateCustomerResponse Hash] response from the API call
71
- def create_customer(body:)
72
- # Prepare query url.
73
- _query_builder = config.get_base_uri
74
- _query_builder << '/v2/customers'
75
- _query_url = APIHelper.clean_url _query_builder
76
-
77
- # Prepare headers.
78
- _headers = {
79
- 'accept' => 'application/json',
80
- 'content-type' => 'application/json; charset=utf-8'
81
- }
82
-
83
- # Prepare and execute HttpRequest.
84
- _request = config.http_client.post(
85
- _query_url,
86
- headers: _headers,
87
- parameters: body.to_json
88
- )
89
- OAuth2.apply(config, _request)
90
- _response = execute_request(_request)
91
-
92
- # Return appropriate response type.
93
- decoded = APIHelper.json_deserialize(_response.raw_body)
94
- _errors = APIHelper.map_response(decoded, ['errors'])
95
- ApiResponse.new(_response, data: decoded, errors: _errors)
96
- end
97
-
98
- # Searches the customer profiles associated with a Square account.
99
- # Calling SearchCustomers without an explicit query parameter returns all
100
- # customer profiles ordered alphabetically based on `given_name` and
101
- # `family_name`.
102
- # @param [SearchCustomersRequest] body Required parameter: An object
103
- # containing the fields to POST for the request. See the corresponding
104
- # object definition for field details.
105
- # @return [SearchCustomersResponse Hash] response from the API call
106
- def search_customers(body:)
107
- # Prepare query url.
108
- _query_builder = config.get_base_uri
109
- _query_builder << '/v2/customers/search'
110
- _query_url = APIHelper.clean_url _query_builder
111
-
112
- # Prepare headers.
113
- _headers = {
114
- 'accept' => 'application/json',
115
- 'content-type' => 'application/json; charset=utf-8'
116
- }
117
-
118
- # Prepare and execute HttpRequest.
119
- _request = config.http_client.post(
120
- _query_url,
121
- headers: _headers,
122
- parameters: body.to_json
123
- )
124
- OAuth2.apply(config, _request)
125
- _response = execute_request(_request)
126
-
127
- # Return appropriate response type.
128
- decoded = APIHelper.json_deserialize(_response.raw_body)
129
- _errors = APIHelper.map_response(decoded, ['errors'])
130
- ApiResponse.new(_response, data: decoded, errors: _errors)
131
- end
132
-
133
- # Deletes a customer from a business, along with any linked cards on file.
134
- # When two profiles
135
- # are merged into a single profile, that profile is assigned a new
136
- # `customer_id`. You must use the
137
- # new `customer_id` to delete merged profiles.
138
- # @param [String] customer_id Required parameter: The ID of the customer to
139
- # delete.
140
- # @return [DeleteCustomerResponse Hash] response from the API call
141
- def delete_customer(customer_id:)
142
- # Prepare query url.
143
- _query_builder = config.get_base_uri
144
- _query_builder << '/v2/customers/{customer_id}'
145
- _query_builder = APIHelper.append_url_with_template_parameters(
146
- _query_builder,
147
- 'customer_id' => customer_id
148
- )
149
- _query_url = APIHelper.clean_url _query_builder
150
-
151
- # Prepare headers.
152
- _headers = {
153
- 'accept' => 'application/json'
154
- }
155
-
156
- # Prepare and execute HttpRequest.
157
- _request = config.http_client.delete(
158
- _query_url,
159
- headers: _headers
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
- # Returns details for a single customer.
171
- # @param [String] customer_id Required parameter: The ID of the customer to
172
- # retrieve.
173
- # @return [RetrieveCustomerResponse Hash] response from the API call
174
- def retrieve_customer(customer_id:)
175
- # Prepare query url.
176
- _query_builder = config.get_base_uri
177
- _query_builder << '/v2/customers/{customer_id}'
178
- _query_builder = APIHelper.append_url_with_template_parameters(
179
- _query_builder,
180
- 'customer_id' => customer_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
- # Updates the details of an existing customer. When two profiles are merged
204
- # into a single profile, that profile is assigned a new `customer_id`. You
205
- # must use
206
- # the new `customer_id` to update merged profiles.
207
- # You cannot edit a customer's cards on file with this endpoint. To make
208
- # changes
209
- # to a card on file, you must delete the existing card on file with the
210
- # [DeleteCustomerCard](#endpoint-customers-deletecustomercard) endpoint,
211
- # then
212
- # create a new one with the
213
- # [CreateCustomerCard](#endpoint-customers-createcustomercard) endpoint.
214
- # @param [String] customer_id Required parameter: The ID of the customer to
215
- # update.
216
- # @param [UpdateCustomerRequest] body Required parameter: An object
217
- # containing the fields to POST for the request. See the corresponding
218
- # object definition for field details.
219
- # @return [UpdateCustomerResponse Hash] response from the API call
220
- def update_customer(customer_id:,
221
- body:)
222
- # Prepare query url.
223
- _query_builder = config.get_base_uri
224
- _query_builder << '/v2/customers/{customer_id}'
225
- _query_builder = APIHelper.append_url_with_template_parameters(
226
- _query_builder,
227
- 'customer_id' => customer_id
228
- )
229
- _query_url = APIHelper.clean_url _query_builder
230
-
231
- # Prepare headers.
232
- _headers = {
233
- 'accept' => 'application/json',
234
- 'content-type' => 'application/json; charset=utf-8'
235
- }
236
-
237
- # Prepare and execute HttpRequest.
238
- _request = config.http_client.put(
239
- _query_url,
240
- headers: _headers,
241
- parameters: body.to_json
242
- )
243
- OAuth2.apply(config, _request)
244
- _response = execute_request(_request)
245
-
246
- # Return appropriate response type.
247
- decoded = APIHelper.json_deserialize(_response.raw_body)
248
- _errors = APIHelper.map_response(decoded, ['errors'])
249
- ApiResponse.new(_response, data: decoded, errors: _errors)
250
- end
251
-
252
- # Adds a card on file to an existing customer.
253
- # As with charges, calls to `CreateCustomerCard` are idempotent. Multiple
254
- # calls with the same card nonce return the same card record that was
255
- # created
256
- # with the provided nonce during the _first_ call.
257
- # Cards on file are automatically updated on a monthly basis to confirm they
258
- # are still valid and can be charged.
259
- # @param [String] customer_id Required parameter: The ID of the customer to
260
- # link the card on file to.
261
- # @param [CreateCustomerCardRequest] body Required parameter: An object
262
- # containing the fields to POST for the request. See the corresponding
263
- # object definition for field details.
264
- # @return [CreateCustomerCardResponse Hash] response from the API call
265
- def create_customer_card(customer_id:,
266
- body:)
267
- # Prepare query url.
268
- _query_builder = config.get_base_uri
269
- _query_builder << '/v2/customers/{customer_id}/cards'
270
- _query_builder = APIHelper.append_url_with_template_parameters(
271
- _query_builder,
272
- 'customer_id' => customer_id
273
- )
274
- _query_url = APIHelper.clean_url _query_builder
275
-
276
- # Prepare headers.
277
- _headers = {
278
- 'accept' => 'application/json',
279
- 'content-type' => 'application/json; charset=utf-8'
280
- }
281
-
282
- # Prepare and execute HttpRequest.
283
- _request = config.http_client.post(
284
- _query_url,
285
- headers: _headers,
286
- parameters: body.to_json
287
- )
288
- OAuth2.apply(config, _request)
289
- _response = execute_request(_request)
290
-
291
- # Return appropriate response type.
292
- decoded = APIHelper.json_deserialize(_response.raw_body)
293
- _errors = APIHelper.map_response(decoded, ['errors'])
294
- ApiResponse.new(_response, data: decoded, errors: _errors)
295
- end
296
-
297
- # Removes a card on file from a customer.
298
- # @param [String] customer_id Required parameter: The ID of the customer
299
- # that the card on file belongs to.
300
- # @param [String] card_id Required parameter: The ID of the card on file to
301
- # delete.
302
- # @return [DeleteCustomerCardResponse Hash] response from the API call
303
- def delete_customer_card(customer_id:,
304
- card_id:)
305
- # Prepare query url.
306
- _query_builder = config.get_base_uri
307
- _query_builder << '/v2/customers/{customer_id}/cards/{card_id}'
308
- _query_builder = APIHelper.append_url_with_template_parameters(
309
- _query_builder,
310
- 'customer_id' => customer_id,
311
- 'card_id' => card_id
312
- )
313
- _query_url = APIHelper.clean_url _query_builder
314
-
315
- # Prepare headers.
316
- _headers = {
317
- 'accept' => 'application/json'
318
- }
319
-
320
- # Prepare and execute HttpRequest.
321
- _request = config.http_client.delete(
322
- _query_url,
323
- headers: _headers
324
- )
325
- OAuth2.apply(config, _request)
326
- _response = execute_request(_request)
327
-
328
- # Return appropriate response type.
329
- decoded = APIHelper.json_deserialize(_response.raw_body)
330
- _errors = APIHelper.map_response(decoded, ['errors'])
331
- ApiResponse.new(_response, data: decoded, errors: _errors)
332
- end
333
- end
334
- end
1
+ # square
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Square
7
+ # CustomersApi
8
+ class CustomersApi < BaseApi
9
+ def initialize(config, http_call_back: nil)
10
+ super(config, http_call_back: http_call_back)
11
+ end
12
+
13
+ # Lists a business's customers.
14
+ # @param [String] cursor Optional parameter: A pagination cursor returned by
15
+ # a previous call to this endpoint. Provide this to retrieve the next set of
16
+ # results for your original query. See
17
+ # [Pagination](https://developer.squareup.com/docs/basics/api101/pagination)
18
+ # for more information.
19
+ # @param [CustomerSortField] sort_field Optional parameter: Indicates how
20
+ # Customers should be sorted. Default: `DEFAULT`.
21
+ # @param [SortOrder] sort_order Optional parameter: Indicates whether
22
+ # Customers should be sorted in ascending (`ASC`) or descending (`DESC`)
23
+ # order. Default: `ASC`.
24
+ # @return [ListCustomersResponse Hash] response from the API call
25
+ def list_customers(cursor: nil,
26
+ sort_field: nil,
27
+ sort_order: nil)
28
+ # Prepare query url.
29
+ _query_builder = config.get_base_uri
30
+ _query_builder << '/v2/customers'
31
+ _query_builder = APIHelper.append_url_with_query_parameters(
32
+ _query_builder,
33
+ 'cursor' => cursor,
34
+ 'sort_field' => sort_field,
35
+ 'sort_order' => sort_order
36
+ )
37
+ _query_url = APIHelper.clean_url _query_builder
38
+
39
+ # Prepare headers.
40
+ _headers = {
41
+ 'accept' => 'application/json'
42
+ }
43
+
44
+ # Prepare and execute HttpRequest.
45
+ _request = config.http_client.get(
46
+ _query_url,
47
+ headers: _headers
48
+ )
49
+ OAuth2.apply(config, _request)
50
+ _response = execute_request(_request)
51
+
52
+ # Return appropriate response type.
53
+ decoded = APIHelper.json_deserialize(_response.raw_body)
54
+ _errors = APIHelper.map_response(decoded, ['errors'])
55
+ ApiResponse.new(_response, data: decoded, errors: _errors)
56
+ end
57
+
58
+ # Creates a new customer for a business, which can have associated cards on
59
+ # file.
60
+ # You must provide __at least one__ of the following values in your request
61
+ # to this
62
+ # endpoint:
63
+ # - `given_name`
64
+ # - `family_name`
65
+ # - `company_name`
66
+ # - `email_address`
67
+ # - `phone_number`
68
+ # @param [CreateCustomerRequest] body Required parameter: An object
69
+ # containing the fields to POST for the request. See the corresponding
70
+ # object definition for field details.
71
+ # @return [CreateCustomerResponse Hash] response from the API call
72
+ def create_customer(body:)
73
+ # Prepare query url.
74
+ _query_builder = config.get_base_uri
75
+ _query_builder << '/v2/customers'
76
+ _query_url = APIHelper.clean_url _query_builder
77
+
78
+ # Prepare headers.
79
+ _headers = {
80
+ 'accept' => 'application/json',
81
+ 'content-type' => 'application/json; charset=utf-8'
82
+ }
83
+
84
+ # Prepare and execute HttpRequest.
85
+ _request = config.http_client.post(
86
+ _query_url,
87
+ headers: _headers,
88
+ parameters: body.to_json
89
+ )
90
+ OAuth2.apply(config, _request)
91
+ _response = execute_request(_request)
92
+
93
+ # Return appropriate response type.
94
+ decoded = APIHelper.json_deserialize(_response.raw_body)
95
+ _errors = APIHelper.map_response(decoded, ['errors'])
96
+ ApiResponse.new(_response, data: decoded, errors: _errors)
97
+ end
98
+
99
+ # Searches the customer profiles associated with a Square account.
100
+ # Calling SearchCustomers without an explicit query parameter returns all
101
+ # customer profiles ordered alphabetically based on `given_name` and
102
+ # `family_name`.
103
+ # @param [SearchCustomersRequest] body Required parameter: An object
104
+ # containing the fields to POST for the request. See the corresponding
105
+ # object definition for field details.
106
+ # @return [SearchCustomersResponse Hash] response from the API call
107
+ def search_customers(body:)
108
+ # Prepare query url.
109
+ _query_builder = config.get_base_uri
110
+ _query_builder << '/v2/customers/search'
111
+ _query_url = APIHelper.clean_url _query_builder
112
+
113
+ # Prepare headers.
114
+ _headers = {
115
+ 'accept' => 'application/json',
116
+ 'content-type' => 'application/json; charset=utf-8'
117
+ }
118
+
119
+ # Prepare and execute HttpRequest.
120
+ _request = config.http_client.post(
121
+ _query_url,
122
+ headers: _headers,
123
+ parameters: body.to_json
124
+ )
125
+ OAuth2.apply(config, _request)
126
+ _response = execute_request(_request)
127
+
128
+ # Return appropriate response type.
129
+ decoded = APIHelper.json_deserialize(_response.raw_body)
130
+ _errors = APIHelper.map_response(decoded, ['errors'])
131
+ ApiResponse.new(_response, data: decoded, errors: _errors)
132
+ end
133
+
134
+ # Deletes a customer from a business, along with any linked cards on file.
135
+ # When two profiles
136
+ # are merged into a single profile, that profile is assigned a new
137
+ # `customer_id`. You must use the
138
+ # new `customer_id` to delete merged profiles.
139
+ # @param [String] customer_id Required parameter: The ID of the customer to
140
+ # delete.
141
+ # @return [DeleteCustomerResponse Hash] response from the API call
142
+ def delete_customer(customer_id:)
143
+ # Prepare query url.
144
+ _query_builder = config.get_base_uri
145
+ _query_builder << '/v2/customers/{customer_id}'
146
+ _query_builder = APIHelper.append_url_with_template_parameters(
147
+ _query_builder,
148
+ 'customer_id' => customer_id
149
+ )
150
+ _query_url = APIHelper.clean_url _query_builder
151
+
152
+ # Prepare headers.
153
+ _headers = {
154
+ 'accept' => 'application/json'
155
+ }
156
+
157
+ # Prepare and execute HttpRequest.
158
+ _request = config.http_client.delete(
159
+ _query_url,
160
+ headers: _headers
161
+ )
162
+ OAuth2.apply(config, _request)
163
+ _response = execute_request(_request)
164
+
165
+ # Return appropriate response type.
166
+ decoded = APIHelper.json_deserialize(_response.raw_body)
167
+ _errors = APIHelper.map_response(decoded, ['errors'])
168
+ ApiResponse.new(_response, data: decoded, errors: _errors)
169
+ end
170
+
171
+ # Returns details for a single customer.
172
+ # @param [String] customer_id Required parameter: The ID of the customer to
173
+ # retrieve.
174
+ # @return [RetrieveCustomerResponse Hash] response from the API call
175
+ def retrieve_customer(customer_id:)
176
+ # Prepare query url.
177
+ _query_builder = config.get_base_uri
178
+ _query_builder << '/v2/customers/{customer_id}'
179
+ _query_builder = APIHelper.append_url_with_template_parameters(
180
+ _query_builder,
181
+ 'customer_id' => customer_id
182
+ )
183
+ _query_url = APIHelper.clean_url _query_builder
184
+
185
+ # Prepare headers.
186
+ _headers = {
187
+ 'accept' => 'application/json'
188
+ }
189
+
190
+ # Prepare and execute HttpRequest.
191
+ _request = config.http_client.get(
192
+ _query_url,
193
+ headers: _headers
194
+ )
195
+ OAuth2.apply(config, _request)
196
+ _response = execute_request(_request)
197
+
198
+ # Return appropriate response type.
199
+ decoded = APIHelper.json_deserialize(_response.raw_body)
200
+ _errors = APIHelper.map_response(decoded, ['errors'])
201
+ ApiResponse.new(_response, data: decoded, errors: _errors)
202
+ end
203
+
204
+ # Updates the details of an existing customer. When two profiles are merged
205
+ # into a single profile, that profile is assigned a new `customer_id`. You
206
+ # must use
207
+ # the new `customer_id` to update merged profiles.
208
+ # You cannot edit a customer's cards on file with this endpoint. To make
209
+ # changes
210
+ # to a card on file, you must delete the existing card on file with the
211
+ # [DeleteCustomerCard](#endpoint-customers-deletecustomercard) endpoint,
212
+ # then
213
+ # create a new one with the
214
+ # [CreateCustomerCard](#endpoint-customers-createcustomercard) endpoint.
215
+ # @param [String] customer_id Required parameter: The ID of the customer to
216
+ # update.
217
+ # @param [UpdateCustomerRequest] body Required parameter: An object
218
+ # containing the fields to POST for the request. See the corresponding
219
+ # object definition for field details.
220
+ # @return [UpdateCustomerResponse Hash] response from the API call
221
+ def update_customer(customer_id:,
222
+ body:)
223
+ # Prepare query url.
224
+ _query_builder = config.get_base_uri
225
+ _query_builder << '/v2/customers/{customer_id}'
226
+ _query_builder = APIHelper.append_url_with_template_parameters(
227
+ _query_builder,
228
+ 'customer_id' => customer_id
229
+ )
230
+ _query_url = APIHelper.clean_url _query_builder
231
+
232
+ # Prepare headers.
233
+ _headers = {
234
+ 'accept' => 'application/json',
235
+ 'content-type' => 'application/json; charset=utf-8'
236
+ }
237
+
238
+ # Prepare and execute HttpRequest.
239
+ _request = config.http_client.put(
240
+ _query_url,
241
+ headers: _headers,
242
+ parameters: body.to_json
243
+ )
244
+ OAuth2.apply(config, _request)
245
+ _response = execute_request(_request)
246
+
247
+ # Return appropriate response type.
248
+ decoded = APIHelper.json_deserialize(_response.raw_body)
249
+ _errors = APIHelper.map_response(decoded, ['errors'])
250
+ ApiResponse.new(_response, data: decoded, errors: _errors)
251
+ end
252
+
253
+ # Adds a card on file to an existing customer.
254
+ # As with charges, calls to `CreateCustomerCard` are idempotent. Multiple
255
+ # calls with the same card nonce return the same card record that was
256
+ # created
257
+ # with the provided nonce during the _first_ call.
258
+ # Cards on file are automatically updated on a monthly basis to confirm they
259
+ # are still valid and can be charged.
260
+ # @param [String] customer_id Required parameter: The Square ID of the
261
+ # customer profile the card is linked to.
262
+ # @param [CreateCustomerCardRequest] body Required parameter: An object
263
+ # containing the fields to POST for the request. See the corresponding
264
+ # object definition for field details.
265
+ # @return [CreateCustomerCardResponse Hash] response from the API call
266
+ def create_customer_card(customer_id:,
267
+ body:)
268
+ # Prepare query url.
269
+ _query_builder = config.get_base_uri
270
+ _query_builder << '/v2/customers/{customer_id}/cards'
271
+ _query_builder = APIHelper.append_url_with_template_parameters(
272
+ _query_builder,
273
+ 'customer_id' => customer_id
274
+ )
275
+ _query_url = APIHelper.clean_url _query_builder
276
+
277
+ # Prepare headers.
278
+ _headers = {
279
+ 'accept' => 'application/json',
280
+ 'content-type' => 'application/json; charset=utf-8'
281
+ }
282
+
283
+ # Prepare and execute HttpRequest.
284
+ _request = config.http_client.post(
285
+ _query_url,
286
+ headers: _headers,
287
+ parameters: body.to_json
288
+ )
289
+ OAuth2.apply(config, _request)
290
+ _response = execute_request(_request)
291
+
292
+ # Return appropriate response type.
293
+ decoded = APIHelper.json_deserialize(_response.raw_body)
294
+ _errors = APIHelper.map_response(decoded, ['errors'])
295
+ ApiResponse.new(_response, data: decoded, errors: _errors)
296
+ end
297
+
298
+ # Removes a card on file from a customer.
299
+ # @param [String] customer_id Required parameter: The ID of the customer
300
+ # that the card on file belongs to.
301
+ # @param [String] card_id Required parameter: The ID of the card on file to
302
+ # delete.
303
+ # @return [DeleteCustomerCardResponse Hash] response from the API call
304
+ def delete_customer_card(customer_id:,
305
+ card_id:)
306
+ # Prepare query url.
307
+ _query_builder = config.get_base_uri
308
+ _query_builder << '/v2/customers/{customer_id}/cards/{card_id}'
309
+ _query_builder = APIHelper.append_url_with_template_parameters(
310
+ _query_builder,
311
+ 'customer_id' => customer_id,
312
+ 'card_id' => card_id
313
+ )
314
+ _query_url = APIHelper.clean_url _query_builder
315
+
316
+ # Prepare headers.
317
+ _headers = {
318
+ 'accept' => 'application/json'
319
+ }
320
+
321
+ # Prepare and execute HttpRequest.
322
+ _request = config.http_client.delete(
323
+ _query_url,
324
+ headers: _headers
325
+ )
326
+ OAuth2.apply(config, _request)
327
+ _response = execute_request(_request)
328
+
329
+ # Return appropriate response type.
330
+ decoded = APIHelper.json_deserialize(_response.raw_body)
331
+ _errors = APIHelper.map_response(decoded, ['errors'])
332
+ ApiResponse.new(_response, data: decoded, errors: _errors)
333
+ end
334
+ end
335
+ end