Class: AdvancedBilling::SubscriptionGroupsController
- Inherits:
-
BaseController
- Object
- BaseController
- AdvancedBilling::SubscriptionGroupsController
- Defined in:
- lib/advanced_billing/controllers/subscription_groups_controller.rb
Overview
SubscriptionGroupsController
Constant Summary
Constants inherited from BaseController
Instance Attribute Summary
Attributes inherited from BaseController
Instance Method Summary collapse
-
#add_subscription_to_group(subscription_id, body: nil) ⇒ SubscriptionGroupResponse
Adds an existing subscription to a subscription group.
-
#create_subscription_group(body: nil) ⇒ SubscriptionGroupResponse
Creates a subscription group with given members.
-
#delete_subscription_group(uid) ⇒ DeleteSubscriptionGroupResponse
Deletes a subscription group.
-
#find_subscription_group(subscription_id) ⇒ FullSubscriptionGroupResponse
Finds the subscription group associated with a subscription.
-
#list_subscription_groups(options = {}) ⇒ ListSubscriptionGroupsResponse
Lists subscription groups for the site.
-
#read_subscription_group(uid, include: nil) ⇒ FullSubscriptionGroupResponse
Returns subscription group details.
-
#remove_subscription_from_group(subscription_id) ⇒ void
Removes an existing subscription from a subscription group.
-
#signup_with_subscription_group(body: nil) ⇒ SubscriptionGroupSignupResponse
Creates multiple subscriptions at once under the same customer and consolidates them into a subscription group.
-
#update_subscription_group_members(uid, body: nil) ⇒ SubscriptionGroupResponse
Updates subscription group members.
Methods inherited from BaseController
#initialize, #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
Adds an existing subscription to a subscription group. For sites making
use of the [Relationship
Billing](https://maxio.zendesk.com/hc/en-us/articles/24252287829645-Advanc
ed-Billing-Invoices-Overview) and [Customer
Hierarchy](https://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.
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, reference the following: [Create Subscription in a Subscription Group](https://developers.chargify.com/docs/api-docs/d571659cf0f24-create- subscription#subscription-in-a-subscription-group) the subscription. description here
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/advanced_billing/controllers/subscription_groups_controller.rb', line 260 def add_subscription_to_group(subscription_id, body: nil) @api_call .request(new_request_builder(HttpMethodEnum::POST, '/subscriptions/{subscription_id}/group.json', Server::PRODUCTION) .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. type description here
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/advanced_billing/controllers/subscription_groups_controller.rb', line 53 def create_subscription_group(body: nil) @api_call .request(new_request_builder(HttpMethodEnum::POST, '/subscription_groups.json', Server::PRODUCTION) .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
Deletes a subscription group. Only groups without members can be deleted. group
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/advanced_billing/controllers/subscription_groups_controller.rb', line 182 def delete_subscription_group(uid) @api_call .request(new_request_builder(HttpMethodEnum::DELETE, '/subscription_groups/{uid}.json', Server::PRODUCTION) .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
Finds the subscription group associated with a subscription. If the subscription is not in a group, this endpoint returns an error. id of the subscription associated with the subscription group
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/advanced_billing/controllers/subscription_groups_controller.rb', line 206 def find_subscription_group(subscription_id) @api_call .request(new_request_builder(HttpMethodEnum::GET, '/subscription_groups/lookup.json', Server::PRODUCTION) .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
Lists 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
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/advanced_billing/controllers/subscription_groups_controller.rb', line 95 def list_subscription_groups( = {}) @api_call .request(new_request_builder(HttpMethodEnum::GET, '/subscription_groups.json', Server::PRODUCTION) .query_param(new_parameter(['page'], key: 'page')) .query_param(new_parameter(['per_page'], key: 'per_page')) .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(ListSubscriptionGroupsResponse.method(:from_hash))) .execute end |
#read_subscription_group(uid, include: nil) ⇒ FullSubscriptionGroupResponse
Returns 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.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/advanced_billing/controllers/subscription_groups_controller.rb', line 124 def read_subscription_group(uid, include: nil) @api_call .request(new_request_builder(HttpMethodEnum::GET, '/subscription_groups/{uid}.json', Server::PRODUCTION) .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.
Removes an existing subscription from a subscription group. For sites making use of the [Relationship Billing](https://maxio.zendesk.com/hc/en-us/articles/24252287829645-Advanc ed-Billing-Invoices-Overview) and [Customer Hierarchy](https://maxio.zendesk.com/hc/en-us/articles/24252185211533-Cust omer-Hierarchies-WhoPays#customer-hierarchies) features, it is possible to remove an existing subscription from a subscription group. the subscription.
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/advanced_billing/controllers/subscription_groups_controller.rb', line 290 def remove_subscription_from_group(subscription_id) @api_call .request(new_request_builder(HttpMethodEnum::DELETE, '/subscriptions/{subscription_id}/group.json', Server::PRODUCTION) .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
Creates multiple subscriptions at once under the same customer and
consolidates 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 a product to a subscription you can use either product_id
or product_handle or offer_id. You can also use custom_price
instead.
The subscription request examples below will be split into two sections.
The first section, "Subscription Customization", will focus on passing
different information with a subscription, such as components, calendar
billing, and custom fields. These examples will presume you are using a
secure chargify_token generated by Maxio.js (formerly Chargify.js).
type description here
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/advanced_billing/controllers/subscription_groups_controller.rb', line 29 def signup_with_subscription_group(body: nil) @api_call .request(new_request_builder(HttpMethodEnum::POST, '/subscription_groups/signup.json', Server::PRODUCTION) .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
Updates 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 the subscription group.
To clean up members, just leave the array empty.
group
type description here
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/advanced_billing/controllers/subscription_groups_controller.rb', line 153 def update_subscription_group_members(uid, body: nil) @api_call .request(new_request_builder(HttpMethodEnum::PUT, '/subscription_groups/{uid}.json', Server::PRODUCTION) .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 |