Skip to main content

VIP Subscriptions Flow

Flow Overview

This diagram outlines the process for purchasing and activating VIP subscriptions.

Process Description

  1. Package Selection:

    • The user selects a desired VipPackage from the available options.
  2. Order Creation:

    • When the user initiates the purchase (e.g., through the app store or a web payment gateway), an Order record is created.
    • The Order links the User (user_id) to the selected VipPackage via the polymorphic relationship (item_id, item_type).
    • It stores initial details like payment method (payment_method), potential free trial days (free_trial_days), and transaction identifiers (iap_product_id).
    • The initial order status is likely set to pending.
  3. Payment Processing:

    • The application processes the payment through the chosen method (e.g., In-App Purchase, Credit Card via gateway).
    • Callbacks or responses from the payment provider update the Order status (e.g., completed, failed).
    • Financial details (total, total_tax, paid_amount, paid_currency) and payment references (payment_reference_id, iap_order_id) are stored.
  4. VIP Subscription Activation/Renewal:

    • Upon successful payment (Order status updated to completed), the VipSubscriptionService is triggered ( via an OrderObserver).
    • New Subscription: If it's a new purchase, createVipSubscription method creates a VipSubscription record, linking the User and VipPackage. It sets the start_date, calculates the expire_date (based on package duration or free_trial_days), and sets the status to ONGOING.
    • Renewal: If the user already has a subscription being renewed, renewVipSubscription method updates the existing VipSubscription with new dates and details. It also logs the previous state into VipSubscriptionHistory.
    • The VipSubscription record grants the user access to VIP features.
  5. Expiration/Refund Handling:

    • The VipSubscriptionService also handles expiration (processExpireVipSubscription) and refunds (refundVipSubscription), updating the VipSubscription status and potentially creating history records.

Key Models

  • User: Represents the customer account.
  • VipPackage: Defines the available subscription plans and their details (price, duration, features, IAP ID).
  • Order: Tracks the specific purchase transaction, payment details, and links the user to the purchased package.
  • VipSubscription: Represents the user's actual access grant to VIP features, including start/end dates and status.
  • VipSubscriptionHistory: Logs significant events (renewals, expirations) in the lifecycle of a VipSubscription.
  • VipSubscriptionService: Contains the business logic for creating, renewing, and managing VIP subscriptions based on Orders.