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.
-
#create_subscription(body:) ⇒ CreateSubscriptionResponse Hash
Enrolls a customer in a subscription.
-
#delete_subscription_action(subscription_id:, action_id:) ⇒ DeleteSubscriptionActionResponse Hash
Deletes a scheduled action for a subscription.
-
#list_subscription_events(subscription_id:, cursor: nil, limit: nil) ⇒ ListSubscriptionEventsResponse Hash
Lists all [events](developer.squareup.com/docs/subscriptions-api/actions-eve nts) 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 specific 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 variation in an existing subscription.
-
#update_subscription(subscription_id:, body:) ⇒ UpdateSubscriptionResponse Hash
Updates a subscription by modifying or clearing ‘subscription` field values.
Methods inherited from BaseApi
#initialize, #new_api_call_builder, #new_parameter, #new_request_builder, #new_response_handler, user_agent, user_agent_parameters
Constructor Details
This class inherits a constructor from Square::BaseApi
Instance Method Details
#cancel_subscription(subscription_id:) ⇒ CancelSubscriptionResponse Hash
Schedules a ‘CANCEL` action to cancel an active subscription. This sets the `canceled_date` field to the end of the active billing period. After this date, the subscription status changes from ACTIVE to CANCELED. subscription to cancel.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/square/api/subscriptions_api.rb', line 156 def cancel_subscription(subscription_id:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::POST, '/v2/subscriptions/{subscription_id}/cancel', 'default') .template_param(new_parameter(subscription_id, key: 'subscription_id') .should_encode(true)) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('global'))) .response(new_response_handler .deserializer(APIHelper.method(:json_deserialize)) .is_api_response(true) .convertor(ApiResponse.method(:create))) .execute end |
#create_subscription(body:) ⇒ CreateSubscriptionResponse Hash
Enrolls a customer in a subscription. If you provide a card on file in the request, Square charges the card for the subscription. Otherwise, Square sends 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. For more information, see [Create a subscription](developer.squareup.com/docs/subscriptions-api/manage -subscriptions#create-a-subscription). containing the fields to POST for the request. See the corresponding object definition for field details.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/square/api/subscriptions_api.rb', line 18 def create_subscription(body:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::POST, '/v2/subscriptions', 'default') .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('global'))) .response(new_response_handler .deserializer(APIHelper.method(:json_deserialize)) .is_api_response(true) .convertor(ApiResponse.method(:create))) .execute 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.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/square/api/subscriptions_api.rb', line 130 def delete_subscription_action(subscription_id:, action_id:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::DELETE, '/v2/subscriptions/{subscription_id}/actions/{action_id}', 'default') .template_param(new_parameter(subscription_id, key: 'subscription_id') .should_encode(true)) .template_param(new_parameter(action_id, key: 'action_id') .should_encode(true)) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('global'))) .response(new_response_handler .deserializer(APIHelper.method(:json_deserialize)) .is_api_response(true) .convertor(ApiResponse.method(:create))) .execute end |
#list_subscription_events(subscription_id:, cursor: nil, limit: nil) ⇒ ListSubscriptionEventsResponse Hash
Lists all [events](developer.squareup.com/docs/subscriptions-api/actions-eve nts) 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/build-basics/common-api-p atterns/pagination). of subscription events to return in a paged response.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/square/api/subscriptions_api.rb', line 187 def list_subscription_events(subscription_id:, cursor: nil, limit: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/v2/subscriptions/{subscription_id}/events', 'default') .template_param(new_parameter(subscription_id, key: 'subscription_id') .should_encode(true)) .query_param(new_parameter(cursor, key: 'cursor')) .query_param(new_parameter(limit, key: 'limit')) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('global'))) .response(new_response_handler .deserializer(APIHelper.method(:json_deserialize)) .is_api_response(true) .convertor(ApiResponse.method(:create))) .execute 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.
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/square/api/subscriptions_api.rb', line 214 def pause_subscription(subscription_id:, body:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::POST, '/v2/subscriptions/{subscription_id}/pause', 'default') .template_param(new_parameter(subscription_id, key: 'subscription_id') .should_encode(true)) .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('global'))) .response(new_response_handler .deserializer(APIHelper.method(:json_deserialize)) .is_api_response(true) .convertor(ApiResponse.method(:create))) .execute 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.
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 242 def resume_subscription(subscription_id:, body:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::POST, '/v2/subscriptions/{subscription_id}/resume', 'default') .template_param(new_parameter(subscription_id, key: 'subscription_id') .should_encode(true)) .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('global'))) .response(new_response_handler .deserializer(APIHelper.method(:json_deserialize)) .is_api_response(true) .convertor(ApiResponse.method(:create))) .execute end |
#retrieve_subscription(subscription_id:, include: nil) ⇒ RetrieveSubscriptionResponse Hash
Retrieves a specific 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.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/square/api/subscriptions_api.rb', line 77 def retrieve_subscription(subscription_id:, include: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/v2/subscriptions/{subscription_id}', 'default') .template_param(new_parameter(subscription_id, key: 'subscription_id') .should_encode(true)) .query_param(new_parameter(include, key: 'include')) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('global'))) .response(new_response_handler .deserializer(APIHelper.method(:json_deserialize)) .is_api_response(true) .convertor(ApiResponse.method(:create))) .execute 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. containing the fields to POST for the request. See the corresponding object definition for field details.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/square/api/subscriptions_api.rb', line 52 def search_subscriptions(body:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::POST, '/v2/subscriptions/search', 'default') .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('global'))) .response(new_response_handler .deserializer(APIHelper.method(:json_deserialize)) .is_api_response(true) .convertor(ApiResponse.method(:create))) .execute end |
#swap_plan(subscription_id:, body:) ⇒ SwapPlanResponse Hash
Schedules a ‘SWAP_PLAN` action to swap a subscription plan variation in an existing subscription. For more information, see [Swap Subscription Plan Variations](developer.squareup.com/docs/subscriptions-api/swap-pla n-variations). subscription to swap the subscription plan for. fields to POST for the request. See the corresponding object definition for field details.
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/square/api/subscriptions_api.rb', line 273 def swap_plan(subscription_id:, body:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::POST, '/v2/subscriptions/{subscription_id}/swap-plan', 'default') .template_param(new_parameter(subscription_id, key: 'subscription_id') .should_encode(true)) .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('global'))) .response(new_response_handler .deserializer(APIHelper.method(:json_deserialize)) .is_api_response(true) .convertor(ApiResponse.method(:create))) .execute end |
#update_subscription(subscription_id:, body:) ⇒ UpdateSubscriptionResponse Hash
Updates a subscription by modifying or clearing ‘subscription` field values. To clear a field, set its value to `null`. subscription to update. containing the fields to POST for the request. See the corresponding object definition for field details.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/square/api/subscriptions_api.rb', line 104 def update_subscription(subscription_id:, body:) new_api_call_builder .request(new_request_builder(HttpMethodEnum::PUT, '/v2/subscriptions/{subscription_id}', 'default') .template_param(new_parameter(subscription_id, key: 'subscription_id') .should_encode(true)) .header_param(new_parameter('application/json', key: 'Content-Type')) .body_param(new_parameter(body)) .header_param(new_parameter('application/json', key: 'accept')) .body_serializer(proc do |param| param.to_json unless param.nil? end) .auth(Single.new('global'))) .response(new_response_handler .deserializer(APIHelper.method(:json_deserialize)) .is_api_response(true) .convertor(ApiResponse.method(:create))) .execute end |