Skip to main content

Order Flow

Flow Overview

Process Description

  1. Cart Creation

    • Customer adds products (courses, bundles, or course videos) to cart
    • Cart model stores:
      • Product information and customer details
      • Affiliate code (ref) for tracking affiliate sales
      • Promo code for promotion tracking
  2. Order Creation

    • When customer attempts payment, an order is created
    • Order contains items through OrderItem pivot table
    • Order tracks payment status, method, and total amounts
    • Order items store product-specific details (prices, discounts, etc.)
  3. Payment Processing

    • Order status is updated based on payment result
    • Upon successful payment, order is marked as completed
  4. Subscription Creation & Update

    • Two jobs are triggered after successful payment:
      • ProcessOrderVideos: Handles video-specific payments and adds them to the relevant subscription
      • ProcessOrderSubscriptions: Creates or updates (renews) subscriptions for each course (even those in bundles)
    • Customer gains access to purchased content through these subscriptions

Post-Purchase Processing

  1. Affiliate Tracking

    • System identifies affiliate through ref code in cart
    • Updates affiliate sales records and commission calculations
  2. Promotion Tracking

    • Records promotion usage through promo_code
    • Updates promotion statistics for campaign analysis
  3. Loyalty Points Calculation

    • Calculates points based on order total
    • Creates points record for customer
    • Updates customer's total points balance

Key Models

  • Cart: Temporary storage for products, affiliate codes, and promo codes before purchase
  • Order: Tracks the complete purchase transaction
  • OrderItem: Pivot table connecting orders with purchased products
  • Subscription: Manages access to purchased content
  • Point: Defines point types and rules for loyalty program
  • PointsRecord: Tracks customer loyalty points transactions
  • Promotion: Manages promotional campaigns and tracking
  • Customer: Includes affiliate marketers who can refer sales