VIP Subscriptions Flow
Flow Overview
This diagram outlines the process for purchasing and activating VIP subscriptions.
Process Description
-
Package Selection:
- The user selects a desired
VipPackagefrom the available options.
- The user selects a desired
-
Order Creation:
- When the user initiates the purchase (e.g., through the app store or a web payment gateway), an
Orderrecord is created. - The
Orderlinks theUser(user_id) to the selectedVipPackagevia 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
statusis likely set to pending.
- When the user initiates the purchase (e.g., through the app store or a web payment gateway), an
-
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
Orderstatus (e.g., completed, failed). - Financial details (
total,total_tax,paid_amount,paid_currency) and payment references (payment_reference_id,iap_order_id) are stored.
-
VIP Subscription Activation/Renewal:
- Upon successful payment (
Orderstatus updated to completed), theVipSubscriptionServiceis triggered ( via anOrderObserver). - New Subscription: If it's a new purchase,
createVipSubscriptionmethod creates aVipSubscriptionrecord, linking theUserandVipPackage. It sets thestart_date, calculates theexpire_date(based on package duration orfree_trial_days), and sets the status toONGOING. - Renewal: If the user already has a subscription being renewed,
renewVipSubscriptionmethod updates the existingVipSubscriptionwith new dates and details. It also logs the previous state intoVipSubscriptionHistory. - The
VipSubscriptionrecord grants the user access to VIP features.
- Upon successful payment (
-
Expiration/Refund Handling:
- The
VipSubscriptionServicealso handles expiration (processExpireVipSubscription) and refunds (refundVipSubscription), updating theVipSubscriptionstatus and potentially creating history records.
- The
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.