BOB Docs
APIApplicationSubscription

PlanService

Key Features

  1. Plan Management:

    • Create, retrieve, and manage subscription plans, linking them to products and permission groups.
    • Control plan availability and configure trial periods for subscription offerings.
  2. Permission Integration:

    • Associate plans with permission groups for role-based access control.
  3. Trial Management:

    • Track and validate trial usage to enforce policies and prevent misuse.
  4. Pagination Support:

    • Retrieve subscription plans with pagination, making the service scalable for large datasets.

Methods

  1. Plan Management:

    • get_plans_groups(): Retrieves all permission groups linked to subscription plans.
    • get_paginated_plans(page, page_size, available): Fetches paginated subscription plans, optionally filtering by availability.
    • create_plan(product_id, group_id, available, trial_period_days): Creates a subscription plan by linking a product and a permission group, with optional trial period configuration.
    • get_plan_based_on_product(product_id): Retrieves the plan associated with a specific product.
  2. Trial Management:

    • check_trial_usage(email): Verifies if a user (identified by email) has already utilized a trial subscription.
    • process_trial_usage(email): Records an email's usage for a trial subscription, ensuring accurate tracking.

Example Workflow

  1. Create a New Subscription Plan: Create a plan associated with a product and a permission group, and configure a trial period:

    new_plan = await plan_service.create_plan(product_id=123, group_id=456, trial_period_days=14)
  2. Retrieve Paginated Plans: Fetch a paginated list of available subscription plans:

plans, pagination = await plan_service.get_paginated_plans(page=1, page_size=5)
  1. Check Trial Eligibility: Determine if a user is eligible for a trial based on their email:
can_use_trial, checksum = await plan_service.check_trial_usage(email="user@example.com")
  1. Record Trial Usage: Register a user's trial usage to ensure they do not exceed their trial allocation:
await plan_service.process_trial_usage(email="user@example.com")
  1. Fetch a Plan for a Product: Retrieve the subscription plan associated with a specific product:
plan = await plan_service.get_plan_based_on_product(product_id=123)

Dependencies

  • Repositories:

    • PlanRepository: Manages database operations for subscription plans.
    • TrialUsageRepository: Tracks and validates trial usage records.
  • Utilities:

    • calculate_checksum: Generates a secure checksum for tracking trial eligibility.

Notes

The PlanService ensures efficient and secure management of subscription plans, integrating seamlessly with products and permission groups. Its trial management capabilities provide robust enforcement of subscription policies, supporting a scalable and user-friendly subscription system.

On this page