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
Sets the `canceled_date` field to the end of the active billing period.
-
#create_subscription(body:) ⇒ CreateSubscriptionResponse Hash
Creates a subscription for a customer to a subscription plan.
-
#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.
-
#resume_subscription(subscription_id:) ⇒ ResumeSubscriptionResponse Hash
Resumes a deactivated subscription.
-
#retrieve_subscription(subscription_id:) ⇒ RetrieveSubscriptionResponse Hash
Retrieves a subscription.
-
#search_subscriptions(body:) ⇒ SearchSubscriptionsResponse Hash
Searches for subscriptions.
-
#update_subscription(subscription_id:, body:) ⇒ UpdateSubscriptionResponse Hash
Updates a subscription.
Methods inherited from BaseApi
#execute_request, #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
Sets the `canceled_date` field to the end of the active billing period. After this date, the status changes from ACTIVE to CANCELED. subscription to cancel.
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/square/api/subscriptions_api.rb', line 180 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 for a customer to a subscription plan. 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; charset=utf-8' } # 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 |
#list_subscription_events(subscription_id:, cursor: nil, limit: nil) ⇒ ListSubscriptionEventsResponse Hash
Lists all events for a specific subscription. In the current implementation, only `START_SUBSCRIPTION` and `STOP_SUBSCRIPTION` (when the subscription was canceled) events are returned. subscription to retrieve the events for. a previous call to this endpoint. Provide this to retrieve the next set of results for the original query. For more information, see [Pagination](developer.squareup.com/docs/working-with-apis/paginat ion). of subscription events to return in the response. Default: `200`
225 226 227 228 229 230 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 261 |
# File 'lib/square/api/subscriptions_api.rb', line 225 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 |
#resume_subscription(subscription_id:) ⇒ ResumeSubscriptionResponse Hash
Resumes a deactivated subscription. subscription to resume.
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/square/api/subscriptions_api.rb', line 267 def resume_subscription(subscription_id:) # 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' } # 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 |
#retrieve_subscription(subscription_id:) ⇒ RetrieveSubscriptionResponse Hash
Retrieves a subscription. subscription to retrieve.
102 103 104 105 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 |
# File 'lib/square/api/subscriptions_api.rb', line 102 def retrieve_subscription(subscription_id:) # 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' } # 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; charset=utf-8' } # 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.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/square/api/subscriptions_api.rb', line 141 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; charset=utf-8' } # 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 |