Billing Settings Documentation
Purpose
The BillingSettings component is part of the Vantage analytics and data platform that handles all billing-related functionalities for organizations. This component allows users to manage billing contacts, view current subscription plans, track token usage, and manage payment methods. It seamlessly integrates with payment gateways like Stripe, providing a user-friendly interface for billing operations.
Settings
The BillingSettings component maintains several state variables to manage its behavior and display. Below are the detailed explanations of each setting:
1. isLoading
- Type: Boolean
- Description: Indicates whether billing data is currently being fetched. The component displays a loading spinner when
true. - Default Value:
true
2. billingContact
- Type: Object | null
- Description: Stores billing contact information for the organization. This includes details of the person responsible for billing operations. The user can update this through the component.
- Default Value:
null
3. orgUsers
- Type: Array
- Description: Contains a list of users in the organization who can be designated as billing contacts. This data is fetched from the server and displayed for selection.
- Default Value:
[]
4. contactSaving
- Type: Boolean
- Description: Indicates whether the system is in the process of saving a new billing contact. This is used for UI feedback.
- Default Value:
false
5. stripeCustomerId
- Type: String | null
- Description: Stores the Stripe customer ID associated with the organization for payment processing. This ID is crucial for any transactions that are processed through Stripe.
- Default Value:
null
6. transactions
- Type: Array
- Description: Stores a record of recent billing transactions. This can be useful for tracking payment history and identifying changes in account balance.
- Default Value:
[]
7. subscriptionInfo
- Type: Object | null
- Description: Contains details about the current subscription plan, including the plan name, state (e.g., active, canceled), and cost. This information is automatically retrieved and displayed to the user.
- Default Value:
null
8. paymentMethod
- Type: Object | null
- Description: Stores information regarding the current payment method for the organization, including payment type and billing address.
- Default Value:
null
9. clientId
- Type: String | null
- Description: A unique identifier for the client, which might be needed for specific payment-related operations.
- Default Value:
null
10. billingMode
- Type: String
- Description: Defines the billing mode of the organization (e.g., 'payg' for Pay-As-You-Go or 'prepaid' for a subscription with upfront payments). This affects how billing summaries are displayed.
- Default Value:
'payg'
11. creditBalance
- Type: Numeric
- Description: Represents the current credit balance available for purchasing tokens or services. Depending on the billing mode, this can vary significantly.
- Default Value:
0
12. currentMonthUsage
- Type: Numeric
- Description: Tracks the token usage for the current month. Important for organizations on a Pay-As-You-Go model to know their spending.
- Default Value:
0
13. stripeInvoices
- Type: Array
- Description: Contains a record of invoices generated by Stripe. Useful for maintaining an audit trail and financial overview.
- Default Value:
[]
14. tiers
- Type: Array
- Description: Represents different billing tiers or subscription plans available to the organization. This is fetched from the server and presented for the user’s choice.
- Default Value:
[]
15. buyModalOpen
- Type: Boolean
- Description: Controls the visibility of the modal for purchasing credits. It toggles based on user interactions.
- Default Value:
false
16. paymentLoading
- Type: Boolean
- Description: Indicates whether a payment operation (like opening the payment portal) is in progress. This is used to disable buttons and provide loading indicators.
- Default Value:
false
17. paymentError
- Type: String | null
- Description: Holds any error messages related to payment processes. This can help in informing users about issues without exposing technical details.
- Default Value:
null
18. plans
- Type: Array
- Description: An array of available subscription plans that the organization can subscribe to. This is also fetched from the server.
- Default Value:
[]
19. plansModalOpen
- Type: Boolean
- Description: Controls the visibility of the modal for viewing available plans. Users can explore different subscription options.
- Default Value:
false
20. plansLoading
- Type: Boolean
- Description: Indicates whether the available plans are currently being fetched. Used to manage loading states within the UI.
- Default Value:
false
21. selectedPlanId
- Type: String | null
- Description: Stores the ID of the plan the user is currently considering for subscription. This allows for easier management and display when the user selects a plan.
- Default Value:
null
22. planCheckoutLoading
- Type: Boolean
- Description: Indicates whether a checkout process for a selected plan is in progress. Providing feedback to the user regarding the checkout's status.
- Default Value:
false
23. planCheckoutSecret
- Type: String | null
- Description: Holds the client secret received from the Stripe API to proceed with the checkout process. Essential for securely initiating the payment.
- Default Value:
null
24. planError
- Type: String | null
- Description: Contains error messages that occur during plan subscription attempts. Useful for debugging and informing users of issues during the subscription process.
- Default Value:
null
How It Works
The BillingSettings component uses state management to manage its state and life cycle. When the component mounts, it calls fetchBillingData and fetchPlans functions to retrieve the latest billing information and subscription options from the server. The state values drive the rendering of UI elements reflecting the billing status and user’s interaction capabilities.
Data Expectations
The component expects the following data from the API endpoints:
-
/api/organization/billing:- Should return a JSON object with fields:
billingContact,orgUsers,stripeCustomerId,transactions,subscriptionInfo,paymentMethod,clientId,billingMode,creditBalance,currentMonthUsage,tiers, andstripeInvoices.
- Should return a JSON object with fields:
-
/api/onboarding/plans:- Should return a structure containing a list of available plans that can be subscribed to by the organization.
Use Cases & Examples
Use Case 1: Managing Subscription Plans
A user from an organization needs to upgrade their subscription plan as they have started using more tokens than their current plan allows. They can open the BillingSettings, click on "View Plans", and choose a more suitable subscription based on their usage.
Use Case 2: Tracking Token Usage
An organization wishes to track its monthly token usage to manage costs efficiently under a Pay-As-You-Go model. The BillingSettings component allows users to view their current month usage and provides information about when their next renewal will be.
Use Case 3: Purchasing Credits
Organizations may run low on tokens due to high usage periods. Through the BillingSettings interface, they can easily purchase additional credits without interrupting service.
Example Configuration for Use Case 1
Configuration for switching to a new plan:
Assuming an organization is currently on a basic plan (with ID basic_plan_001) and wishes to upgrade to a premium_plan_002, the handlePlanSubscribe function would be executed with the corresponding priceId of premium_plan_002.
Sample Code Snippet:
// Example call to upgrade the plan
const priceId = 'premium_plan_002'; // ID of the new plan
handlePlanSubscribe(priceId);This initiates the process to upgrade the organization’s current subscription plan, which updates the UI if successful, informs the user about the new plan and associated charges, and adjusts the billing state appropriately.
In summary, the BillingSettings component integrates critical billing functions while ensuring usability and accessibility for organizations using the Vantage platform. It plays a vital role in the user experience related to financial matters and helps maintain a clear overview of their billing status.