Loyalty Order Flow

%%{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
    participant M as Merchant
    participant DR as Deliverect
    participant LP as Loyalty Partner (Webhook Receiver)
    participant Ch as Ordering Channel

    Note over M,LP: Registration (during certification)
    M->>DR: Selects generic integration as loyalty provider
    DR->>LP: POST Register Loyalty Provider
    LP-->>DR: Remaining configuration

    Note over DR,LP: Optional SSO Authentication
    DR->>LP: POST SSO: OAuth token exchange (auth code)
    LP-->>DR: Access token
    DR->>Ch: POST Channel SSO: Authorization
    Ch-->>DR: Authentication result

    Note over DR,LP: Customer Management
    DR->>LP: POST Create Customer (create/update profile)
    LP-->>DR: Customer profile
    DR->>LP: GET Get Customer
    LP-->>DR: Profile + loyalty customer ID

    Note over DR,LP: Tier System
    DR->>LP: GET Get Loyalty Tiers
    LP-->>DR: List of tiers (name, description, point requirements)

    Note over DR,LP: Wallet Application Lifecycle
    DR->>LP: GET Get Customer Wallet
    LP-->>DR: Wallet balance (cash / points)
    DR->>LP: POST Validate Wallet Application
    LP-->>DR: Discount amount & type (after business-rule checks)

    Note over DR,LP: Program Application Lifecycle
    DR->>LP: POST Retrieve Loyalty Programs
    LP-->>DR: List of eligible programs
    DR->>LP: POST Validate Loyalty Program application
    LP-->>DR: Discounts to apply to basket

    Note over DR,LP: Order Completion
    alt Order placed
        DR->>LP: POST Create Order
        LP-->>DR: Redeem discounts / deduct points / mark coupons used
    else Order cancelled
        DR->>LP: POST Cancel Order
        LP-->>DR: Revert redemptions / return points
    end