Class: AdvancedBilling::SubscriptionGroupsController

Inherits:
BaseController show all
Defined in:
lib/advanced_billing/controllers/subscription_groups_controller.rb

Overview

SubscriptionGroupsController

Constant Summary

Constants inherited from BaseController

BaseController::GLOBAL_ERRORS

Instance Attribute Summary

Attributes inherited from BaseController

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseController

#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 AdvancedBilling::BaseController

Instance Method Details

#add_subscription_to_group(subscription_id, body: nil) ⇒ SubscriptionGroupResponse

For sites making use of the [Relationship Billing](maxio.zendesk.com/hc/en-us/articles/24252287829645-Advanc ed-Billing-Invoices-Overview) and [Customer Hierarchy](maxio.zendesk.com/hc/en-us/articles/24252185211533-Cust omer-Hierarchies-WhoPays#customer-hierarchies) features, it is possible to add existing subscriptions to subscription groups. Passing ‘group` parameters with a `target` containing a `type` and optional `id` is all that’s needed. When the ‘target` parameter specifies a `“customer”` or `“subscription”` that is already part of a hierarchy, the subscription will become a member of the customer’s subscription group. If the target customer or subscription is not part of a subscription group, a new group will be created and the subscription will become part of the group with the specified target customer set as the responsible payer for the group’s subscriptions. **Please Note:** In order to add an existing subscription to a subscription group, it must belong to either the same customer record as the target, or be within the same customer hierarchy. Rather than specifying a customer, the ‘target` parameter could instead simply have a value of

  • ‘“self”` which indicates the subscription will be paid for not by some

other customer, but by the subscribing customer,

  • ‘“parent”` which indicates the subscription will be paid for by the

subscribing customer’s parent within a customer hierarchy, or

  • ‘“eldest”` which indicates the subscription will be paid for by the

root-level customer in the subscribing customer’s hierarchy. To create a new subscription into a subscription group, please reference the following: [Create Subscription in a Subscription Group](developers.chargify.com/docs/api-docs/d571659cf0f24-create- subscription#subscription-in-a-subscription-group) the subscription

Parameters:

  • subscription_id (Integer)

    Required parameter: The Chargify id of

  • body (AddSubscriptionToAGroup) (defaults to: nil)

    Optional parameter: Example:

Returns:



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/advanced_billing/controllers/subscription_groups_controller.rb', line 252

def add_subscription_to_group(subscription_id,
                              body: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/subscriptions/{subscription_id}/group.json',
                                 Server::DEFAULT)
               .template_param(new_parameter(subscription_id, key: 'subscription_id')
                                .is_required(true)
                                .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('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(SubscriptionGroupResponse.method(:from_hash)))
    .execute
end

#create_subscription_group(body: nil) ⇒ SubscriptionGroupResponse

Creates a subscription group with given members. Example:

Parameters:

Returns:



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/advanced_billing/controllers/subscription_groups_controller.rb', line 47

def create_subscription_group(body: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/subscription_groups.json',
                                 Server::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('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(SubscriptionGroupResponse.method(:from_hash))
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      SubscriptionGroupCreateErrorResponseException))
    .execute
end

#delete_subscription_group(uid) ⇒ DeleteSubscriptionGroupResponse

Use this endpoint to delete subscription group. Only groups without members can be deleted group

Parameters:

  • uid (String)

    Required parameter: The uid of the subscription

Returns:



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/advanced_billing/controllers/subscription_groups_controller.rb', line 176

def delete_subscription_group(uid)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::DELETE,
                                 '/subscription_groups/{uid}.json',
                                 Server::DEFAULT)
               .template_param(new_parameter(uid, key: 'uid')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(DeleteSubscriptionGroupResponse.method(:from_hash))
                .local_error_template('404',
                                      'Not Found:\'{$response.body}\'',
                                      APIException))
    .execute
end

#find_subscription_group(subscription_id) ⇒ FullSubscriptionGroupResponse

Use this endpoint to find subscription group associated with subscription. If the subscription is not in a group endpoint will return 404 code. id of the subscription associated with the subscription group

Parameters:

  • subscription_id (String)

    Required parameter: The Advanced Billing

Returns:



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/advanced_billing/controllers/subscription_groups_controller.rb', line 200

def find_subscription_group(subscription_id)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/subscription_groups/lookup.json',
                                 Server::DEFAULT)
               .query_param(new_parameter(subscription_id, key: 'subscription_id')
                             .is_required(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(FullSubscriptionGroupResponse.method(:from_hash))
                .local_error_template('404',
                                      'Not Found:\'{$response.body}\'',
                                      APIException))
    .execute
end

#list_subscription_groups(options = {}) ⇒ ListSubscriptionGroupsResponse

Returns an array of subscription groups for the site. The response is paginated and will return a ‘meta` key with pagination information. #### Account Balance Information Account balance information for the subscription groups is not returned by default. If this information is desired, the `include[]=account_balances` parameter must be provided with the request. pages. By default, the first page of results is displayed. The page parameter specifies a page number of results to fetch. You can start navigating through the pages to consume the results. You do this by passing in a page parameter. Retrieve the next page by adding ?page=2 to the query string. If there are no results to return, then an empty result set will be returned. Use in query `page=1`. many records to fetch in each request. Default value is 20. The maximum allowed values is 200; any per_page value over 200 will be changed to 200. Use in query `per_page=200`. A list of additional information to include in the response. The following values are supported: - `account_balances`: Account balance information for the subscription groups. Use in query: `include[]=account_balances`

Parameters:

  • page (Integer)

    Optional parameter: Result records are organized in

  • per_page (Integer)

    Optional parameter: This parameter indicates how

  • include (Array[SubscriptionGroupsListInclude])

    Optional parameter:

Returns:



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/advanced_billing/controllers/subscription_groups_controller.rb', line 89

def list_subscription_groups(options = {})
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/subscription_groups.json',
                                 Server::DEFAULT)
               .query_param(new_parameter(options['page'], key: 'page'))
               .query_param(new_parameter(options['per_page'], key: 'per_page'))
               .query_param(new_parameter(options['include'], key: 'include'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth'))
               .array_serialization_format(ArraySerializationFormat::UN_INDEXED))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(ListSubscriptionGroupsResponse.method(:from_hash)))
    .execute
