square.rb 3.3.0.20191217

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +10 -0
  3. data/README.md +285 -0
  4. data/lib/square/api/apple_pay_api.rb +50 -0
  5. data/lib/square/api/base_api.rb +43 -0
  6. data/lib/square/api/cash_drawers_api.rb +150 -0
  7. data/lib/square/api/catalog_api.rb +545 -0
  8. data/lib/square/api/checkout_api.rb +49 -0
  9. data/lib/square/api/customers_api.rb +327 -0
  10. data/lib/square/api/employees_api.rb +86 -0
  11. data/lib/square/api/inventory_api.rb +295 -0
  12. data/lib/square/api/labor_api.rb +553 -0
  13. data/lib/square/api/locations_api.rb +146 -0
  14. data/lib/square/api/merchants_api.rb +82 -0
  15. data/lib/square/api/mobile_authorization_api.rb +52 -0
  16. data/lib/square/api/o_auth_api.rb +163 -0
  17. data/lib/square/api/orders_api.rb +266 -0
  18. data/lib/square/api/payments_api.rb +277 -0
  19. data/lib/square/api/refunds_api.rb +144 -0
  20. data/lib/square/api/reporting_api.rb +138 -0
  21. data/lib/square/api/transactions_api.rb +377 -0
  22. data/lib/square/api/v1_employees_api.rb +715 -0
  23. data/lib/square/api/v1_items_api.rb +2046 -0
  24. data/lib/square/api/v1_locations_api.rb +83 -0
  25. data/lib/square/api/v1_transactions_api.rb +568 -0
  26. data/lib/square/api_helper.rb +276 -0
  27. data/lib/square/client.rb +156 -0
  28. data/lib/square/configuration.rb +93 -0
  29. data/lib/square/exceptions/api_exception.rb +15 -0
  30. data/lib/square/http/api_response.rb +45 -0
  31. data/lib/square/http/auth/o_auth2.rb +12 -0
  32. data/lib/square/http/faraday_client.rb +59 -0
  33. data/lib/square/http/http_call_back.rb +19 -0
  34. data/lib/square/http/http_client.rb +99 -0
  35. data/lib/square/http/http_method_enum.rb +8 -0
  36. data/lib/square/http/http_request.rb +45 -0
  37. data/lib/square/http/http_response.rb +24 -0
  38. data/lib/square.rb +49 -0
  39. data/spec/user_journey_spec.rb +145 -0
  40. data/test/api/api_test_base.rb +24 -0
  41. data/test/api/test_catalog_api.rb +59 -0
  42. data/test/api/test_customers_api.rb +45 -0
  43. data/test/api/test_employees_api.rb +36 -0
  44. data/test/api/test_labor_api.rb +74 -0
  45. data/test/api/test_locations_api.rb +35 -0
  46. data/test/api/test_merchants_api.rb +40 -0
  47. data/test/api/test_payments_api.rb +42 -0
  48. data/test/api/test_refunds_api.rb +41 -0
  49. data/test/http_response_catcher.rb +19 -0
  50. data/test/test_helper.rb +94 -0
  51. metadata +190 -0
