Class: AdvancedBilling::SubscriptionInvoiceAccountController

Inherits:
BaseController
  • Object
show all
Defined in:
lib/advanced_billing/controllers/subscription_invoice_account_controller.rb

Overview

SubscriptionInvoiceAccountController

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

#create_prepayment(subscription_id, body: nil) ⇒ CreatePrepaymentResponse

## Create Prepayment In order to specify a prepayment made against a subscription, specify the ‘amount, memo, details, method`. When the `method` specified is `“credit_card_on_file”`, the prepayment amount will be collected using the default credit card payment profile and applied to the prepayment account balance. This is especially useful for manual replenishment of prepaid subscriptions. Please note that you **can’t** pass ‘amount_in_cents`. the subscription description here

Parameters:

  • subscription_id (Integer)

    Required parameter: The Chargify id of

  • body (CreatePrepaymentRequest) (defaults to: nil)

    Optional parameter: TODO: type

Returns:



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

def create_prepayment(subscription_id,
                      body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/subscriptions/{subscription_id}/prepayments.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(CreatePrepaymentResponse.method(:from_hash))
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      APIException))
    .execute
end

#deduct_service_credit(subscription_id, body: nil) ⇒ void

This method returns an undefined value.

Credit will be removed from the subscription in the amount specified in the request body. The credit amount being deducted must be equal to or less than the current credit balance. the subscription description here

Parameters:

  • subscription_id (Integer)

    Required parameter: The Chargify id of

  • body (DeductServiceCreditRequest) (defaults to: nil)

    Optional parameter: TODO: type



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

def deduct_service_credit(subscription_id,
                          body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/subscriptions/{subscription_id}/service_credit_deductions.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))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .is_response_void(true)
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      APIException))
    .execute
end

#issue_service_credit(subscription_id, body: nil) ⇒ ServiceCredit

Credit will be added to the subscription in the amount specified in the request body. The credit is subsequently applied to the next generated invoice. the subscription description here

Parameters:

  • subscription_id (Integer)

    Required parameter: The Chargify id of

  • body (IssueServiceCreditRequest) (defaults to: nil)

    Optional parameter: TODO: type

Returns:



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

def issue_service_credit(subscription_id,
                         body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/subscriptions/{subscription_id}/service_credits.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(ServiceCredit.method(:from_hash))
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      APIException))
    .execute
end

#list_prepayments(options = {}) ⇒ PrepaymentsResponse

This request will list a subscription’s prepayments. the subscription 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`. for List Prepayments operations

Parameters:

  • subscription_id (Integer)

    Required parameter: The Chargify id of

  • page (Integer)

    Optional parameter: Result records are organized in

  • per_page (Integer)

    Optional parameter: This parameter indicates how

  • filter (ListPrepaymentsFilter)

    Optional parameter: Filter to use

Returns:



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/advanced_billing/controllers/subscription_invoice_account_controller.rb', line 85

def list_prepayments(options = {})
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/subscriptions/{subscription_id}/prepayments.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(options['subscription_id'], key: 'subscription_id')
                                .is_required(true)
                                .should_encode(true))
               .query_param(new_parameter(options['page'], key: 'page'))
               .query_param(new_parameter(options['per_page'], key: 'per_page'))
               .query_param(new_parameter(options['filter'], key: 'filter'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth'))
               .array_serialization_format(ArraySerializationFormat::CSV))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(PrepaymentsResponse.method(:from_hash))
                .local_error_template('404',
                                      'Not Found:\'{$response.body}\'',
                                      APIException))
    .execute
end

#list_service_credits(subscription_id, page: 1, per_page: 20, direction: nil) ⇒ ListServiceCreditsResponse

This request will list a subscription’s service credits. the subscription 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`. in which results are returned. Use in query `direction=asc`.

Parameters:

  • subscription_id (Integer)

    Required parameter: The Chargify id of

  • page (Integer) (defaults to: 1)

    Optional parameter: Result records are organized in

  • per_page (Integer) (defaults to: 20)

    Optional parameter: This parameter indicates how

  • direction (SortingDirection) (defaults to: nil)

    Optional parameter: Controls the order

Returns:



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/advanced_billing/controllers/subscription_invoice_account_controller.rb', line 187

def list_service_credits(subscription_id,
                         page: 1,
                         per_page: 20,
                         direction: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/subscriptions/{subscription_id}/service_credits/list.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(subscription_id, key: 'subscription_id')
                                .is_required(true)
                                .should_encode(true))
               .query_param(new_parameter(page, key: 'page'))
               .query_param(new_parameter(per_page, key: 'per_page'))
               .query_param(new_parameter(direction, key: 'direction'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(ListServiceCreditsResponse.method(:from_hash))
                .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

#read_account_balances(subscription_id) ⇒ AccountBalances

Returns the ‘balance_in_cents` of the Subscription’s Pending Discount, Service Credit, and Prepayment accounts, as well as the sum of the Subscription’s open, payable invoices. the subscription

Parameters:

  • subscription_id (Integer)

    Required parameter: The Chargify id of

Returns:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/advanced_billing/controllers/subscription_invoice_account_controller.rb', line 15

def (subscription_id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/subscriptions/{subscription_id}/account_balances.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: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(AccountBalances.method(:from_hash)))
    .execute
end

#refund_prepayment(subscription_id, prepayment_id, body: nil) ⇒ PrepaymentResponse

This endpoint will refund, completely or partially, a particular prepayment applied to a subscription. The ‘prepayment_id` will be the account transaction ID of the original payment. The prepayment must have some amount remaining in order to be refunded. The amount may be passed either as a decimal, with `amount`, or an integer in cents, with `amount_in_cents`. the subscription description here

Parameters:

  • subscription_id (Integer)

    Required parameter: The Chargify id of

  • prepayment_id (Integer)

    Required parameter: id of prepayment

  • body (RefundPrepaymentRequest) (defaults to: nil)

    Optional parameter: TODO: type

Returns:



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/advanced_billing/controllers/subscription_invoice_account_controller.rb', line 228

def refund_prepayment(subscription_id,
                      prepayment_id,
                      body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/subscriptions/{subscription_id}/prepayments/{prepayment_id}/refunds.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(subscription_id, key: 'subscription_id')
                                .is_required(true)
                                .should_encode(true))
               .template_param(new_parameter(prepayment_id, key: 'prepayment_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(PrepaymentResponse.method(:from_hash))
                .local_error_template('404',
                                      'Not Found:\'{$response.body}\'',
                                      APIException)
                .local_error_template('400',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      RefundPrepaymentBaseErrorsResponseException)
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      APIException))
    .execute
end