Class: AdvancedBilling::BillingPortalController

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

Overview

BillingPortalController

Constant Summary

Constants inherited from BaseController

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

#enable_billing_portal_for_customer(customer_id, auto_invite: nil) ⇒ CustomerResponse

## Billing Portal Documentation Full documentation on how the Billing Portal operates within the Chargify UI can be located [here](chargify.zendesk.com/hc/en-us/articles/4407648972443). This documentation is focused on how the to configure the Billing Portal Settings, as well as Subscriber Interaction and Merchant Management of the Billing Portal. You can use this endpoint to enable Billing Portal access for a Customer, with the option of sending the Customer an Invitation email at the same time. ## Billing Portal Security If your customer has been invited to the Billing Portal, then they will receive a link to manage their subscription (the “Management URL”) automatically at the bottom of their statements, invoices, and receipts. **This link changes periodically for security and is only valid for 65 days.** If you need to provide your customer their Management URL through other means, you can retrieve it via the API. Because the URL is cryptographically signed with a timestamp, it is not possible for merchants to generate the URL without requesting it from Chargify. In order to prevent abuse & overuse, we ask that you request a new URL only when absolutely necessary. Management URLs are good for 65 days, so you should re-use a previously generated one as much as possible. If you use the URL frequently (such as to display on your website), please **do not** make an API request to Chargify every time. customer Invitation email will be sent to the Customer. When set to 0, or not sent, an email will not be sent. Use in query: ‘auto_invite=1`.

Parameters:

  • customer_id (Integer)

    Required parameter: The Chargify id of the

  • auto_invite (AutoInvite) (defaults to: nil)

    Optional parameter: When set to 1, an

Returns:



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/advanced_billing/controllers/billing_portal_controller.rb', line 143

def enable_billing_portal_for_customer(customer_id,
                                       auto_invite: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/portal/customers/{customer_id}/enable.json',
                                 Server::DEFAULT)
               .template_param(new_parameter(customer_id, key: 'customer_id')
                                .is_required(true)
                                .should_encode(true))
               .query_param(new_parameter(auto_invite, key: 'auto_invite'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .is_nullify404(true)
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(CustomerResponse.method(:from_hash))
                .local_error('422',
                             'Unprocessable Entity (WebDAV)',
                             ErrorListResponseException))
    .execute
end

This method will provide to the API user the exact URL required for a subscriber to access the Billing Portal. ## Rules for Management Link API + When retrieving a management URL, multiple requests for the same customer in a short period will return the same URL + We will not generate a new URL for 15 days + You must cache and remember this URL if you are going to need it again within 15 days + Only request a new URL after the ‘new_link_available_at` date + You are limited to 15 requests for the same URL. If you make more than 15 requests before `new_link_available_at`, you will be blocked from further Management URL requests (with a response code `429`) customer

Parameters:

  • customer_id (Integer)

    Required parameter: The Chargify id of the

Returns:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/advanced_billing/controllers/billing_portal_controller.rb', line 52

def read_billing_portal_link(customer_id)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/portal/customers/{customer_id}/management_link.json',
                                 Server::DEFAULT)
               .template_param(new_parameter(customer_id, key: 'customer_id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .is_nullify404(true)
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(PortalManagementLink.method(:from_hash))
                .local_error('422',
                             'Unprocessable Entity (WebDAV)',
                             ErrorListResponseException)
                .local_error('429',
                             'Too Many Requests',
                             TooManyManagementLinkRequestsErrorException))
    .execute
end

#resend_billing_portal_invitation(customer_id) ⇒ ResentInvitation

You can resend a customer’s Billing Portal invitation. If you attempt to resend an invitation 5 times within 30 minutes, you will receive a ‘422` response with `error` message in the body. If you attempt to resend an invitation when the Billing Portal is already disabled for a Customer, you will receive a `422` error response. If you attempt to resend an invitation when the Billing Portal is already disabled for a Customer, you will receive a `422` error response. If you attempt to resend an invitation when the Customer does not exist a Customer, you will receive a `404` error response. ## Limitations This endpoint will only return a JSON response. customer

Parameters:

  • customer_id (Integer)

    Required parameter: The Chargify id of the

Returns:



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/advanced_billing/controllers/billing_portal_controller.rb', line 89

def resend_billing_portal_invitation(customer_id)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/portal/customers/{customer_id}/invitations/invite.json',
                                 Server::DEFAULT)
               .template_param(new_parameter(customer_id, key: 'customer_id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .is_nullify404(true)
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(ResentInvitation.method(:from_hash))
                .local_error('404',
                             'Not Found',
                             APIException)
                .local_error('422',
                             'Unprocessable Entity (WebDAV)',
                             ErrorListResponseException))
    .execute
end

#revoke_billing_portal_access(customer_id) ⇒ RevokedInvitation

You can revoke a customer’s Billing Portal invitation. If you attempt to revoke an invitation when the Billing Portal is already disabled for a Customer, you will receive a 422 error response. ## Limitations This endpoint will only return a JSON response. customer

Parameters:

  • customer_id (Integer)

    Required parameter: The Chargify id of the

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/advanced_billing/controllers/billing_portal_controller.rb', line 17

def revoke_billing_portal_access(customer_id)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::DELETE,
                                 '/portal/customers/{customer_id}/invitations/revoke.json',
                                 Server::DEFAULT)
               .template_param(new_parameter(customer_id, key: 'customer_id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .is_nullify404(true)
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(RevokedInvitation.method(:from_hash))
                .local_error('422',
                             'Unprocessable Entity (WebDAV)',
                             APIException))
    .execute
end