Class: Square::SubscriptionsApi
- Defined in:
- lib/square/api/subscriptions_api.rb
Overview
SubscriptionsApi
Instance Attribute Summary
Attributes inherited from BaseApi
Instance Method Summary collapse
-
#cancel_subscription(subscription_id:) ⇒ CancelSubscriptionResponse Hash
Schedules a ‘CANCEL` action to cancel an active subscription by setting the `canceled_date` field to the end of the active billing period and changing the subscription status from ACTIVE to CANCELED after this date.
-
#create_subscription(body:) ⇒ CreateSubscriptionResponse Hash
Creates a subscription to a subscription plan by a customer.
-
#delete_subscription_action(subscription_id:, action_id:) ⇒ DeleteSubscriptionActionResponse Hash
Deletes a scheduled action for a subscription.
-
#initialize(config, http_call_back: nil) ⇒ SubscriptionsApi
constructor
A new instance of SubscriptionsApi.
-
#list_subscription_events(subscription_id:, cursor: nil, limit: nil) ⇒ ListSubscriptionEventsResponse Hash
Lists all events for a specific subscription.
-
#pause_subscription(subscription_id:, body:) ⇒ PauseSubscriptionResponse Hash
Schedules a ‘PAUSE` action to pause an active subscription.
-
#resume_subscription(subscription_id:, body:) ⇒ ResumeSubscriptionResponse Hash
Schedules a ‘RESUME` action to resume a paused or a deactivated subscription.
-
#retrieve_subscription(subscription_id:, include: nil) ⇒ RetrieveSubscriptionResponse Hash
Retrieves a subscription.
-
#search_subscriptions(body:) ⇒ SearchSubscriptionsResponse Hash
Searches for subscriptions.
-
#swap_plan(subscription_id:, body:) ⇒ SwapPlanResponse Hash
Schedules a ‘SWAP_PLAN` action to swap a subscription plan in an existing subscription.
-
#update_subscription(subscription_id:, body:) ⇒ UpdateSubscriptionResponse Hash
Updates a subscription.
Methods inherited from BaseApi
#execute_request, #get_user_agent, #validate_parameters
Constructor Details
#initialize(config, http_call_back: nil) ⇒ SubscriptionsApi
Returns a new instance of SubscriptionsApi.
4 5 6 |
# File 'lib/square/api/subscriptions_api.rb', line 4 def initialize(config, http_call_back: nil) super(config, http_call_back: http_call_back) end |
Instance Method Details
#cancel_subscription(subscription_id:) ⇒ CancelSubscriptionResponse Hash
Schedules a ‘CANCEL` action to cancel an active subscription by setting the `canceled_date` field to the end of the active billing period and changing the subscription status from ACTIVE to CANCELED after this date. subscription to cancel.
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/square/api/subscriptions_api.rb', line 231 def cancel_subscription(subscription_id:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/subscriptions/{subscription_id}/cancel' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'subscription_id' => { 'value' => subscription_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#create_subscription(body:) ⇒ CreateSubscriptionResponse Hash
Creates a subscription to a subscription plan by a customer. If you provide a card on file in the request, Square charges the card for the subscription. Otherwise, Square bills an invoice to the customer’s email address. The subscription starts immediately, unless the request includes the optional ‘start_date`. Each individual subscription is associated with a particular location. containing the fields to POST for the request. See the corresponding object definition for field details.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/square/api/subscriptions_api.rb', line 19 def create_subscription(body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/subscriptions' _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'Content-Type' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#delete_subscription_action(subscription_id:, action_id:) ⇒ DeleteSubscriptionActionResponse Hash
Deletes a scheduled action for a subscription. subscription the targeted action is to act upon. action to be deleted.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/square/api/subscriptions_api.rb', line 190 def delete_subscription_action(subscription_id:, action_id:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/subscriptions/{subscription_id}/actions/{action_id}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'subscription_id' => { 'value' => subscription_id, 'encode' => true }, 'action_id' => { 'value' => action_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.delete( _query_url, headers: _headers ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#list_subscription_events(subscription_id:, cursor: nil, limit: nil) ⇒ ListSubscriptionEventsResponse Hash
Lists all events for a specific subscription. subscription to retrieve the events for. resulting subscription events exceeds the limit of a paged response, specify the cursor returned from a preceding response here to fetch the next set of results. If the cursor is unset, the response contains the last page of the results. For more information, see [Pagination](developer.squareup.com/docs/working-with-apis/paginat ion). of subscription events to return in a paged response.
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/square/api/subscriptions_api.rb', line 275 def list_subscription_events(subscription_id:, cursor: nil, limit: nil) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/subscriptions/{subscription_id}/events' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'subscription_id' => { 'value' => subscription_id, 'encode' => true } ) _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, 'cursor' => cursor, 'limit' => limit ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.get( _query_url, headers: _headers ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#pause_subscription(subscription_id:, body:) ⇒ PauseSubscriptionResponse Hash
Schedules a ‘PAUSE` action to pause an active subscription. subscription to pause. containing the fields to POST for the request. See the corresponding object definition for field details.
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/square/api/subscriptions_api.rb', line 320 def pause_subscription(subscription_id:, body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/subscriptions/{subscription_id}/pause' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'subscription_id' => { 'value' => subscription_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'Content-Type' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#resume_subscription(subscription_id:, body:) ⇒ ResumeSubscriptionResponse Hash
Schedules a ‘RESUME` action to resume a paused or a deactivated subscription. subscription to resume. containing the fields to POST for the request. See the corresponding object definition for field details.
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/square/api/subscriptions_api.rb', line 362 def resume_subscription(subscription_id:, body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/subscriptions/{subscription_id}/resume' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'subscription_id' => { 'value' => subscription_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'Content-Type' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#retrieve_subscription(subscription_id:, include: nil) ⇒ RetrieveSubscriptionResponse Hash
Retrieves a subscription. subscription to retrieve. related information to be included in the response. The supported query parameter values are: - ‘actions`: to include scheduled actions on the targeted subscription.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/square/api/subscriptions_api.rb', line 106 def retrieve_subscription(subscription_id:, include: nil) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/subscriptions/{subscription_id}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'subscription_id' => { 'value' => subscription_id, 'encode' => true } ) _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, 'include' => include ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.get( _query_url, headers: _headers ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#search_subscriptions(body:) ⇒ SearchSubscriptionsResponse Hash
Searches for subscriptions. Results are ordered chronologically by subscription creation date. If the request specifies more than one location ID, the endpoint orders the result by location ID, and then by creation date within each location. If no locations are given in the query, all locations are searched. You can also optionally specify ‘customer_ids` to search by customer. If left unset, all customers associated with the specified locations are returned. If the request specifies customer IDs, the endpoint orders results first by location, within location by customer ID, and within customer by subscription creation date. For more information, see [Retrieve subscriptions](developer.squareup.com/docs/subscriptions-api/overv iew#retrieve-subscriptions). containing the fields to POST for the request. See the corresponding object definition for field details.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/square/api/subscriptions_api.rb', line 69 def search_subscriptions(body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/subscriptions/search' _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'Content-Type' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#swap_plan(subscription_id:, body:) ⇒ SwapPlanResponse Hash
Schedules a ‘SWAP_PLAN` action to swap a subscription plan in an existing subscription. subscription to swap the subscription plan for. fields to POST for the request. See the corresponding object definition for field details.
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
# File 'lib/square/api/subscriptions_api.rb', line 404 def swap_plan(subscription_id:, body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/subscriptions/{subscription_id}/swap-plan' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'subscription_id' => { 'value' => subscription_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'Content-Type' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.post( _query_url, headers: _headers, parameters: body.to_json ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |
#update_subscription(subscription_id:, body:) ⇒ UpdateSubscriptionResponse Hash
Updates a subscription. You can set, modify, and clear the ‘subscription` field values. subscription to update. containing the fields to POST for the request. See the corresponding object definition for field details.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/square/api/subscriptions_api.rb', line 150 def update_subscription(subscription_id:, body:) # Prepare query url. _query_builder = config.get_base_uri _query_builder << '/v2/subscriptions/{subscription_id}' _query_builder = APIHelper.append_url_with_template_parameters( _query_builder, 'subscription_id' => { 'value' => subscription_id, 'encode' => true } ) _query_url = APIHelper.clean_url _query_builder # Prepare headers. _headers = { 'accept' => 'application/json', 'Content-Type' => 'application/json' } # Prepare and execute HttpRequest. _request = config.http_client.put( _query_url, headers: _headers, parameters: body.to_json ) OAuth2.apply(config, _request) _response = execute_request(_request) # Return appropriate response type. decoded = APIHelper.json_deserialize(_response.raw_body) _errors = APIHelper.map_response(decoded, ['errors']) ApiResponse.new( _response, data: decoded, errors: _errors ) end |