# Invoice Lifecycle Flow

stateDiagram-v2 [*] --> Draft : Admin creates invoice Draft --> Sent : Send to customer Sent --> Paid : Customer pays (Stripe/PayPal) Sent --> Overdue : Due date passed (batch job) Sent --> Cancelled : Admin cancels Draft --> Cancelled : Admin cancels Overdue --> Paid : Late payment received Paid --> [*] Cancelled --> [*]

## Payment Flow (Stripe)

sequenceDiagram participant C as Customer Portal participant B as Backend API participant S as Stripe API C->>B: POST /payment/stripe/create-intent (invoiceId, amount) B->>S: Create PaymentIntent S-->>B: clientSecret B-->>C: Return clientSecret C->>S: Confirm payment (card details) S-->>C: Payment confirmed C->>B: POST /payment/stripe/confirm (paymentIntentId) B->>B: invoice.markAsPaid("stripe", paymentIntentId) B-->>C: Success — Invoice paid

## Payment Flow (PayPal)

sequenceDiagram participant C as Customer Portal participant B as Backend API participant P as PayPal API C->>B: POST /payment/paypal/create-order (invoiceId, amount) B->>P: POST /v2/checkout/orders P-->>B: orderId + approval URL B-->>C: Redirect to PayPal C->>P: Customer approves payment P-->>C: Redirect back with orderId C->>B: POST /payment/paypal/capture-order (orderId) B->>P: POST /v2/checkout/orders/{id}/capture P-->>B: COMPLETED B->>B: invoice.markAsPaid("paypal", orderId) B-->>C: Success — Invoice paid