square.rb 5.2.2.20200422 → 6.3.0.20200826

Sign up to get free protection for your applications and to get access to all the features.
@@ -48,7 +48,8 @@ module Square
48
48
 
49
49
  # Retrieve a `Merchant` object for the given `merchant_id`.
50
50
  # @param [String] merchant_id Required parameter: The ID of the merchant to
51
- # retrieve.
51
+ # retrieve. If the string "me" is supplied as the ID, then retrieve the
52
+ # merchant that is currently accessible to this call.
52
53
  # @return [RetrieveMerchantResponse Hash] response from the API call
53
54
  def retrieve_merchant(merchant_id:)
54
55
  # Prepare query url.
@@ -16,21 +16,14 @@ module Square
16
16
  # To learn more about the Orders API, see the
17
17
  # [Orders API
18
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
19
  # @param [CreateOrderRequest] body Required parameter: An object containing
22
20
  # the fields to POST for the request. See the corresponding object
23
21
  # definition for field details.
24
22
  # @return [CreateOrderResponse Hash] response from the API call
25
- def create_order(location_id:,
26
- body:)
23
+ def create_order(body:)
27
24
  # Prepare query url.
28
25
  _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
- )
26
+ _query_builder << '/v2/orders'
34
27
  _query_url = APIHelper.clean_url _query_builder
35
28
 
36
29
  # Prepare headers.
@@ -57,21 +50,14 @@ module Square
57
50
  # Retrieves a set of [Order](#type-order)s by their IDs.
58
51
  # If a given Order ID does not exist, the ID is ignored instead of
59
52
  # generating an error.
60
- # @param [String] location_id Required parameter: The ID of the orders'
61
- # associated location.
62
53
  # @param [BatchRetrieveOrdersRequest] body Required parameter: An object
63
54
  # containing the fields to POST for the request. See the corresponding
64
55
  # object definition for field details.
65
56
  # @return [BatchRetrieveOrdersResponse Hash] response from the API call
66
- def batch_retrieve_orders(location_id:,
67
- body:)
57
+ def batch_retrieve_orders(body:)
68
58
  # Prepare query url.
69
59
  _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
- )
60
+ _query_builder << '/v2/orders/batch-retrieve'
75
61
  _query_url = APIHelper.clean_url _query_builder
76
62
 
77
63
  # Prepare headers.
@@ -95,45 +81,15 @@ module Square
95
81
  ApiResponse.new(_response, data: decoded, errors: _errors)
96
82
  end
97
83
 
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:)
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:)
129
90
  # Prepare query url.
130
91
  _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
- )
92
+ _query_builder << '/v2/orders/calculate'
137
93
  _query_url = APIHelper.clean_url _query_builder
138
94
 
139
95
  # Prepare headers.
@@ -143,7 +99,7 @@ module Square
143
99
  }
144
100
 
145
101
  # Prepare and execute HttpRequest.
