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,83 @@
1
+ module Square
2
+ # MerchantsApi
3
+ class MerchantsApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Returns `Merchant` information for a given access token.
9
+ # If you don't know a `Merchant` ID, you can use this endpoint to retrieve
10
+ # the merchant ID for an access token.
11
+ # You can specify your personal access token to get your own merchant
12
+ # information or specify an OAuth token
13
+ # to get the information for the merchant that granted you access.
14
+ # If you know the merchant ID, you can also use the
15
+ # [RetrieveMerchant](#endpoint-merchants-retrievemerchant)
16
+ # endpoint to get the merchant information.
17
+ # @param [Integer] cursor Optional parameter: The cursor generated by the
18
+ # previous response.
19
+ # @return [ListMerchantsResponse Hash] response from the API call
20
+ def list_merchants(cursor: nil)
21
+ # Prepare query url.
22
+ _query_builder = config.get_base_uri
23
+ _query_builder << '/v2/merchants'
24
+ _query_builder = APIHelper.append_url_with_query_parameters(
25
+ _query_builder,
26
+ 'cursor' => cursor
27
+ )
28
+ _query_url = APIHelper.clean_url _query_builder
29
+
30
+ # Prepare headers.
31
+ _headers = {
32
+ 'accept' => 'application/json'
33
+ }
34
+
35
+ # Prepare and execute HttpRequest.
36
+ _request = config.http_client.get(
37
+ _query_url,
38
+ headers: _headers
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
+
49
+ # Retrieve a `Merchant` object for the given `merchant_id`.
50
+ # @param [String] merchant_id Required parameter: The ID of the merchant to
51
+ # retrieve. If the string "me" is supplied as the ID, then retrieve the
52
+ # merchant that is currently accessible to this call.
53
+ # @return [RetrieveMerchantResponse Hash] response from the API call
54
+ def retrieve_merchant(merchant_id:)
55
+ # Prepare query url.
56
+ _query_builder = config.get_base_uri
57
+ _query_builder << '/v2/merchants/{merchant_id}'
58
+ _query_builder = APIHelper.append_url_with_template_parameters(
59
+ _query_builder,
60
+ 'merchant_id' => merchant_id
61
+ )
62
+ _query_url = APIHelper.clean_url _query_builder
63
+
64
+ # Prepare headers.
65
+ _headers = {
66
+ 'accept' => 'application/json'
67
+ }
68
+
69
+ # Prepare and execute HttpRequest.
70
+ _request = config.http_client.get(
71
+ _query_url,
72
+ headers: _headers
73
+ )
74
+ OAuth2.apply(config, _request)
75
+ _response = execute_request(_request)
76
+
77
+ # Return appropriate response type.
78
+ decoded = APIHelper.json_deserialize(_response.raw_body)
79
+ _errors = APIHelper.map_response(decoded, ['errors'])
80
+ ApiResponse.new(_response, data: decoded, errors: _errors)
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,52 @@
1
+ module Square
2
+ # MobileAuthorizationApi
3
+ class MobileAuthorizationApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Generates code to authorize a mobile application to connect to a Square
9
+ # card reader
10
+ # Authorization codes are one-time-use and expire __60 minutes__ after being
11
+ # issued.
12
+ # __Important:__ The `Authorization` header you provide to this endpoint
13
+ # must have the following format:
14
+ # ```
15
+ # Authorization: Bearer ACCESS_TOKEN
16
+ # ```
17
+ # Replace `ACCESS_TOKEN` with a
18
+ # [valid production authorization
19
+ # credential](https://developer.squareup.com/docs/docs/build-basics/access-t
20
+ # okens).
21
+ # @param [CreateMobileAuthorizationCodeRequest] body Required parameter: An
22
+ # object containing the fields to POST for the request. See the
23
+ # corresponding object definition for field details.
24
+ # @return [CreateMobileAuthorizationCodeResponse Hash] response from the API call
25
+ def create_mobile_authorization_code(body:)
26
+ # Prepare query url.
27
+ _query_builder = config.get_base_uri
28
+ _query_builder << '/mobile/authorization-code'
29
+ _query_url = APIHelper.clean_url _query_builder
30
+
31
+ # Prepare headers.
32
+ _headers = {
33
+ 'accept' => 'application/json',
34
+ 'content-type' => 'application/json; charset=utf-8'
35
+ }
36
+
37
+ # Prepare and execute HttpRequest.
38
+ _request = config.http_client.post(
39
+ _query_url,
40
+ headers: _headers,
41
+ parameters: body.to_json
42
+ )
43
+ OAuth2.apply(config, _request)
44
+ _response = execute_request(_request)
45
+
46
+ # Return appropriate response type.
47
+ decoded = APIHelper.json_deserialize(_response.raw_body)
48
+ _errors = APIHelper.map_response(decoded, ['errors'])
49
+ ApiResponse.new(_response, data: decoded, errors: _errors)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,163 @@
1
+ module Square
2
+ # OAuthApi
3
+ class OAuthApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # `RenewToken` is deprecated. For information about refreshing OAuth access
9
+ # tokens, see
10
+ # [Renew OAuth
11
+ # Token](https://developer.squareup.com/docs/oauth-api/cookbook/renew-oauth-
12
+ # tokens).
13
+ # Renews an OAuth access token before it expires.
14
+ # OAuth access tokens besides your application's personal access token
15
+ # expire after __30 days__.
16
+ # You can also renew expired tokens within __15 days__ of their expiration.
17
+ # You cannot renew an access token that has been expired for more than 15
18
+ # days.
19
+ # Instead, the associated user must re-complete the OAuth flow from the
20
+ # beginning.
21
+ # __Important:__ The `Authorization` header for this endpoint must have the
22
+ # following format:
23
+ # ```
24
+ # Authorization: Client APPLICATION_SECRET
25
+ # ```
26
+ # Replace `APPLICATION_SECRET` with the application secret on the
27
+ # Credentials
28
+ # page in the [application dashboard](https://connect.squareup.com/apps).
29
+ # @param [String] client_id Required parameter: Your application ID,
30
+ # available from the [application
31
+ # dashboard](https://connect.squareup.com/apps).
32
+ # @param [RenewTokenRequest] body Required parameter: An object containing
33
+ # the fields to POST for the request. See the corresponding object
34
+ # definition for field details.
35
+ # @param [String] authorization Required parameter: Client
36
+ # APPLICATION_SECRET
37
+ # @return [RenewTokenResponse Hash] response from the API call
38
+ def renew_token(client_id:,
39
+ body:,
40
+ authorization:)
41
+ warn 'Endpoint renew_token in OAuthApi is deprecated'
42
+ # Prepare query url.
43
+ _query_builder = config.get_base_uri
44
+ _query_builder << '/oauth2/clients/{client_id}/access-token/renew'
45
+ _query_builder = APIHelper.append_url_with_template_parameters(
46
+ _query_builder,
47
+ 'client_id' => client_id
48
+ )
49
+ _query_url = APIHelper.clean_url _query_builder
50
+
51
+ # Prepare headers.
52
+ _headers = {
53
+ 'accept' => 'application/json',
54
+ 'content-type' => 'application/json; charset=utf-8',
55
+ 'Authorization' => authorization
56
+ }
57
+
58
+ # Prepare and execute HttpRequest.
59
+ _request = config.http_client.post(
60
+ _query_url,
61
+ headers: _headers,
62
+ parameters: body.to_json
63
+ )
64
+ _response = execute_request(_request)
65
+
66
+ # Return appropriate response type.
67
+ decoded = APIHelper.json_deserialize(_response.raw_body)
68
+ _errors = APIHelper.map_response(decoded, ['errors'])
69
+ ApiResponse.new(_response, data: decoded, errors: _errors)
70
+ end
71
+
72
+ # Revokes an access token generated with the OAuth flow.
73
+ # If an account has more than one OAuth access token for your application,
74
+ # this
75
+ # endpoint revokes all of them, regardless of which token you specify. When
76
+ # an
77
+ # OAuth access token is revoked, all of the active subscriptions associated
78
+ # with that OAuth token are canceled immediately.
79
+ # __Important:__ The `Authorization` header for this endpoint must have the
80
+ # following format:
81
+ # ```
82
+ # Authorization: Client APPLICATION_SECRET
83
+ # ```
84
+ # Replace `APPLICATION_SECRET` with the application secret on the
85
+ # Credentials
86
+ # page in the [application dashboard](https://connect.squareup.com/apps).
87
+ # @param [RevokeTokenRequest] body Required parameter: An object containing
88
+ # the fields to POST for the request. See the corresponding object
89
+ # definition for field details.
90
+ # @param [String] authorization Required parameter: Client
91
+ # APPLICATION_SECRET
92
+ # @return [RevokeTokenResponse Hash] response from the API call
93
+ def revoke_token(body:,
94
+ authorization:)
95
+ # Prepare query url.
96
+ _query_builder = config.get_base_uri
97
+ _query_builder << '/oauth2/revoke'
98
+ _query_url = APIHelper.clean_url _query_builder
99
+
100
+ # Prepare headers.
101
+ _headers = {
102
+ 'accept' => 'application/json',
103
+ 'content-type' => 'application/json; charset=utf-8',
104
+ 'Authorization' => authorization
105
+ }
106
+
107
+ # Prepare and execute HttpRequest.
108
+ _request = config.http_client.post(
109
+ _query_url,
110
+ headers: _headers,
111
+ parameters: body.to_json
112
+ )
113
+ _response = execute_request(_request)
114
+
115
+ # Return appropriate response type.
116
+ decoded = APIHelper.json_deserialize(_response.raw_body)
117
+ _errors = APIHelper.map_response(decoded, ['errors'])
118
+ ApiResponse.new(_response, data: decoded, errors: _errors)
119
+ end
120
+
121
+ # Returns an OAuth access token.
122
+ # The endpoint supports distinct methods of obtaining OAuth access tokens.
123
+ # Applications specify a method by adding the `grant_type` parameter
124
+ # in the request and also provide relevant information.
125
+ # For more information, see [OAuth access token
126
+ # management](https://developer.squareup.com/docs/authz/oauth/how-it-works#o
127
+ # auth-access-token-management).
128
+ # __Note:__ Regardless of the method application specified,
129
+ # the endpoint always returns two items; an OAuth access token and
130
+ # a refresh token in the response.
131
+ # __OAuth tokens should only live on secure servers. Application clients
132
+ # should never interact directly with OAuth tokens__.
133
+ # @param [ObtainTokenRequest] body Required parameter: An object containing
134
+ # the fields to POST for the request. See the corresponding object
135
+ # definition for field details.
136
+ # @return [ObtainTokenResponse Hash] response from the API call
137
+ def obtain_token(body:)
138
+ # Prepare query url.
139
+ _query_builder = config.get_base_uri
140
+ _query_builder << '/oauth2/token'
141
+ _query_url = APIHelper.clean_url _query_builder
142
+
143
+ # Prepare headers.
144
+ _headers = {
145
+ 'accept' => 'application/json',
146
+ 'content-type' => 'application/json; charset=utf-8'
147
+ }
148
+
149
+ # Prepare and execute HttpRequest.
150
+ _request = config.http_client.post(
151
+ _query_url,
152
+ headers: _headers,
153
+ parameters: body.to_json
154
+ )
155
+ _response = execute_request(_request)
156
+
157
+ # Return appropriate response type.
158
+ decoded = APIHelper.json_deserialize(_response.raw_body)
159
+ _errors = APIHelper.map_response(decoded, ['errors'])
160
+ ApiResponse.new(_response, data: decoded, errors: _errors)
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,280 @@
1
+ module Square
2
+ # OrdersApi
3
+ class OrdersApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Creates a new [Order](#type-order) which can include information on
9
+ # products for
10
+ # purchase and settings to apply to the purchase.
11
+ # To pay for a created order, please refer to the [Pay for
12
+ # Orders](https://developer.squareup.com/docs/orders-api/pay-for-orders)
13
+ # guide.
14
+ # You can modify open orders using the
15
+ # [UpdateOrder](#endpoint-orders-updateorder) endpoint.
16
+ # To learn more about the Orders API, see the
17
+ # [Orders API
18
+ # Overview](https://developer.squareup.com/docs/orders-api/what-it-does).
19
+ # @param [CreateOrderRequest] body Required parameter: An object containing
20
+ # the fields to POST for the request. See the corresponding object
21
+ # definition for field details.
22
+ # @return [CreateOrderResponse Hash] response from the API call
23
+ def create_order(body:)
24
+ # Prepare query url.
25
+ _query_builder = config.get_base_uri
26
+ _query_builder << '/v2/orders'
27
+ _query_url = APIHelper.clean_url _query_builder
28
+
29
+ # Prepare headers.
30
+ _headers = {
31
+ 'accept' => 'application/json',
32
+ 'content-type' => 'application/json; charset=utf-8'
33
+ }
34
+
35
+ # Prepare and execute HttpRequest.
36
+ _request = config.http_client.post(
37
+ _query_url,
38
+ headers: _headers,
39
+ parameters: body.to_json
40
+ )
41
+ OAuth2.apply(config, _request)
42
+ _response = execute_request(_request)
43
+
44
+ # Return appropriate response type.
45
+ decoded = APIHelper.json_deserialize(_response.raw_body)
46
+ _errors = APIHelper.map_response(decoded, ['errors'])
47
+ ApiResponse.new(_response, data: decoded, errors: _errors)
48
+ end
49
+
50
+ # Retrieves a set of [Order](#type-order)s by their IDs.
51
+ # If a given Order ID does not exist, the ID is ignored instead of
52
+ # generating an error.
53
+ # @param [BatchRetrieveOrdersRequest] body Required parameter: An object
54
+ # containing the fields to POST for the request. See the corresponding
55
+ # object definition for field details.
56
+ # @return [BatchRetrieveOrdersResponse Hash] response from the API call
57
+ def batch_retrieve_orders(body:)
58
+ # Prepare query url.
59
+ _query_builder = config.get_base_uri
60
+ _query_builder << '/v2/orders/batch-retrieve'
61
+ _query_url = APIHelper.clean_url _query_builder
62
+
63
+ # Prepare headers.
64
+ _headers = {
65
+ 'accept' => 'application/json',
66
+ 'content-type' => 'application/json; charset=utf-8'
67
+ }
68
+
69
+ # Prepare and execute HttpRequest.
70
+ _request = config.http_client.post(
71
+ _query_url,
72
+ headers: _headers,
73
+ parameters: body.to_json
74
+ )
75
+ OAuth2.apply(config, _request)
76
+ _response = execute_request(_request)
77
+
78
+ # Return appropriate response type.
79
+ decoded = APIHelper.json_deserialize(_response.raw_body)
80
+ _errors = APIHelper.map_response(decoded, ['errors'])
81
+ ApiResponse.new(_response, data: decoded, errors: _errors)
82
+ end
83
+
84
+ # Calculates an [Order](#type-order).
85
+ # @param [CalculateOrderRequest] body Required parameter: An object
86
+ # containing the fields to POST for the request. See the corresponding
87
+ # object definition for field details.
88
+ # @return [CalculateOrderResponse Hash] response from the API call
89
+ def calculate_order(body:)
90
+ # Prepare query url.
91
+ _query_builder = config.get_base_uri
92
+ _query_builder << '/v2/orders/calculate'
93
+ _query_url = APIHelper.clean_url _query_builder
94
+
95
+ # Prepare headers.
96
+ _headers = {
97
+ 'accept' => 'application/json',
98
+ 'content-type' => 'application/json; charset=utf-8'
99
+ }
100
+
101
+ # Prepare and execute HttpRequest.
102
+ _request = config.http_client.post(
103
+ _query_url,
104
+ headers: _headers,
105
+ parameters: body.to_json
106
+ )
107
+ OAuth2.apply(config, _request)
108
+ _response = execute_request(_request)
109
+
110
+ # Return appropriate response type.
111
+ decoded = APIHelper.json_deserialize(_response.raw_body)
112
+ _errors = APIHelper.map_response(decoded, ['errors'])
113
+ ApiResponse.new(_response, data: decoded, errors: _errors)
114
+ end
115
+
116
+ # Search all orders for one or more locations. Orders include all sales,
117
+ # returns, and exchanges regardless of how or when they entered the Square
118
+ # Ecosystem (e.g. Point of Sale, Invoices, Connect APIs, etc).
119
+ # SearchOrders requests need to specify which locations to search and define
120
+ # a
121
+ # [`SearchOrdersQuery`](#type-searchordersquery) object which controls
122
+ # how to sort or filter the results. Your SearchOrdersQuery can:
123
+ # Set filter criteria.
124
+ # Set sort order.
125
+ # Determine whether to return results as complete Order objects, or as
126
+ # [OrderEntry](#type-orderentry) objects.
127
+ # Note that details for orders processed with Square Point of Sale while in
128
+ # offline mode may not be transmitted to Square for up to 72 hours. Offline
129
+ # orders have a `created_at` value that reflects the time the order was
130
+ # created,
131
+ # not the time it was subsequently transmitted to Square.
132
+ # @param [SearchOrdersRequest] body Required parameter: An object containing
133
+ # the fields to POST for the request. See the corresponding object
134
+ # definition for field details.
135
+ # @return [SearchOrdersResponse Hash] response from the API call
136
+ def search_orders(body:)
137
+ # Prepare query url.
138
+ _query_builder = config.get_base_uri
139
+ _query_builder << '/v2/orders/search'
140
+ _query_url = APIHelper.clean_url _query_builder
141
+
142
+ # Prepare headers.
143
+ _headers = {
144
+ 'accept' => 'application/json',
145
+ 'content-type' => 'application/json; charset=utf-8'
146
+ }
147
+
148
+ # Prepare and execute HttpRequest.
149
+ _request = config.http_client.post(
150
+ _query_url,
151
+ headers: _headers,
152
+ parameters: body.to_json
153
+ )
154
+ OAuth2.apply(config, _request)
155
+ _response = execute_request(_request)
156
+
157
+ # Return appropriate response type.
158
+ decoded = APIHelper.json_deserialize(_response.raw_body)
159
+ _errors = APIHelper.map_response(decoded, ['errors'])
160
+ ApiResponse.new(_response, data: decoded, errors: _errors)
161
+ end
162
+
163
+ # Updates an open [Order](#type-order) by adding, replacing, or deleting
164
+ # fields. Orders with a `COMPLETED` or `CANCELED` state cannot be updated.
165
+ # An UpdateOrder request requires the following:
166
+ # - The `order_id` in the endpoint path, identifying the order to update.
167
+ # - The latest `version` of the order to update.
168
+ # - The [sparse
169
+ # order](https://developer.squareup.com/docs/orders-api/manage-orders#sparse
170
+ # -order-objects)
171
+ # containing only the fields to update and the version the update is
172
+ # being applied to.
173
+ # - If deleting fields, the [dot notation
174
+ # paths](https://developer.squareup.com/docs/orders-api/manage-orders#on-dot
175
+ # -notation)
176
+ # identifying fields to clear.
177
+ # To pay for an order, please refer to the [Pay for
178
+ # Orders](https://developer.squareup.com/docs/orders-api/pay-for-orders)
179
+ # guide.
180
+ # To learn more about the Orders API, see the
181
+ # [Orders API
182
+ # Overview](https://developer.squareup.com/docs/orders-api/what-it-does).
183
+ # @param [String] order_id Required parameter: The ID of the order to
184
+ # update.
185
+ # @param [UpdateOrderRequest] body Required parameter: An object containing
186
+ # the fields to POST for the request. See the corresponding object
187
+ # definition for field details.
188
+ # @return [UpdateOrderResponse Hash] response from the API call
189
+ def update_order(order_id:,
190
+ body:)
191
+ # Prepare query url.
192
+ _query_builder = config.get_base_uri
193
+ _query_builder << '/v2/orders/{order_id}'
194
+ _query_builder = APIHelper.append_url_with_template_parameters(
195
+ _query_builder,
196
+ 'order_id' => order_id
197
+ )
198
+ _query_url = APIHelper.clean_url _query_builder
199
+
200
+ # Prepare headers.
201
+ _headers = {
202
+ 'accept' => 'application/json',
203
+ 'content-type' => 'application/json; charset=utf-8'
204
+ }
205
+
206
+ # Prepare and execute HttpRequest.
207
+ _request = config.http_client.put(
208
+ _query_url,
209
+ headers: _headers,
210
+ parameters: body.to_json
211
+ )
212
+ OAuth2.apply(config, _request)
213
+ _response = execute_request(_request)
214
+
215
+ # Return appropriate response type.
216
+ decoded = APIHelper.json_deserialize(_response.raw_body)
217
+ _errors = APIHelper.map_response(decoded, ['errors'])
218
+ ApiResponse.new(_response, data: decoded, errors: _errors)
219
+ end
220
+
221
+ # Pay for an [order](#type-order) using one or more approved
222
+ # [payments](#type-payment),
223
+ # or settle an order with a total of `0`.
224
+ # The total of the `payment_ids` listed in the request must be equal to the
225
+ # order
226
+ # total. Orders with a total amount of `0` can be marked as paid by
227
+ # specifying an empty
228
+ # array of `payment_ids` in the request.
229
+ # To be used with PayOrder, a payment must:
230
+ # - Reference the order by specifying the `order_id` when [creating the
231
+ # payment](#endpoint-payments-createpayment).
232
+ # Any approved payments that reference the same `order_id` not specified in
233
+ # the
234
+ # `payment_ids` will be canceled.
235
+ # - Be approved with [delayed
236
+ # capture](https://developer.squareup.com/docs/payments-api/take-payments#de
237
+ # layed-capture).
238
+ # Using a delayed capture payment with PayOrder will complete the approved
239
+ # payment.
240
+ # Learn how to [pay for orders with a single payment using the Payments
241
+ # API](https://developer.squareup.com/docs/orders-api/pay-for-orders).
242
+ # @param [String] order_id Required parameter: The ID of the order being
243
+ # paid.
244
+ # @param [PayOrderRequest] body Required parameter: An object containing the
245
+ # fields to POST for the request. See the corresponding object definition
246
+ # for field details.
247
+ # @return [PayOrderResponse Hash] response from the API call
248
+ def pay_order(order_id:,
249
+ body:)
250
+ # Prepare query url.
251
+ _query_builder = config.get_base_uri
252
+ _query_builder << '/v2/orders/{order_id}/pay'
253
+ _query_builder = APIHelper.append_url_with_template_parameters(
254
+ _query_builder,
255
+ 'order_id' => order_id
256
+ )
257
+ _query_url = APIHelper.clean_url _query_builder
258
+
259
+ # Prepare headers.
260
+ _headers = {
261
+ 'accept' => 'application/json',
262
+ 'content-type' => 'application/json; charset=utf-8'
263
+ }
264
+
265
+ # Prepare and execute HttpRequest.
266
+ _request = config.http_client.post(
267
+ _query_url,
268
+ headers: _headers,
269
+ parameters: body.to_json
270
+ )
271
+ OAuth2.apply(config, _request)
272
+ _response = execute_request(_request)
273
+
274
+ # Return appropriate response type.
275
+ decoded = APIHelper.json_deserialize(_response.raw_body)
276
+ _errors = APIHelper.map_response(decoded, ['errors'])
277
+ ApiResponse.new(_response, data: decoded, errors: _errors)
278
+ end
279
+ end
280
+ end