sequenceDiagram
    actor User
    participant UI as TV Console UI
    participant API as TV API
    participant Stripe
    participant DB as TV Console DB
    participant Webhook as Stripe Webhook
    participant Slack

    User->>UI: Access TV Console
    User->>UI: Select package plan<br/>(Basic/Standard/Premium)
    User->>UI: Confirm buy plan
    
    UI->>API: Request create order
    API->>DB: Check if user has payment_provider_customer_id
    
    alt No Stripe Customer ID
        API->>Stripe: Create Customer
        Stripe-->>API: Return Customer ID
        API->>DB: Update user with payment_provider_customer_id
    end
    
    API->>Stripe: Create Checkout Session<br/>(with customer ID)
    Stripe-->>API: Return Session ID
    
    API->>DB: Create wishlist to user record<br/>Create order history (unpaid)
    DB-->>API: Confirm saved
    API-->>UI: Return Checkout Session ID
    
    UI->>Stripe: Redirect to payment form
    User->>Stripe: Fill payment info
    
    Note over Stripe,Webhook: Payment Processing
    
    alt Successful Payment
        rect rgb(230, 230, 255)
            Webhook->>API: Webhook: checkout.session.completed
            
            API->>DB: Transaction begin
            API->>DB: Update order history<br/>(payment_intent_id, invoice_id,<br/>status, payment_status, paid_at)
            API->>DB: Update wishlist status to active
            API->>DB: Transaction commit
            
            API->>Slack: Send notification of successful purchase
            
            API-->>UI: Return success status
            UI-->>User: Show success message
        end
    else Failed Payment
        rect rgb(255, 200, 200)
            Note over Webhook,API: Payment fails in Stripe
            
            API->>DB: Update order history<br/>(status: failed)
            
            API-->>UI: Return error status
            UI-->>User: Show failure message<br/>with retry option
        end
    end