Standalone Dispatch Diagram

%%{init: { "theme": "base", "themeVariables": { "fontSize": "18px", "background": "transparent", "actorBkg": "#038851", "actorTextColor": "#ffffff", "actorBorder": "#026139", "actorLineColor": "#94a3b8", "signalColor": "#64748b", "signalTextColor": "#059669", "noteBkgColor": "#e6f4ee", "noteTextColor": "#02502f", "noteBorderColor": "#038851", "activationBkgColor": "#c6ebdc", "activationBorderColor": "#026139", "sequenceNumberColor": "#ffffff" }, "sequence": { "useMaxWidth": true, "actorMargin": 70, "width": 150, "height": 60, "boxMargin": 12, "noteMargin": 14, "messageMargin": 50, "diagramMarginX": 20, "diagramMarginY": 20, "actorFontSize": 18, "actorFontWeight": 700, "noteFontSize": 15, "noteFontFamily": "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace", "messageFontSize": 16, "messageFontWeight": 700, "noteAlign": "left", "mirrorActors": false } }}%%
sequenceDiagram
    autonumber
    participant P as Partner<br/>(1P channel / POS)
    participant D as Deliverect API<br/>(staging / production)
    participant C as Dispatch Provider<br/>(courier)

    Note over P,D: Base URL<br/>Staging: https://api.staging.deliverect.com<br/>Production: https://api.deliverect.com

    P->>D: Get Access Token
    D-->>P: Bearer token

    rect rgba(3, 136, 81, 0.08)
    Note over P,D: 1. Dispatch Availability
    P->>D: POST Dispatch Availability
    D->>C: Check courier availability
    C-->>D: Availability / quote
    D-->>P: Dispatch available?
    end

    alt Dispatch available
        rect rgba(3, 136, 81, 0.08)
        Note over P,D: 2. Create Order
        P->>D: POST Create Order (delivery)
        D->>C: Assign order to dispatch service
        C-->>D: Assignment confirmed
        D-->>P: Order created
        end

        rect rgba(3, 136, 81, 0.08)
        Note over P,C: 3. Courier Status Update Webhook
        loop Delivery progress
            C->>D: Courier status change
            D->>P: POST Courier Status Update (webhook)
            P-->>D: 200 OK
        end
        end

        opt Order needs cancelling
            Note over P,D: 4. Cancel Order
            P->>D: POST Cancel Order
            D->>C: Cancel delivery
            D-->>P: Cancellation confirmed
        end
    else Dispatch not available
        D-->>P: No courier available — fall back to own delivery
    end