square.rb 6.1.0.20200722 → 6.2.0.20200812
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/square.rb +1 -0
- data/lib/square/api/base_api.rb +1 -1
- data/lib/square/api/subscriptions_api.rb +262 -0
- data/lib/square/client.rb +8 -2
- data/lib/square/configuration.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 491aaaccfa43e7c8d9d17a2d48624c28207bbea80dc75359d525b3d4cd64b0cf
|
4
|
+
data.tar.gz: 645d97dc4dcef2655903ad1f89dee5e361c6b072794bf2920d83fe66dfae1723
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41bc326ab367dae322de2187a0fb3d509384f5af88787e75ab37db42db1263833f65fd0bf39e48ecd60d437970752eb5380cba65eeee02a113c39ae48692e74d
|
7
|
+
data.tar.gz: d2f6cd63f7a4475ae78c64a980831c4f3b2b23ca8e657deb6dc737b188906987f2b67a21966ed74f7001c25553d5590b1a619c923713f25e9000d199f6196e21
|
data/README.md
CHANGED
@@ -38,6 +38,9 @@ gem 'square.rb'
|
|
38
38
|
### Orders
|
39
39
|
* [Orders]
|
40
40
|
|
41
|
+
### Subscriptions
|
42
|
+
* [Subscriptions]
|
43
|
+
|
41
44
|
### Invoices
|
42
45
|
* [Invoices]
|
43
46
|
|
@@ -312,4 +315,5 @@ You can also use the Square API to create applications or services that work wit
|
|
312
315
|
[V1 Employees]: doc/v1-employees.md
|
313
316
|
[V1 Transactions]: doc/v1-transactions.md
|
314
317
|
[V1 Items]: doc/v1-items.md
|
315
|
-
[Transactions]: doc/transactions.md
|
318
|
+
[Transactions]: doc/transactions.md
|
319
|
+
[Subscriptions]: doc/subscriptions.md
|
data/lib/square.rb
CHANGED
@@ -57,5 +57,6 @@ require_relative 'square/api/loyalty_api.rb'
|
|
57
57
|
require_relative 'square/api/merchants_api.rb'
|
58
58
|
require_relative 'square/api/payments_api.rb'
|
59
59
|
require_relative 'square/api/refunds_api.rb'
|
60
|
+
require_relative 'square/api/subscriptions_api.rb'
|
60
61
|
require_relative 'square/api/team_api.rb'
|
61
62
|
require_relative 'square/api/terminal_api.rb'
|
data/lib/square/api/base_api.rb
CHANGED
@@ -0,0 +1,262 @@
|
|
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
|
+
# For more information,
|
16
|
+
# see [Subscription API
|
17
|
+
# Overview](https://developer.squareup.com/docs/docs/subscriptions-api/overv
|
18
|
+
# iew).
|
19
|
+
# @param [CreateSubscriptionRequest] body Required parameter: An object
|
20
|
+
# containing the fields to POST for the request. See the corresponding
|
21
|
+
# object definition for field details.
|
22
|
+
# @return [CreateSubscriptionResponse Hash] response from the API call
|
23
|
+
def create_subscription(body:)
|
24
|
+
# Prepare query url.
|
25
|
+
_query_builder = config.get_base_uri
|
26
|
+
_query_builder << '/v2/subscriptions'
|
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
|
+
# Searches for subscriptions.
|
51
|
+
# Results are ordered chronologically by subscription creation date. If
|
52
|
+
# the request specifies more than one location ID,
|
53
|
+
# the endpoint orders the result
|
54
|
+
# by location ID, and then by creation date within each location. If no
|
55
|
+
# locations are given
|
56
|
+
# in the query, all locations are searched.
|
57
|
+
# You can also optionally specify `customer_ids` to search by customer.
|
58
|
+
# If left unset, all customers
|
59
|
+
# associated with the specified locations are returned.
|
60
|
+
# If the request specifies customer IDs, the endpoint orders results
|
61
|
+
# first by location, within location by customer ID, and within
|
62
|
+
# customer by subscription creation date.
|
63
|
+
# For more information, see
|
64
|
+
# [Retrieve
|
65
|
+
# subscriptions](https://developer.squareup.com/docs/docs/subscriptions-api/
|
66
|
+
# overview#retrieve-subscriptions).
|
67
|
+
# @param [SearchSubscriptionsRequest] body Required parameter: An object
|
68
|
+
# containing the fields to POST for the request. See the corresponding
|
69
|
+
# object definition for field details.
|
70
|
+
# @return [SearchSubscriptionsResponse Hash] response from the API call
|
71
|
+
def search_subscriptions(body:)
|
72
|
+
# Prepare query url.
|
73
|
+
_query_builder = config.get_base_uri
|
74
|
+
_query_builder << '/v2/subscriptions/search'
|
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
|
+
# Retrieves a subscription.
|
99
|
+
# @param [String] subscription_id Required parameter: The ID of the
|
100
|
+
# subscription to retrieve.
|
101
|
+
# @return [RetrieveSubscriptionResponse Hash] response from the API call
|
102
|
+
def retrieve_subscription(subscription_id:)
|
103
|
+
# Prepare query url.
|
104
|
+
_query_builder = config.get_base_uri
|
105
|
+
_query_builder << '/v2/subscriptions/{subscription_id}'
|
106
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
107
|
+
_query_builder,
|
108
|
+
'subscription_id' => subscription_id
|
109
|
+
)
|
110
|
+
_query_url = APIHelper.clean_url _query_builder
|
111
|
+
|
112
|
+
# Prepare headers.
|
113
|
+
_headers = {
|
114
|
+
'accept' => 'application/json'
|
115
|
+
}
|
116
|
+
|
117
|
+
# Prepare and execute HttpRequest.
|
118
|
+
_request = config.http_client.get(
|
119
|
+
_query_url,
|
120
|
+
headers: _headers
|
121
|
+
)
|
122
|
+
OAuth2.apply(config, _request)
|
123
|
+
_response = execute_request(_request)
|
124
|
+
|
125
|
+
# Return appropriate response type.
|
126
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
127
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
128
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
129
|
+
end
|
130
|
+
|
131
|
+
# Updates a subscription. You can set, modify, and clear the
|
132
|
+
# `subscription` field values. For more information and examples, see
|
133
|
+
# [Update
|
134
|
+
# subscriptions](https://developer.squareup.com/docs/docs/subscriptions-api/
|
135
|
+
# overview#update-subscriptions).
|
136
|
+
# @param [String] subscription_id Required parameter: The ID for the
|
137
|
+
# subscription to update.
|
138
|
+
# @param [UpdateSubscriptionRequest] body Required parameter: An object
|
139
|
+
# containing the fields to POST for the request. See the corresponding
|
140
|
+
# object definition for field details.
|
141
|
+
# @return [UpdateSubscriptionResponse Hash] response from the API call
|
142
|
+
def update_subscription(subscription_id:,
|
143
|
+
body:)
|
144
|
+
# Prepare query url.
|
145
|
+
_query_builder = config.get_base_uri
|
146
|
+
_query_builder << '/v2/subscriptions/{subscription_id}'
|
147
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
148
|
+
_query_builder,
|
149
|
+
'subscription_id' => subscription_id
|
150
|
+
)
|
151
|
+
_query_url = APIHelper.clean_url _query_builder
|
152
|
+
|
153
|
+
# Prepare headers.
|
154
|
+
_headers = {
|
155
|
+
'accept' => 'application/json',
|
156
|
+
'content-type' => 'application/json; charset=utf-8'
|
157
|
+
}
|
158
|
+
|
159
|
+
# Prepare and execute HttpRequest.
|
160
|
+
_request = config.http_client.put(
|
161
|
+
_query_url,
|
162
|
+
headers: _headers,
|
163
|
+
parameters: body.to_json
|
164
|
+
)
|
165
|
+
OAuth2.apply(config, _request)
|
166
|
+
_response = execute_request(_request)
|
167
|
+
|
168
|
+
# Return appropriate response type.
|
169
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
170
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
171
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
172
|
+
end
|
173
|
+
|
174
|
+
# Cancels a subscription immediately and sets the subscription
|
175
|
+
# `status` to `CANCELED`. You can also use the `UpdateSubscription`
|
176
|
+
# endpoint to cancel a subscription at a future date. For more
|
177
|
+
# information, see
|
178
|
+
# [CancelSubscriptions](https://developer.squareup.com/docs/docs/subscriptio
|
179
|
+
# ns-api/overview#cancel-subscriptions).
|
180
|
+
# @param [String] subscription_id Required parameter: The ID of the
|
181
|
+
# subscription to cancel.
|
182
|
+
# @return [CancelSubscriptionResponse Hash] response from the API call
|
183
|
+
def cancel_subscription(subscription_id:)
|
184
|
+
# Prepare query url.
|
185
|
+
_query_builder = config.get_base_uri
|
186
|
+
_query_builder << '/v2/subscriptions/{subscription_id}/cancel'
|
187
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
188
|
+
_query_builder,
|
189
|
+
'subscription_id' => subscription_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.post(
|
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
|
+
# Lists all events for a specific subscription.
|
213
|
+
# In the current implementation, only `START_SUBSCRIPTION` and
|
214
|
+
# `STOP_SUBSCRIPTION` (when the subscription was canceled) events are
|
215
|
+
# returned.
|
216
|
+
# @param [String] subscription_id Required parameter: The ID of the
|
217
|
+
# subscription to retrieve the events for.
|
218
|
+
# @param [String] cursor Optional parameter: A pagination cursor returned by
|
219
|
+
# a previous call to this endpoint. Provide this to retrieve the next set of
|
220
|
+
# results for the original query. For more information, see
|
221
|
+
# [Pagination](https://developer.squareup.com/docs/docs/working-with-apis/pa
|
222
|
+
# gination).
|
223
|
+
# @param [Integer] limit Optional parameter: The upper limit on the number
|
224
|
+
# of subscription events to return in the response. Default: `200`
|
225
|
+
# @return [ListSubscriptionEventsResponse Hash] response from the API call
|
226
|
+
def list_subscription_events(subscription_id:,
|
227
|
+
cursor: nil,
|
228
|
+
limit: nil)
|
229
|
+
# Prepare query url.
|
230
|
+
_query_builder = config.get_base_uri
|
231
|
+
_query_builder << '/v2/subscriptions/{subscription_id}/events'
|
232
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
233
|
+
_query_builder,
|
234
|
+
'subscription_id' => subscription_id
|
235
|
+
)
|
236
|
+
_query_builder = APIHelper.append_url_with_query_parameters(
|
237
|
+
_query_builder,
|
238
|
+
'cursor' => cursor,
|
239
|
+
'limit' => limit
|
240
|
+
)
|
241
|
+
_query_url = APIHelper.clean_url _query_builder
|
242
|
+
|
243
|
+
# Prepare headers.
|
244
|
+
_headers = {
|
245
|
+
'accept' => 'application/json'
|
246
|
+
}
|
247
|
+
|
248
|
+
# Prepare and execute HttpRequest.
|
249
|
+
_request = config.http_client.get(
|
250
|
+
_query_url,
|
251
|
+
headers: _headers
|
252
|
+
)
|
253
|
+
OAuth2.apply(config, _request)
|
254
|
+
_response = execute_request(_request)
|
255
|
+
|
256
|
+
# Return appropriate response type.
|
257
|
+
decoded = APIHelper.json_deserialize(_response.raw_body)
|
258
|
+
_errors = APIHelper.map_response(decoded, ['errors'])
|
259
|
+
ApiResponse.new(_response, data: decoded, errors: _errors)
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
data/lib/square/client.rb
CHANGED
@@ -4,7 +4,7 @@ module Square
|
|
4
4
|
attr_reader :config
|
5
5
|
|
6
6
|
def sdk_version
|
7
|
-
'6.
|
7
|
+
'6.2.0.20200812'
|
8
8
|
end
|
9
9
|
|
10
10
|
def square_version
|
@@ -179,6 +179,12 @@ module Square
|
|
179
179
|
@refunds ||= RefundsApi.new config
|
180
180
|
end
|
181
181
|
|
182
|
+
# Access to subscriptions controller.
|
183
|
+
# @return [SubscriptionsApi] Returns the controller instance.
|
184
|
+
def subscriptions
|
185
|
+
@subscriptions ||= SubscriptionsApi.new config
|
186
|
+
end
|
187
|
+
|
182
188
|
# Access to team controller.
|
183
189
|
# @return [TeamApi] Returns the controller instance.
|
184
190
|
def team
|
@@ -193,7 +199,7 @@ module Square
|
|
193
199
|
|
194
200
|
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
|
195
201
|
backoff_factor: 1, environment: 'production',
|
196
|
-
square_version: '2020-
|
202
|
+
square_version: '2020-08-12', access_token: 'TODO: Replace',
|
197
203
|
additional_headers: {}, config: nil)
|
198
204
|
@config = if config.nil?
|
199
205
|
Configuration.new(timeout: timeout, max_retries: max_retries,
|
data/lib/square/configuration.rb
CHANGED
@@ -22,7 +22,7 @@ module Square
|
|
22
22
|
|
23
23
|
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
|
24
24
|
backoff_factor: 1, environment: 'production',
|
25
|
-
square_version: '2020-
|
25
|
+
square_version: '2020-08-12', access_token: 'TODO: Replace',
|
26
26
|
additional_headers: {})
|
27
27
|
# The value to use for connection timeout
|
28
28
|
@timeout = timeout
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: square.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.2.0.20200812
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Square Developer Platform
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logging
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- lib/square/api/payments_api.rb
|
143
143
|
- lib/square/api/refunds_api.rb
|
144
144
|
- lib/square/api/reporting_api.rb
|
145
|
+
- lib/square/api/subscriptions_api.rb
|
145
146
|
- lib/square/api/team_api.rb
|
146
147
|
- lib/square/api/terminal_api.rb
|
147
148
|
- lib/square/api/transactions_api.rb
|