146
- _request = config.http_client.put(
102
+ _request = config.http_client.post(
147
103
  _query_url,
148
104
  headers: _headers,
149
105
  parameters: body.to_json
@@ -204,6 +160,64 @@ module Square
204
160
  ApiResponse.new(_response, data: decoded, errors: _errors)
205
161
  end
206
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
+
207
221
  # Pay for an [order](#type-order) using one or more approved
208
222
  # [payments](#type-payment),
209
223
  # or settle an order with a total of `0`.
@@ -246,12 +246,8 @@ module Square
246
246
  # elayed-payments).
247
247
  # @param [String] payment_id Required parameter: Unique ID identifying the
248
248
  # payment to be completed.
249
- # @param [Object] body Required parameter: An object containing the fields
250
- # to POST for the request. See the corresponding object definition for
251
- # field details.
252
249
  # @return [CompletePaymentResponse Hash] response from the API call
253
- def complete_payment(payment_id:,
254
- body:)
250
+ def complete_payment(payment_id:)
255
251
  # Prepare query url.
256
252
  _query_builder = config.get_base_uri
257
253
  _query_builder << '/v2/payments/{payment_id}/complete'
@@ -263,15 +259,13 @@ module Square
263
259
 
264
260
  # Prepare headers.
265
261
  _headers = {
266
- 'accept' => 'application/json',
267
- 'content-type' => 'application/json; charset=utf-8'
262
+ 'accept' => 'application/json'
268
263
  }
269
264
 
270
265
  # Prepare and execute HttpRequest.
271
266
  _request = config.http_client.post(
272
267
  _query_url,
273
- headers: _headers,
274
- parameters: body.to_json
268
+ headers: _headers
275
269
  )
276
270
  OAuth2.apply(config, _request)
277
271
  _response = execute_request(_request)
@@ -21,8 +21,9 @@ module Square
21
21
  # results for the original query. See
22
22
  # [Pagination](https://developer.squareup.com/docs/basics/api101/pagination)
23
23
  # for more information.
24
- # @param [String] location_id Optional parameter: ID of location associated
25
- # with payment.
24
+ # @param [String] location_id Optional parameter: Limit results to the
25
+ # location supplied. By default, results are returned for all locations
26
+ # associated with the merchant.
26
27
  # @param [String] status Optional parameter: If provided, only refunds with
27
28
  # the given status are returned. For a list of refund status values, see
28
29
  # [PaymentRefund](#type-paymentrefund). Default: If omitted refunds are
@@ -0,0 +1,251 @@
1
+ module Square
2
+ # SubscriptionsApi
3
+ class SubscriptionsApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Creates a subscription for a customer to a subscription plan.
9
+ # If you provide a card on file in the request, Square charges the card for
10
+ # the subscription. Otherwise, Square bills an invoice to the customer's
11
+ # email
12
+ # address. The subscription starts immediately, unless the request includes
13
+ # the optional `start_date`. Each individual subscription is associated with
14
+ # a particular location.
15
+ # @param [CreateSubscriptionRequest] body Required parameter: An object
16
+ # containing the fields to POST for the request. See the corresponding
17
+ # object definition for field details.
18
+ # @return [CreateSubscriptionResponse Hash] response from the API call
19
+ def create_subscription(body:)
20
+ # Prepare query url.
21
+ _query_builder = config.get_base_uri
22
+ _query_builder << '/v2/subscriptions'
23
+ _query_url = APIHelper.clean_url _query_builder
24
+
25
+ # Prepare headers.
26
+ _headers = {
27
+ 'accept' => 'application/json',
28
+ 'content-type' => 'application/json; charset=utf-8'
29
+ }
30
+
31
+ # Prepare and execute HttpRequest.
32
+ _request = config.http_client.post(
33
+ _query_url,
34
+ headers: _headers,
35
+ parameters: body.to_json
36
+ )
37
+ OAuth2.apply(config, _request)
38
+ _response = execute_request(_request)
39
+
40
+ # Return appropriate response type.
41
+ decoded = APIHelper.json_deserialize(_response.raw_body)
42
+ _errors = APIHelper.map_response(decoded, ['errors'])
43
+ ApiResponse.new(_response, data: decoded, errors: _errors)
44
+ end
45
+
46
+ # Searches for subscriptions.
47
+ # Results are ordered chronologically by subscription creation date. If
48
+ # the request specifies more than one location ID,
49
+ # the endpoint orders the result
50
+ # by location ID, and then by creation date within each location. If no
51
+ # locations are given
52
+ # in the query, all locations are searched.
53
+ # You can also optionally specify `customer_ids` to search by customer.
54
+ # If left unset, all customers
55
+ # associated with the specified locations are returned.
56
+ # If the request specifies customer IDs, the endpoint orders results
57
+ # first by location, within location by customer ID, and within
58
+ # customer by subscription creation date.
59
+ # For more information, see
60
+ # [Retrieve
61
+ # subscriptions](https://developer.squareup.com/docs/docs/subscriptions-api/
62
+ # overview#retrieve-subscriptions).
63
+ # @param [SearchSubscriptionsRequest] body Required parameter: An object
64
+ # containing the fields to POST for the request. See the corresponding
65
+ # object definition for field details.
66
+ # @return [SearchSubscriptionsResponse Hash] response from the API call
67
+ def search_subscriptions(body:)
68
+ # Prepare query url.
69
+ _query_builder = config.get_base_uri
70
+ _query_builder << '/v2/subscriptions/search'
71
+ _query_url = APIHelper.clean_url _query_builder
72
+
73
+ # Prepare headers.
74
+ _headers = {
75
+ 'accept' => 'application/json',
76
+ 'content-type' => 'application/json; charset=utf-8'
77
+ }
78
+
79
+ # Prepare and execute HttpRequest.
80
+ _request = config.http_client.post(
81
+ _query_url,
82
+ headers: _headers,
83
+ parameters: body.to_json
84
+ )
85
+ OAuth2.apply(config, _request)
86
+ _response = execute_request(_request)
87
+
88
+ # Return appropriate response type.
89
+ decoded = APIHelper.json_deserialize(_response.raw_body)
90
+ _errors = APIHelper.map_response(decoded, ['errors'])
91
+ ApiResponse.new(_response, data: decoded, errors: _errors)
92
+ end
93
+
94
+ # Retrieves a subscription.
95
+ # @param [String] subscription_id Required parameter: The ID of the
96
+ # subscription to retrieve.
97
+ # @return [RetrieveSubscriptionResponse Hash] response from the API call
98
+ def retrieve_subscription(subscription_id:)
99
+ # Prepare query url.
100
+ _query_builder = config.get_base_uri
101
+ _query_builder << '/v2/subscriptions/{subscription_id}'
102
+ _query_builder = APIHelper.append_url_with_template_parameters(
103
+ _query_builder,
104
+ 'subscription_id' => subscription_id
105
+ )
106
+ _query_url = APIHelper.clean_url _query_builder
107
+
108
+ # Prepare headers.
109
+ _headers = {
110
+ 'accept' => 'application/json'
111
+ }
112
+
113
+ # Prepare and execute HttpRequest.
114
+ _request = config.http_client.get(
115
+ _query_url,
116
+ headers: _headers
117
+ )
118
+ OAuth2.apply(config, _request)
119
+ _response = execute_request(_request)
120
+
121
+ # Return appropriate response type.
122
+ decoded = APIHelper.json_deserialize(_response.raw_body)
123
+ _errors = APIHelper.map_response(decoded, ['errors'])
124
+ ApiResponse.new(_response, data: decoded, errors: _errors)
125
+ end
126
+
127
+ # Updates a subscription. You can set, modify, and clear the
128
+ # `subscription` field values.
129
+ # @param [String] subscription_id Required parameter: The ID for the
130
+ # subscription to update.
131
+ # @param [UpdateSubscriptionRequest] body Required parameter: An object
132
+ # containing the fields to POST for the request. See the corresponding
133
+ # object definition for field details.
134
+ # @return [UpdateSubscriptionResponse Hash] response from the API call
135
+ def update_subscription(subscription_id:,
136
+ body:)
137
+ # Prepare query url.
138
+ _query_builder = config.get_base_uri
139
+ _query_builder << '/v2/subscriptions/{subscription_id}'
140
+ _query_builder = APIHelper.append_url_with_template_parameters(
141
+ _query_builder,
142
+ 'subscription_id' => subscription_id
143
+ )
144
+ _query_url = APIHelper.clean_url _query_builder
145
+
146
+ # Prepare headers.
147
+ _headers = {
148
+ 'accept' => 'application/json',
149
+ 'content-type' => 'application/json; charset=utf-8'
150
+ }
151
+
152
+ # Prepare and execute HttpRequest.
153
+ _request = config.http_client.put(
154
+ _query_url,
155
+ headers: _headers,
156
+ parameters: body.to_json
157
+ )
158
+ OAuth2.apply(config, _request)
159
+ _response = execute_request(_request)
160
+
161
+ # Return appropriate response type.
162
+ decoded = APIHelper.json_deserialize(_response.raw_body)
163
+ _errors = APIHelper.map_response(decoded, ['errors'])
164
+ ApiResponse.new(_response, data: decoded, errors: _errors)
165
+ end
166
+
167
+ # Sets the `canceled_date` field to the end of the active billing period.
168
+ # After this date, the status changes from ACTIVE to CANCELED.
169
+ # @param [String] subscription_id Required parameter: The ID of the
170
+ # subscription to cancel.
171
+ # @return [CancelSubscriptionResponse Hash] response from the API call
172
+ def cancel_subscription(subscription_id:)
173
+ # Prepare query url.
174
+ _query_builder = config.get_base_uri
175
+ _query_builder << '/v2/subscriptions/{subscription_id}/cancel'
176
+ _query_builder = APIHelper.append_url_with_template_parameters(
177
+ _query_builder,
178
+ 'subscription_id' => subscription_id
179
+ )
180
+ _query_url = APIHelper.clean_url _query_builder
181
+
182
+ # Prepare headers.
183
+ _headers = {
184
+ 'accept' => 'application/json'
185
+ }
186
+
187
+ # Prepare and execute HttpRequest.
188
+ _request = config.http_client.post(
189
+ _query_url,
190
+ headers: _headers
191
+ )
192
+ OAuth2.apply(config, _request)
193
+ _response = execute_request(_request)
194
+
195
+ # Return appropriate response type.
196
+ decoded = APIHelper.json_deserialize(_response.raw_body)
197
+ _errors = APIHelper.map_response(decoded, ['errors'])
198
+ ApiResponse.new(_response, data: decoded, errors: _errors)
199
+ end
200
+
201
+ # Lists all events for a specific subscription.
202
+ # In the current implementation, only `START_SUBSCRIPTION` and
203
+ # `STOP_SUBSCRIPTION` (when the subscription was canceled) events are
204
+ # returned.
205
+ # @param [String] subscription_id Required parameter: The ID of the
206
+ # subscription to retrieve the events for.
207
+ # @param [String] cursor Optional parameter: A pagination cursor returned by
208
+ # a previous call to this endpoint. Provide this to retrieve the next set of
209
+ # results for the original query. For more information, see
210
+ # [Pagination](https://developer.squareup.com/docs/docs/working-with-apis/pa
211
+ # gination).
212
+ # @param [Integer] limit Optional parameter: The upper limit on the number
213
+ # of subscription events to return in the response. Default: `200`
214
+ # @return [ListSubscriptionEventsResponse Hash] response from the API call
215
+ def list_subscription_events(subscription_id:,
216
+ cursor: nil,
217
+ limit: nil)
218
+ # Prepare query url.
219
+ _query_builder = config.get_base_uri
220
+ _query_builder << '/v2/subscriptions/{subscription_id}/events'
221
+ _query_builder = APIHelper.append_url_with_template_parameters(
222
+ _query_builder,
223
+ 'subscription_id' => subscription_id
224
+ )
225
+ _query_builder = APIHelper.append_url_with_query_parameters(
226
+ _query_builder,
227
+ 'cursor' => cursor,
228
+ 'limit' => limit
229
+ )
230
+ _query_url = APIHelper.clean_url _query_builder
231
+
232
+ # Prepare headers.
233
+ _headers = {
234
+ 'accept' => 'application/json'
235
+ }
236
+
237
+ # Prepare and execute HttpRequest.
238
+ _request = config.http_client.get(
239
+ _query_url,
240
+ headers: _headers
241
+ )
242
+ OAuth2.apply(config, _request)
243
+ _response = execute_request(_request)
244
+
245
+ # Return appropriate response type.
246
+ decoded = APIHelper.json_deserialize(_response.raw_body)
247
+ _errors = APIHelper.map_response(decoded, ['errors'])
248
+ ApiResponse.new(_response, data: decoded, errors: _errors)
249
+ end
250
+ end
251
+ end