BOB Docs
APIApplicationSubscription

Subscription Service

Key Features

  1. Subscription Management:

    • Create, update, and delete subscriptions, managing attributes such as billing cycle, associated plans, and trial periods.
  2. Subscription Validation:

    • Validates whether users can be added to an organization based on subscription limits.
  3. Subscription Retrieval:

    • Fetch detailed subscription data or retrieve paginated lists for organizational subscriptions.

Methods

  1. Subscription Validation:

    • check_can_add_user(organization_id, final_users_amount): Ensures an organization can add a specified number of users based on its subscription limits.
  2. Subscription Creation and Updates:

    • create_subscription(organization_id, plan_id, subscription_status, billing_cycle_anchor, start_date, trial_start, trial_end): Creates a new subscription with attributes like the associated plan, billing cycle, and trial dates.
    • update_subscription(subscription_id, plan_id, subscription_status, billing_cycle_anchor, start_date, trial_start, trial_end): Updates existing subscription details, including its plan or status.
  3. Subscription Deletion:

    • finish_subscription(subscription_id): Deletes a subscription by its unique ID, marking it as finished or inactive.
  4. Subscription Retrieval:

    • get_subscription(subscription_id): Fetches subscription details, including associated plan, product, and permissions.
    • get_organization_subscriptions(organization_id, page, page_size): Retrieves paginated subscriptions for a specific organization, including metadata like product images and translations.

Example Workflow

  1. Create a New Subscription: Set up a subscription for an organization, specifying billing and trial details:

    subscription = await subscription_service.create_subscription(
        organization_id="org123",
        plan_id=456,
        subscription_status="active",
        billing_cycle_anchor=1672531200,
        start_date=1672444800,
        trial_start=1672444800,
        trial_end=1673136000
    )
  2. Update an Existing Subscription: Modify details of a subscription, such as its status or associated plan:

updated_subscription = await subscription_service.update_subscription(
    subscription_id=123,
    plan_id=789,
    subscription_status="inactive",
    billing_cycle_anchor=1673136000,
    start_date=1672531200
)
  1. Validate User Addition Eligibility: Check if an organization can add more users:
can_add_user = await subscription_service.check_can_add_user(
    organization_id="org123",
    final_users_amount=10
)
  1. Retrieve Paginated Subscriptions: Fetch a paginated list of subscriptions for an organization:
subscriptions, pagination = await subscription_service.get_organization_subscriptions(
    organization_id="org123",
    page=1,
    page_size=5
)
  1. Delete a Subscription: Mark a subscription as finished or inactive:
await subscription_service.finish_subscription(subscription_id=123)

Dependencies

  • Repositories Used:

  • SubscriptionRepository: Handles database operations for subscription records.

  • Utilities:

  • Pagination: Supports efficient paginated retrieval of subscriptions.

Notes

The SubscriptionService simplifies subscription management by offering a robust API for creating, updating, and maintaining subscriptions while ensuring compliance with organizational limits. It integrates seamlessly with other services to deliver a consistent and efficient user experience.

On this page