end

#read_subscription_group(uid, include: nil) ⇒ FullSubscriptionGroupResponse

Use this endpoint to find subscription group details. #### Current Billing Amount in Cents Current billing amount for the subscription group is not returned by default. If this information is desired, the ‘include[]=current_billing_amount_in_cents` parameter must be provided with the request. group Allows including additional data in the response. Use in query: `include[]=current_billing_amount_in_cents`.

Parameters:

  • uid (String)

    Required parameter: The uid of the subscription

  • include (Array[SubscriptionGroupInclude]) (defaults to: nil)

    Optional parameter:

Returns:



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/advanced_billing/controllers/subscription_groups_controller.rb', line 118

def read_subscription_group(uid,
                            include: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/subscription_groups/{uid}.json',
                                 Server::DEFAULT)
               .template_param(new_parameter(uid, key: 'uid')
                                .is_required(true)
                                .should_encode(true))
               .query_param(new_parameter(include, key: 'include'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth'))
               .array_serialization_format(ArraySerializationFormat::UN_INDEXED))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(FullSubscriptionGroupResponse.method(:from_hash)))
    .execute
end

#remove_subscription_from_group(subscription_id) ⇒ void

This method returns an undefined value.

For sites making use of the [Relationship Billing](maxio.zendesk.com/hc/en-us/articles/24252287829645-Advanc ed-Billing-Invoices-Overview) and [Customer Hierarchy](maxio.zendesk.com/hc/en-us/articles/24252185211533-Cust omer-Hierarchies-WhoPays#customer-hierarchies) features, it is possible to remove existing subscription from subscription group. the subscription

Parameters:

  • subscription_id (Integer)

    Required parameter: The Chargify id of



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/advanced_billing/controllers/subscription_groups_controller.rb', line 281

def remove_subscription_from_group(subscription_id)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::DELETE,
                                 '/subscriptions/{subscription_id}/group.json',
                                 Server::DEFAULT)
               .template_param(new_parameter(subscription_id, key: 'subscription_id')
                                .is_required(true)
                                .should_encode(true))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .is_response_void(true)
                .local_error_template('404',
                                      'Not Found:\'{$response.body}\'',
                                      APIException)
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      ErrorListResponseException))
    .execute
end

#signup_with_subscription_group(body: nil) ⇒ SubscriptionGroupSignupResponse

Create multiple subscriptions at once under the same customer and consolidate them into a subscription group. You must provide one and only one of the ‘payer_id`/`payer_reference`/`payer_attributes` for the customer attached to the group. You must provide one and only one of the `payment_profile_id`/`credit_card_attributes`/`bank_account_attributes` for the payment profile attached to the group. Only one of the `subscriptions` can have `“primary”: true` attribute set. When passing product to a subscription you can use either `product_id` or `product_handle` or `offer_id`. You can also use `custom_price` instead. Example:

Parameters:

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/advanced_billing/controllers/subscription_groups_controller.rb', line 23

def (body: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/subscription_groups/signup.json',
                                 Server::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('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(SubscriptionGroupSignupResponse.method(:from_hash))
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      SubscriptionGroupSignupErrorResponseException))
    .execute
end

#update_subscription_group_members(uid, body: nil) ⇒ SubscriptionGroupResponse

Use this endpoint to update subscription group members. ‘“member_ids”` should contain an array of both subscription IDs to set as group members and subscription IDs already present in the groups. Not including them will result in removing them from subscription group. To clean up members, just leave the array empty. group Example:

Parameters:

Returns:



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/advanced_billing/controllers/subscription_groups_controller.rb', line 147

def update_subscription_group_members(uid,
                                      body: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/subscription_groups/{uid}.json',
                                 Server::DEFAULT)
               .template_param(new_parameter(uid, key: 'uid')
                                .is_required(true)
                                .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('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(SubscriptionGroupResponse.method(:from_hash))
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      SubscriptionGroupUpdateErrorResponseException))
    .execute
end