Class: Square::SubscriptionsApi

Inherits:
BaseApi
  • Object
show all
Defined in:
lib/square/api/subscriptions_api.rb

Overview

SubscriptionsApi

Instance Attribute Summary

Attributes inherited from BaseApi

#config, #http_call_back

Instance Method Summary collapse

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 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.

Parameters:

  • subscription_id (String)

    Required parameter: The ID of the

Returns:

  • (CancelSubscriptionResponse Hash)

    response from the API call



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/square/api/subscriptions_api.rb', line 157

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

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.

Parameters:

  • body (CreateSubscriptionRequest)

    Required parameter: An object

Returns:

  • (CreateSubscriptionResponse Hash)

    response from the API call



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/square/api/subscriptions_api.rb', line 15

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.

Parameters:

  • subscription_id (String)

    Required parameter: The ID of the

  • action_id (String)

    Required parameter: The ID of the targeted

Returns:

  • (DeleteSubscriptionActionResponse Hash)

    response from the API call



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 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.

Parameters:

  • subscription_id (String)

    Required parameter: The ID of the

  • cursor (String) (defaults to: nil)

    Optional parameter: When the total number of

  • limit (Integer) (defaults to: nil)

    Optional parameter: The upper limit on the number

Returns:

  • (ListSubscriptionEventsResponse Hash)

    response from the API call



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/square/api/subscriptions_api.rb', line 186

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.

Parameters:

  • subscription_id (String)

    Required parameter: The ID of the

  • body (PauseSubscriptionRequest)

    Required parameter: An object

Returns:

  • (PauseSubscriptionResponse Hash)

    response from the API call



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/square/api/subscriptions_api.rb', line 213

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.

Parameters:

  • subscription_id (String)

    Required parameter: The ID of the

  • body (ResumeSubscriptionRequest)

    Required parameter: An object

Returns:

  • (ResumeSubscriptionResponse Hash)

    response from the API call



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/square/api/subscriptions_api.rb', line 241

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 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.

Parameters:

  • subscription_id (String)

    Required parameter: The ID of the

  • include (String) (defaults to: nil)

    Optional parameter: A query parameter to specify

Returns:

  • (RetrieveSubscriptionResponse Hash)

    response from the API call



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/square/api/subscriptions_api.rb', line 78

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. 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.

Parameters:

  • body (SearchSubscriptionsRequest)

    Required parameter: An object

Returns:

  • (SearchSubscriptionsResponse Hash)

    response from the API call



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/square/api/subscriptions_api.rb', line 53

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 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.

Parameters:

  • subscription_id (String)

    Required parameter: The ID of the

  • body (SwapPlanRequest)

    Required parameter: An object containing the

Returns:

  • (SwapPlanResponse Hash)

    response from the API call



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/square/api/subscriptions_api.rb', line 269

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. 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.

Parameters:

  • subscription_id (String)

    Required parameter: The ID of the

  • body (UpdateSubscriptionRequest)

    Required parameter: An object

Returns:

  • (UpdateSubscriptionResponse Hash)

    response from the API call



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