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,49 @@
1
+ module Square
2
+ # CheckoutApi
3
+ class CheckoutApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Links a `checkoutId` to a `checkout_page_url` that customers will
9
+ # be directed to in order to provide their payment information using a
10
+ # payment processing workflow hosted on connect.squareup.com.
11
+ # @param [String] location_id Required parameter: The ID of the business
12
+ # location to associate the checkout with.
13
+ # @param [CreateCheckoutRequest] body Required parameter: An object
14
+ # containing the fields to POST for the request. See the corresponding
15
+ # object definition for field details.
16
+ # @return [CreateCheckoutResponse Hash] response from the API call
17
+ def create_checkout(location_id:,
18
+ body:)
19
+ # Prepare query url.
20
+ _query_builder = config.get_base_uri
21
+ _query_builder << '/v2/locations/{location_id}/checkouts'
22
+ _query_builder = APIHelper.append_url_with_template_parameters(
23
+ _query_builder,
24
+ 'location_id' => location_id
25
+ )
26
+ _query_url = APIHelper.clean_url _query_builder
27
+
28
+ # Prepare headers.
29
+ _headers = {
30
+ 'accept' => 'application/json',
31
+ 'content-type' => 'application/json; charset=utf-8'
32
+ }
33
+
34
+ # Prepare and execute HttpRequest.
35
+ _request = config.http_client.post(
36
+ _query_url,
37
+ headers: _headers,
38
+ parameters: body.to_json
39
+ )
40
+ OAuth2.apply(config, _request)
41
+ _response = execute_request(_request)
42
+
43
+ # Return appropriate response type.
44
+ decoded = APIHelper.json_deserialize(_response.raw_body)
45
+ _errors = APIHelper.map_response(decoded, ['errors'])
46
+ ApiResponse.new(_response, data: decoded, errors: _errors)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,182 @@
1
+ module Square
2
+ # CustomerGroupsApi
3
+ class CustomerGroupsApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Retrieves the list of customer groups of a business.
9
+ # @param [String] cursor Optional parameter: A pagination cursor returned by
10
+ # a previous call to this endpoint. Provide this to retrieve the next set of
11
+ # results for your original query. See the [Pagination
12
+ # guide](https://developer.squareup.com/docs/working-with-apis/pagination)
13
+ # for more information.
14
+ # @return [ListCustomerGroupsResponse Hash] response from the API call
15
+ def list_customer_groups(cursor: nil)
16
+ # Prepare query url.
17
+ _query_builder = config.get_base_uri
18
+ _query_builder << '/v2/customers/groups'
19
+ _query_builder = APIHelper.append_url_with_query_parameters(
20
+ _query_builder,
21
+ 'cursor' => cursor
22
+ )
23
+ _query_url = APIHelper.clean_url _query_builder
24
+
25
+ # Prepare headers.
26
+ _headers = {
27
+ 'accept' => 'application/json'
28
+ }
29
+
30
+ # Prepare and execute HttpRequest.
31
+ _request = config.http_client.get(
32
+ _query_url,
33
+ headers: _headers
34
+ )
35
+ OAuth2.apply(config, _request)
36
+ _response = execute_request(_request)
37
+
38
+ # Return appropriate response type.
39
+ decoded = APIHelper.json_deserialize(_response.raw_body)
40
+ _errors = APIHelper.map_response(decoded, ['errors'])
41
+ ApiResponse.new(_response, data: decoded, errors: _errors)
42
+ end
43
+
44
+ # Creates a new customer group for a business.
45
+ # The request must include the `name` value of the group.
46
+ # @param [CreateCustomerGroupRequest] body Required parameter: An object
47
+ # containing the fields to POST for the request. See the corresponding
48
+ # object definition for field details.
49
+ # @return [CreateCustomerGroupResponse Hash] response from the API call
50
+ def create_customer_group(body:)
51
+ # Prepare query url.
52
+ _query_builder = config.get_base_uri
53
+ _query_builder << '/v2/customers/groups'
54
+ _query_url = APIHelper.clean_url _query_builder
55
+
56
+ # Prepare headers.
57
+ _headers = {
58
+ 'accept' => 'application/json',
59
+ 'content-type' => 'application/json; charset=utf-8'
60
+ }
61
+
62
+ # Prepare and execute HttpRequest.
63
+ _request = config.http_client.post(
64
+ _query_url,
65
+ headers: _headers,
66
+ parameters: body.to_json
67
+ )
68
+ OAuth2.apply(config, _request)
69
+ _response = execute_request(_request)
70
+
71
+ # Return appropriate response type.
72
+ decoded = APIHelper.json_deserialize(_response.raw_body)
73
+ _errors = APIHelper.map_response(decoded, ['errors'])
74
+ ApiResponse.new(_response, data: decoded, errors: _errors)
75
+ end
76
+
77
+ # Deletes a customer group as identified by the `group_id` value.
78
+ # @param [String] group_id Required parameter: The ID of the customer group
79
+ # to delete.
80
+ # @return [DeleteCustomerGroupResponse Hash] response from the API call
81
+ def delete_customer_group(group_id:)
82
+ # Prepare query url.
83
+ _query_builder = config.get_base_uri
84
+ _query_builder << '/v2/customers/groups/{group_id}'
85
+ _query_builder = APIHelper.append_url_with_template_parameters(
86
+ _query_builder,
87
+ 'group_id' => group_id
88
+ )
89
+ _query_url = APIHelper.clean_url _query_builder
90
+
91
+ # Prepare headers.
92
+ _headers = {
93
+ 'accept' => 'application/json'
94
+ }
95
+
96
+ # Prepare and execute HttpRequest.
97
+ _request = config.http_client.delete(
98
+ _query_url,
99
+ headers: _headers
100
+ )
101
+ OAuth2.apply(config, _request)
102
+ _response = execute_request(_request)
103
+
104
+ # Return appropriate response type.
105
+ decoded = APIHelper.json_deserialize(_response.raw_body)
106
+ _errors = APIHelper.map_response(decoded, ['errors'])
107
+ ApiResponse.new(_response, data: decoded, errors: _errors)
108
+ end
109
+
110
+ # Retrieves a specific customer group as identified by the `group_id` value.
111
+ # @param [String] group_id Required parameter: The ID of the customer group
112
+ # to retrieve.
113
+ # @return [RetrieveCustomerGroupResponse Hash] response from the API call
114
+ def retrieve_customer_group(group_id:)
115
+ # Prepare query url.
116
+ _query_builder = config.get_base_uri
117
+ _query_builder << '/v2/customers/groups/{group_id}'
118
+ _query_builder = APIHelper.append_url_with_template_parameters(
119
+ _query_builder,
120
+ 'group_id' => group_id
121
+ )
122
+ _query_url = APIHelper.clean_url _query_builder
123
+
124
+ # Prepare headers.
125
+ _headers = {
126
+ 'accept' => 'application/json'
127
+ }
128
+
129
+ # Prepare and execute HttpRequest.
130
+ _request = config.http_client.get(
131
+ _query_url,
132
+ headers: _headers
133
+ )
134
+ OAuth2.apply(config, _request)
135
+ _response = execute_request(_request)
136
+
137
+ # Return appropriate response type.
138
+ decoded = APIHelper.json_deserialize(_response.raw_body)
139
+ _errors = APIHelper.map_response(decoded, ['errors'])
140
+ ApiResponse.new(_response, data: decoded, errors: _errors)
141
+ end
142
+
143
+ # Updates a customer group as identified by the `group_id` value.
144
+ # @param [String] group_id Required parameter: The ID of the customer group
145
+ # to update.
146
+ # @param [UpdateCustomerGroupRequest] body Required parameter: An object
147
+ # containing the fields to POST for the request. See the corresponding
148
+ # object definition for field details.
149
+ # @return [UpdateCustomerGroupResponse Hash] response from the API call
150
+ def update_customer_group(group_id:,
151
+ body:)
152
+ # Prepare query url.
153
+ _query_builder = config.get_base_uri
154
+ _query_builder << '/v2/customers/groups/{group_id}'
155
+ _query_builder = APIHelper.append_url_with_template_parameters(
156
+ _query_builder,
157
+ 'group_id' => group_id
158
+ )
159
+ _query_url = APIHelper.clean_url _query_builder
160
+
161
+ # Prepare headers.
162
+ _headers = {
163
+ 'accept' => 'application/json',
164
+ 'content-type' => 'application/json; charset=utf-8'
165
+ }
166
+
167
+ # Prepare and execute HttpRequest.
168
+ _request = config.http_client.put(
169
+ _query_url,
170
+ headers: _headers,
171
+ parameters: body.to_json
172
+ )
173
+ OAuth2.apply(config, _request)
174
+ _response = execute_request(_request)
175
+
176
+ # Return appropriate response type.
177
+ decoded = APIHelper.json_deserialize(_response.raw_body)
178
+ _errors = APIHelper.map_response(decoded, ['errors'])
179
+ ApiResponse.new(_response, data: decoded, errors: _errors)
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,78 @@
1
+ module Square
2
+ # CustomerSegmentsApi
3
+ class CustomerSegmentsApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Retrieves the list of customer segments of a business.
9
+ # @param [String] cursor Optional parameter: A pagination cursor returned by
10
+ # previous calls to __ListCustomerSegments__. Used to retrieve the next set
11
+ # of query results. See the [Pagination
12
+ # guide](https://developer.squareup.com/docs/docs/working-with-apis/paginati
13
+ # on) for more information.
14
+ # @return [ListCustomerSegmentsResponse Hash] response from the API call
15
+ def list_customer_segments(cursor: nil)
16
+ # Prepare query url.
17
+ _query_builder = config.get_base_uri
18
+ _query_builder << '/v2/customers/segments'
19
+ _query_builder = APIHelper.append_url_with_query_parameters(
20
+ _query_builder,
21
+ 'cursor' => cursor
22
+ )
23
+ _query_url = APIHelper.clean_url _query_builder
24
+
25
+ # Prepare headers.
26
+ _headers = {
27
+ 'accept' => 'application/json'
28
+ }
29
+
30
+ # Prepare and execute HttpRequest.
31
+ _request = config.http_client.get(
32
+ _query_url,
33
+ headers: _headers
34
+ )
35
+ OAuth2.apply(config, _request)
36
+ _response = execute_request(_request)
37
+
38
+ # Return appropriate response type.
39
+ decoded = APIHelper.json_deserialize(_response.raw_body)
40
+ _errors = APIHelper.map_response(decoded, ['errors'])
41
+ ApiResponse.new(_response, data: decoded, errors: _errors)
42
+ end
43
+
44
+ # Retrieves a specific customer segment as identified by the `segment_id`
45
+ # value.
46
+ # @param [String] segment_id Required parameter: The Square-issued ID of the
47
+ # customer segment.
48
+ # @return [RetrieveCustomerSegmentResponse Hash] response from the API call
49
+ def retrieve_customer_segment(segment_id:)
50
+ # Prepare query url.
51
+ _query_builder = config.get_base_uri
52
+ _query_builder << '/v2/customers/segments/{segment_id}'
53
+ _query_builder = APIHelper.append_url_with_template_parameters(
54
+ _query_builder,
55
+ 'segment_id' => segment_id
56
+ )
57
+ _query_url = APIHelper.clean_url _query_builder
58
+
59
+ # Prepare headers.
60
+ _headers = {
61
+ 'accept' => 'application/json'
62
+ }
63
+
64
+ # Prepare and execute HttpRequest.
65
+ _request = config.http_client.get(
66
+ _query_url,
67
+ headers: _headers
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
+ end
78
+ end
@@ -0,0 +1,418 @@
1
+ module Square
2
+ # CustomersApi
3
+ class CustomersApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Lists customer profiles associated with a Square account.
9
+ # Under normal operating conditions, newly created or updated customer
10
+ # profiles become available
11
+ # for the listing operation in well under 30 seconds. Occasionally,
12
+ # propagation of the new or updated
13
+ # profiles can take closer to one minute or longer, espeically during
14
+ # network incidents and outages.
15
+ # @param [String] cursor Optional parameter: A pagination cursor returned by
16
+ # a previous call to this endpoint. Provide this to retrieve the next set of
17
+ # results for your original query. See the [Pagination
18
+ # guide](https://developer.squareup.com/docs/working-with-apis/pagination)
19
+ # for more information.
20
+ # @param [CustomerSortField] sort_field Optional parameter: Indicates how
21
+ # Customers should be sorted. Default: `DEFAULT`.
22
+ # @param [SortOrder] sort_order Optional parameter: Indicates whether
23
+ # Customers should be sorted in ascending (`ASC`) or descending (`DESC`)
24
+ # order. Default: `ASC`.
25
+ # @return [ListCustomersResponse Hash] response from the API call
26
+ def list_customers(cursor: nil,
27
+ sort_field: nil,
28
+ sort_order: nil)
29
+ # Prepare query url.
30
+ _query_builder = config.get_base_uri
31
+ _query_builder << '/v2/customers'
32
+ _query_builder = APIHelper.append_url_with_query_parameters(
33
+ _query_builder,
34
+ 'cursor' => cursor,
35
+ 'sort_field' => sort_field,
36
+ 'sort_order' => sort_order
37
+ )
38
+ _query_url = APIHelper.clean_url _query_builder
39
+
40
+ # Prepare headers.
41
+ _headers = {
42
+ 'accept' => 'application/json'
43
+ }
44
+
45
+ # Prepare and execute HttpRequest.
46
+ _request = config.http_client.get(
47
+ _query_url,
48
+ headers: _headers
49
+ )
50
+ OAuth2.apply(config, _request)
51
+ _response = execute_request(_request)
52
+
53
+ # Return appropriate response type.
54
+ decoded = APIHelper.json_deserialize(_response.raw_body)
55
+ _errors = APIHelper.map_response(decoded, ['errors'])
56
+ ApiResponse.new(_response, data: decoded, errors: _errors)
57
+ end
58
+
59
+ # Creates a new customer for a business, which can have associated cards on
60
+ # file.
61
+ # You must provide __at least one__ of the following values in your request
62
+ # to this
63
+ # endpoint:
64
+ # - `given_name`
65
+ # - `family_name`
66
+ # - `company_name`
67
+ # - `email_address`
68
+ # - `phone_number`
69
+ # @param [CreateCustomerRequest] body Required parameter: An object
70
+ # containing the fields to POST for the request. See the corresponding
71
+ # object definition for field details.
72
+ # @return [CreateCustomerResponse Hash] response from the API call
73
+ def create_customer(body:)
74
+ # Prepare query url.
75
+ _query_builder = config.get_base_uri
76
+ _query_builder << '/v2/customers'
77
+ _query_url = APIHelper.clean_url _query_builder
78
+
79
+ # Prepare headers.
80
+ _headers = {
81
+ 'accept' => 'application/json',
82
+ 'content-type' => 'application/json; charset=utf-8'
83
+ }
84
+
85
+ # Prepare and execute HttpRequest.
86
+ _request = config.http_client.post(
87
+ _query_url,
88
+ headers: _headers,
89
+ parameters: body.to_json
90
+ )
91
+ OAuth2.apply(config, _request)
92
+ _response = execute_request(_request)
93
+
94
+ # Return appropriate response type.
95
+ decoded = APIHelper.json_deserialize(_response.raw_body)
96
+ _errors = APIHelper.map_response(decoded, ['errors'])
97
+ ApiResponse.new(_response, data: decoded, errors: _errors)
98
+ end
99
+
100
+ # Searches the customer profiles associated with a Square account using
101
+ # one or more supported query filters.
102
+ # Calling `SearchCustomers` without any explicit query filter returns all
103
+ # customer profiles ordered alphabetically based on `given_name` and
104
+ # `family_name`.
105
+ # Under normal operating conditions, newly created or updated customer
106
+ # profiles become available
107
+ # for the search operation in well under 30 seconds. Occasionally,
108
+ # propagation of the new or updated
109
+ # profiles can take closer to one minute or longer, espeically during
110
+ # network incidents and outages.
111
+ # @param [SearchCustomersRequest] body Required parameter: An object
112
+ # containing the fields to POST for the request. See the corresponding
113
+ # object definition for field details.
114
+ # @return [SearchCustomersResponse Hash] response from the API call
115
+ def search_customers(body:)
116
+ # Prepare query url.
117
+ _query_builder = config.get_base_uri
118
+ _query_builder << '/v2/customers/search'
119
+ _query_url = APIHelper.clean_url _query_builder
120
+
121
+ # Prepare headers.
122
+ _headers = {
123
+ 'accept' => 'application/json',
124
+ 'content-type' => 'application/json; charset=utf-8'
125
+ }
126
+
127
+ # Prepare and execute HttpRequest.
128
+ _request = config.http_client.post(
129
+ _query_url,
130
+ headers: _headers,
131
+ parameters: body.to_json
132
+ )
133
+ OAuth2.apply(config, _request)
134
+ _response = execute_request(_request)
135
+
136
+ # Return appropriate response type.
137
+ decoded = APIHelper.json_deserialize(_response.raw_body)
138
+ _errors = APIHelper.map_response(decoded, ['errors'])
139
+ ApiResponse.new(_response, data: decoded, errors: _errors)
140
+ end
141
+
142
+ # Deletes a customer from a business, along with any linked cards on file.
143
+ # When two profiles
144
+ # are merged into a single profile, that profile is assigned a new
145
+ # `customer_id`. You must use the
146
+ # new `customer_id` to delete merged profiles.
147
+ # @param [String] customer_id Required parameter: The ID of the customer to
148
+ # delete.
149
+ # @return [DeleteCustomerResponse Hash] response from the API call
150
+ def delete_customer(customer_id:)
151
+ # Prepare query url.
152
+ _query_builder = config.get_base_uri
153
+ _query_builder << '/v2/customers/{customer_id}'
154
+ _query_builder = APIHelper.append_url_with_template_parameters(
155
+ _query_builder,
156
+ 'customer_id' => customer_id
157
+ )
158
+ _query_url = APIHelper.clean_url _query_builder
159
+
160
+ # Prepare headers.
161
+ _headers = {
162
+ 'accept' => 'application/json'
163
+ }
164
+
165
+ # Prepare and execute HttpRequest.
166
+ _request = config.http_client.delete(
167
+ _query_url,
168
+ headers: _headers
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(_response, data: decoded, errors: _errors)
177
+ end
178
+
179
+ # Returns details for a single customer.
180
+ # @param [String] customer_id Required parameter: The ID of the customer to
181
+ # retrieve.
182
+ # @return [RetrieveCustomerResponse Hash] response from the API call
183
+ def retrieve_customer(customer_id:)
184
+ # Prepare query url.
185
+ _query_builder = config.get_base_uri
186
+ _query_builder << '/v2/customers/{customer_id}'
187
+ _query_builder = APIHelper.append_url_with_template_parameters(
188
+ _query_builder,
189
+ 'customer_id' => customer_id
190
+ )
191
+ _query_url = APIHelper.clean_url _query_builder
192
+
193
+ # Prepare headers.
194
+ _headers = {
195
+ 'accept' => 'application/json'
196
+ }
197
+
198
+ # Prepare and execute HttpRequest.
199
+ _request = config.http_client.get(
200
+ _query_url,
201
+ headers: _headers
202
+ )
203
+ OAuth2.apply(config, _request)
204
+ _response = execute_request(_request)
205
+
206
+ # Return appropriate response type.
207
+ decoded = APIHelper.json_deserialize(_response.raw_body)
208
+ _errors = APIHelper.map_response(decoded, ['errors'])
209
+ ApiResponse.new(_response, data: decoded, errors: _errors)
210
+ end
211
+
212
+ # Updates the details of an existing customer. When two profiles are merged
213
+ # into a single profile, that profile is assigned a new `customer_id`. You
214
+ # must use
215
+ # the new `customer_id` to update merged profiles.
216
+ # You cannot edit a customer's cards on file with this endpoint. To make
217
+ # changes
218
+ # to a card on file, you must delete the existing card on file with the
219
+ # [DeleteCustomerCard](#endpoint-deletecustomercard) endpoint, then create a
220
+ # new one with the
221
+ # [CreateCustomerCard](#endpoint-createcustomercard) endpoint.
222
+ # @param [String] customer_id Required parameter: The ID of the customer to
223
+ # update.
224
+ # @param [UpdateCustomerRequest] body Required parameter: An object
225
+ # containing the fields to POST for the request. See the corresponding
226
+ # object definition for field details.
227
+ # @return [UpdateCustomerResponse Hash] response from the API call
228
+ def update_customer(customer_id:,
229
+ body:)
230
+ # Prepare query url.
231
+ _query_builder = config.get_base_uri
232
+ _query_builder << '/v2/customers/{customer_id}'
233
+ _query_builder = APIHelper.append_url_with_template_parameters(
234
+ _query_builder,
235
+ 'customer_id' => customer_id
236
+ )
237
+ _query_url = APIHelper.clean_url _query_builder
238
+
239
+ # Prepare headers.
240
+ _headers = {
241
+ 'accept' => 'application/json',
242
+ 'content-type' => 'application/json; charset=utf-8'
243
+ }
244
+
245
+ # Prepare and execute HttpRequest.
246
+ _request = config.http_client.put(
247
+ _query_url,
248
+ headers: _headers,
249
+ parameters: body.to_json
250
+ )
251
+ OAuth2.apply(config, _request)
252
+ _response = execute_request(_request)
253
+
254
+ # Return appropriate response type.
255
+ decoded = APIHelper.json_deserialize(_response.raw_body)
256
+ _errors = APIHelper.map_response(decoded, ['errors'])
257
+ ApiResponse.new(_response, data: decoded, errors: _errors)
258
+ end
259
+
260
+ # Adds a card on file to an existing customer.
261
+ # As with charges, calls to `CreateCustomerCard` are idempotent. Multiple
262
+ # calls with the same card nonce return the same card record that was
263
+ # created
264
+ # with the provided nonce during the _first_ call.
265
+ # @param [String] customer_id Required parameter: The Square ID of the
266
+ # customer profile the card is linked to.
267
+ # @param [CreateCustomerCardRequest] body Required parameter: An object
268
+ # containing the fields to POST for the request. See the corresponding
269
+ # object definition for field details.
270
+ # @return [CreateCustomerCardResponse Hash] response from the API call
271
+ def create_customer_card(customer_id:,
272
+ body:)
273
+ # Prepare query url.
274
+ _query_builder = config.get_base_uri
275
+ _query_builder << '/v2/customers/{customer_id}/cards'
276
+ _query_builder = APIHelper.append_url_with_template_parameters(
277
+ _query_builder,
278
+ 'customer_id' => customer_id
279
+ )
280
+ _query_url = APIHelper.clean_url _query_builder
281
+
282
+ # Prepare headers.
283
+ _headers = {
284
+ 'accept' => 'application/json',
285
+ 'content-type' => 'application/json; charset=utf-8'
286
+ }
287
+
288
+ # Prepare and execute HttpRequest.
289
+ _request = config.http_client.post(
290
+ _query_url,
291
+ headers: _headers,
292
+ parameters: body.to_json
293
+ )
294
+ OAuth2.apply(config, _request)
295
+ _response = execute_request(_request)
296
+
297
+ # Return appropriate response type.
298
+ decoded = APIHelper.json_deserialize(_response.raw_body)
299
+ _errors = APIHelper.map_response(decoded, ['errors'])
300
+ ApiResponse.new(_response, data: decoded, errors: _errors)
301
+ end
302
+
303
+ # Removes a card on file from a customer.
304
+ # @param [String] customer_id Required parameter: The ID of the customer
305
+ # that the card on file belongs to.
306
+ # @param [String] card_id Required parameter: The ID of the card on file to
307
+ # delete.
308
+ # @return [DeleteCustomerCardResponse Hash] response from the API call
309
+ def delete_customer_card(customer_id:,
310
+ card_id:)
311
+ # Prepare query url.
312
+ _query_builder = config.get_base_uri
313
+ _query_builder << '/v2/customers/{customer_id}/cards/{card_id}'
314
+ _query_builder = APIHelper.append_url_with_template_parameters(
315
+ _query_builder,
316
+ 'customer_id' => customer_id,
317
+ 'card_id' => card_id
318
+ )
319
+ _query_url = APIHelper.clean_url _query_builder
320
+
321
+ # Prepare headers.
322
+ _headers = {
323
+ 'accept' => 'application/json'
324
+ }
325
+
326
+ # Prepare and execute HttpRequest.
327
+ _request = config.http_client.delete(
328
+ _query_url,
329
+ headers: _headers
330
+ )
331
+ OAuth2.apply(config, _request)
332
+ _response = execute_request(_request)
333
+
334
+ # Return appropriate response type.
335
+ decoded = APIHelper.json_deserialize(_response.raw_body)
336
+ _errors = APIHelper.map_response(decoded, ['errors'])
337
+ ApiResponse.new(_response, data: decoded, errors: _errors)
338
+ end
339
+
340
+ # Removes a group membership from a customer.
341
+ # The customer is identified by the `customer_id` value
342
+ # and the customer group is identified by the `group_id` value.
343
+ # @param [String] customer_id Required parameter: The ID of the customer to
344
+ # remove from the group.
345
+ # @param [String] group_id Required parameter: The ID of the customer group
346
+ # to remove the customer from.
347
+ # @return [RemoveGroupFromCustomerResponse Hash] response from the API call
348
+ def remove_group_from_customer(customer_id:,
349
+ group_id:)
350
+ # Prepare query url.
351
+ _query_builder = config.get_base_uri
352
+ _query_builder << '/v2/customers/{customer_id}/groups/{group_id}'
353
+ _query_builder = APIHelper.append_url_with_template_parameters(
354
+ _query_builder,
355
+ 'customer_id' => customer_id,
356
+ 'group_id' => group_id
357
+ )
358
+ _query_url = APIHelper.clean_url _query_builder
359
+
360
+ # Prepare headers.
361
+ _headers = {
362
+ 'accept' => 'application/json'
363
+ }
364
+
365
+ # Prepare and execute HttpRequest.
366
+ _request = config.http_client.delete(
367
+ _query_url,
368
+ headers: _headers
369
+ )
370
+ OAuth2.apply(config, _request)
371
+ _response = execute_request(_request)
372
+
373
+ # Return appropriate response type.
374
+ decoded = APIHelper.json_deserialize(_response.raw_body)
375
+ _errors = APIHelper.map_response(decoded, ['errors'])
376
+ ApiResponse.new(_response, data: decoded, errors: _errors)
377
+ end
378
+
379
+ # Adds a group membership to a customer.
380
+ # The customer is identified by the `customer_id` value
381
+ # and the customer group is identified by the `group_id` value.
382
+ # @param [String] customer_id Required parameter: The ID of the customer to
383
+ # add to a group.
384
+ # @param [String] group_id Required parameter: The ID of the customer group
385
+ # to add the customer to.
386
+ # @return [AddGroupToCustomerResponse Hash] response from the API call
387
+ def add_group_to_customer(customer_id:,
388
+ group_id:)
389
+ # Prepare query url.
390
+ _query_builder = config.get_base_uri
391
+ _query_builder << '/v2/customers/{customer_id}/groups/{group_id}'
392
+ _query_builder = APIHelper.append_url_with_template_parameters(
393
+ _query_builder,
394
+ 'customer_id' => customer_id,
395
+ 'group_id' => group_id
396
+ )
397
+ _query_url = APIHelper.clean_url _query_builder
398
+
399
+ # Prepare headers.
400
+ _headers = {
401
+ 'accept' => 'application/json'
402
+ }
403
+
404
+ # Prepare and execute HttpRequest.
405
+ _request = config.http_client.put(
406
+ _query_url,
407
+ headers: _headers
408
+ )
409
+ OAuth2.apply(config, _request)
410
+ _response = execute_request(_request)
411
+
412
+ # Return appropriate response type.
413
+ decoded = APIHelper.json_deserialize(_response.raw_body)
414
+ _errors = APIHelper.map_response(decoded, ['errors'])
415
+ ApiResponse.new(_response, data: decoded, errors: _errors)
416
+ end
417
+ end
418
+ end