@@ -0,0 +1,82 @@
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.
52
+ # @return [RetrieveMerchantResponse Hash] response from the API call
53
+ def retrieve_merchant(merchant_id:)
54
+ # Prepare query url.
55
+ _query_builder = config.get_base_uri
56
+ _query_builder << '/v2/merchants/{merchant_id}'
57
+ _query_builder = APIHelper.append_url_with_template_parameters(
58
+ _query_builder,
59
+ 'merchant_id' => merchant_id
60
+ )
61
+ _query_url = APIHelper.clean_url _query_builder
62
+
63
+ # Prepare headers.
64
+ _headers = {
65
+ 'accept' => 'application/json'
66
+ }
67
+
68
+ # Prepare and execute HttpRequest.
69
+ _request = config.http_client.get(
70
+ _query_url,
71
+ headers: _headers
72
+ )
73
+ OAuth2.apply(config, _request)
74
+ _response = execute_request(_request)
75
+
76
+ # Return appropriate response type.
77
+ decoded = APIHelper.json_deserialize(_response.raw_body)
78
+ _errors = APIHelper.map_response(decoded, ['errors'])
79
+ ApiResponse.new(_response, data: decoded, errors: _errors)
80
+ end
81
+ end
82
+ 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,266 @@
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 [String] location_id Required parameter: The ID of the business
20
+ # location to associate the order with.
21
+ # @param [CreateOrderRequest] body Required parameter: An object containing
22
+ # the fields to POST for the request. See the corresponding object
23
+ # definition for field details.
24
+ # @return [CreateOrderResponse Hash] response from the API call
25
+ def create_order(location_id:,
26
+ body:)
27
+ # Prepare query url.
28
+ _query_builder = config.get_base_uri
29
+ _query_builder << '/v2/locations/{location_id}/orders'
30
+ _query_builder = APIHelper.append_url_with_template_parameters(
31
+ _query_builder,
32
+ 'location_id' => location_id
33
+ )
34
+ _query_url = APIHelper.clean_url _query_builder
35
+
36
+ # Prepare headers.
37
+ _headers = {
38
+ 'accept' => 'application/json',
39
+ 'content-type' => 'application/json; charset=utf-8'
40
+ }
41
+
42
+ # Prepare and execute HttpRequest.
43
+ _request = config.http_client.post(
44
+ _query_url,
45
+ headers: _headers,
46
+ parameters: body.to_json
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
+ # Retrieves a set of [Order](#type-order)s by their IDs.
58
+ # If a given Order ID does not exist, the ID is ignored instead of
59
+ # generating an error.
60
+ # @param [String] location_id Required parameter: The ID of the orders'
61
+ # associated location.
62
+ # @param [BatchRetrieveOrdersRequest] body Required parameter: An object
63
+ # containing the fields to POST for the request. See the corresponding
64
+ # object definition for field details.
65
+ # @return [BatchRetrieveOrdersResponse Hash] response from the API call
66
+ def batch_retrieve_orders(location_id:,
67
+ body:)
68
+ # Prepare query url.
69
+ _query_builder = config.get_base_uri
70
+ _query_builder << '/v2/locations/{location_id}/orders/batch-retrieve'
71
+ _query_builder = APIHelper.append_url_with_template_parameters(
72
+ _query_builder,
73
+ 'location_id' => location_id
74
+ )
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
+ # Updates an open [Order](#type-order) by adding, replacing, or deleting
99
+ # fields. Orders with a `COMPLETED` or `CANCELED` state cannot be updated.
100
+ # An UpdateOrder request requires the following:
101
+ # - The `order_id` in the endpoint path, identifying the order to update.
102
+ # - The latest `version` of the order to update.
103
+ # - The [sparse
104
+ # order](https://developer.squareup.com/docs/orders-api/manage-orders#sparse
105
+ # -order-objects)
106
+ # containing only the fields to update and the version the update is
107
+ # being applied to.
108
+ # - If deleting fields, the [dot notation
109
+ # paths](https://developer.squareup.com/docs/orders-api/manage-orders#on-dot
110
+ # -notation)
111
+ # identifying fields to clear.
112
+ # To pay for an order, please refer to the [Pay for
113
+ # Orders](https://developer.squareup.com/docs/orders-api/pay-for-orders)
114
+ # guide.
115
+ # To learn more about the Orders API, see the
116
+ # [Orders API
117
+ # Overview](https://developer.squareup.com/docs/orders-api/what-it-does).
118
+ # @param [String] location_id Required parameter: The ID of the order's
119
+ # associated location.
120
+ # @param [String] order_id Required parameter: The ID of the order to
121
+ # update.
122
+ # @param [UpdateOrderRequest] body Required parameter: An object containing
123
+ # the fields to POST for the request. See the corresponding object
124
+ # definition for field details.
125
+ # @return [UpdateOrderResponse Hash] response from the API call
126
+ def update_order(location_id:,
127
+ order_id:,
128
+ body:)
129
+ # Prepare query url.
130
+ _query_builder = config.get_base_uri
131
+ _query_builder << '/v2/locations/{location_id}/orders/{order_id}'
132
+ _query_builder = APIHelper.append_url_with_template_parameters(
133
+ _query_builder,
134
+ 'location_id' => location_id,
135
+ 'order_id' => order_id
136
+ )
137
+ _query_url = APIHelper.clean_url _query_builder
138
+
139
+ # Prepare headers.
140
+ _headers = {
141
+ 'accept' => 'application/json',
142
+ 'content-type' => 'application/json; charset=utf-8'
143
+ }
144
+
145
+ # Prepare and execute HttpRequest.
146
+ _request = config.http_client.put(
147
+ _query_url,
148
+ headers: _headers,
149
+ parameters: body.to_json
150
+ )
151
+ OAuth2.apply(config, _request)
152
+ _response = execute_request(_request)
153
+
154
+ # Return appropriate response type.
155
+ decoded = APIHelper.json_deserialize(_response.raw_body)
156
+ _errors = APIHelper.map_response(decoded, ['errors'])
157
+ ApiResponse.new(_response, data: decoded, errors: _errors)
158
+ end
159
+
160
+ # Search all orders for one or more locations. Orders include all sales,
161
+ # returns, and exchanges regardless of how or when they entered the Square
162
+ # Ecosystem (e.g. Point of Sale, Invoices, Connect APIs, etc).
163
+ # SearchOrders requests need to specify which locations to search and define
164
+ # a
165
+ # [`SearchOrdersQuery`](#type-searchordersquery) object which controls
166
+ # how to sort or filter the results. Your SearchOrdersQuery can:
167
+ # Set filter criteria.
168
+ # Set sort order.
169
+ # Determine whether to return results as complete Order objects, or as
170
+ # [OrderEntry](#type-orderentry) objects.
171
+ # Note that details for orders processed with Square Point of Sale while in
172
+ # offline mode may not be transmitted to Square for up to 72 hours. Offline
173
+ # orders have a `created_at` value that reflects the time the order was
174
+ # created,
175
+ # not the time it was subsequently transmitted to Square.
176
+ # @param [SearchOrdersRequest] body Required parameter: An object containing
177
+ # the fields to POST for the request. See the corresponding object
178
+ # definition for field details.
179
+ # @return [SearchOrdersResponse Hash] response from the API call
180
+ def search_orders(body:)
181
+ # Prepare query url.
182
+ _query_builder = config.get_base_uri
183
+ _query_builder << '/v2/orders/search'
184
+ _query_url = APIHelper.clean_url _query_builder
185
+
186
+ # Prepare headers.
187
+ _headers = {
188
+ 'accept' => 'application/json',
189
+ 'content-type' => 'application/json; charset=utf-8'
190
+ }
191
+
192
+ # Prepare and execute HttpRequest.
193
+ _request = config.http_client.post(
194
+ _query_url,
195
+ headers: _headers,
196
+ parameters: body.to_json
197
+ )
198
+ OAuth2.apply(config, _request)
199
+ _response = execute_request(_request)
200
+
201
+ # Return appropriate response type.
202
+ decoded = APIHelper.json_deserialize(_response.raw_body)
203
+ _errors = APIHelper.map_response(decoded, ['errors'])
204
+ ApiResponse.new(_response, data: decoded, errors: _errors)
205
+ end
206
+
207
+ # Pay for an [order](#type-order) using one or more approved
208
+ # [payments](#type-payment),
209
+ # or settle an order with a total of `0`.
210
+ # The total of the `payment_ids` listed in the request must be equal to the
211
+ # order
212
+ # total. Orders with a total amount of `0` can be marked as paid by
213
+ # specifying an empty
214
+ # array of `payment_ids` in the request.
215
+ # To be used with PayOrder, a payment must:
216
+ # - Reference the order by specifying the `order_id` when [creating the
217
+ # payment](#endpoint-payments-createpayment).
218
+ # Any approved payments that reference the same `order_id` not specified in
219
+ # the
220
+ # `payment_ids` will be canceled.
221
+ # - Be approved with [delayed
222
+ # capture](https://developer.squareup.com/docs/payments-api/take-payments#de
223
+ # layed-capture).
224
+ # Using a delayed capture payment with PayOrder will complete the approved
225
+ # payment.
226
+ # Learn how to [pay for orders with a single payment using the Payments
227
+ # API](https://developer.squareup.com/docs/orders-api/pay-for-orders).
228
+ # @param [String] order_id Required parameter: The ID of the order being
229
+ # paid.
230
+ # @param [PayOrderRequest] body Required parameter: An object containing the
231
+ # fields to POST for the request. See the corresponding object definition
232
+ # for field details.
233
+ # @return [PayOrderResponse Hash] response from the API call
234
+ def pay_order(order_id:,
235
+ body:)
236
+ # Prepare query url.
237
+ _query_builder = config.get_base_uri
238
+ _query_builder << '/v2/orders/{order_id}/pay'
239
+ _query_builder = APIHelper.append_url_with_template_parameters(
240
+ _query_builder,
241
+ 'order_id' => order_id
242
+ )
243
+ _query_url = APIHelper.clean_url _query_builder
244
+
245
+ # Prepare headers.
246
+ _headers = {
247
+ 'accept' => 'application/json',
248
+ 'content-type' => 'application/json; charset=utf-8'
249
+ }
250
+
251
+ # Prepare and execute HttpRequest.
252
+ _request = config.http_client.post(
253
+ _query_url,
254
+ headers: _headers,
255
+ parameters: body.to_json
256
+ )
257
+ OAuth2.apply(config, _request)
258
+ _response = execute_request(_request)
259
+
260
+ # Return appropriate response type.
261
+ decoded = APIHelper.json_deserialize(_response.raw_body)
262
+ _errors = APIHelper.map_response(decoded, ['errors'])
263
+ ApiResponse.new(_response, data: decoded, errors: _errors)
264
+ end
265
+ end
266
+ end