> ## Documentation Index
> Fetch the complete documentation index at: https://fit4lifecare.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Automate Reorders, Invoices, and Clinic Notifications

> Fit4Life OS automates the reorder-to-payment chain: a confirmed order triggers an invoice, payment commits the order, and the clinic is notified automatically.

Fit4Life OS connects the entire reorder-to-payment workflow so your team spends less time chasing invoices and more time with patients. When a customer confirms a reorder, the platform creates a pending order, fires a Clover invoice, and waits for payment, at which point the order commits, the clinic is notified, and an Uber delivery can be dispatched. Every step is independently callable (so you can run one piece by hand), every step is audited, and every adapter can run in stub mode so you can test the full chain before going live.

<Note>
  The clinic and owner notification numbers must be configured in your deployment settings (`CLINIC_NOTIFY_NUMBER` and `OWNER_NOTIFY_NUMBER`) for SMS alerts to send on payment. Without these values, the notification step is logged but not sent.
</Note>

## The automation chain

<Steps>
  <Step title="Customer confirms a reorder">
    The customer replies to the SMS bot confirming they want to reorder.
  </Step>

  <Step title="Pending order created + Clover invoice sent">
    A pending order is written to the database and a Clover invoice/payment link is dispatched. The order is marked **pending\_payment** and does not yet appear in reports or financial totals.
  </Step>

  <Step title="Customer pays on the branded pay page">
    The link opens the Fit4Life secure checkout page. Card details are entered directly into Clover's embedded card fields (they never touch Fit4Life servers) and the charge is processed by Clover. The charge result comes back synchronously, so payment confirmation is immediate.
  </Step>

  <Step title="Order committed">
    On confirmed payment, the order status flips to **paid**, it becomes visible in all reports and financials, and the clinic is notified. An Uber delivery is dispatched when delivery is enabled for the order.
  </Step>

  <Step title="Fulfillment notified">
    Fit4Life OS texts the configured notify number with the full order detail: customer, amount, and every line item (the payment link itself only ever shows a total). This message is what the fulfillment team works from.
  </Step>
</Steps>

## Payment-gated commit

Pending orders are intentionally invisible in the Reports hub and all financial calculations until payment is confirmed. This prevents unearned revenue from appearing in your P\&L and ensures your financials only reflect real transactions. Once payment lands and the order commits, it surfaces immediately in every relevant view.

## Clover integration

Fit4Life OS uses an adapter pattern for Clover payments.

<CardGroup cols={2}>
  <Card title="Live mode" icon="plug">
    When the Clover Ecommerce credentials are present, the payment link opens a branded Fit4Life checkout page with Clover's embedded card fields, and the charge is processed through your Clover merchant account. Payment confirmation is synchronous: a succeeded charge commits the order on the spot.
  </Card>

  <Card title="Stub mode" icon="flask">
    Without Clover credentials, the system runs a stub adapter that simulates invoice creation and payment confirmation. Use this for demos and end-to-end testing without touching real payments.
  </Card>
</CardGroup>

## Uber delivery integration

Delivery dispatch follows the same adapter pattern.

<CardGroup cols={2}>
  <Card title="Live mode" icon="truck">
    When the `UBER_*` environment variables are set, Fit4Life OS submits a real delivery request to the Uber API.
  </Card>

  <Card title="Stub mode" icon="flask">
    Without Uber credentials, the adapter logs the dispatch internally and simulates a successful pickup. No real delivery is requested.
  </Card>
</CardGroup>

## Flipping from stub to live

Switching either integration from stub to live requires no code changes. Add the appropriate environment variables to your deployment settings and redeploy.

| Integration          | Goes live when these are present                                                              |
| -------------------- | --------------------------------------------------------------------------------------------- |
| Clover payments      | `CLOVER_ECOMM_PUBLIC_TOKEN` **and** `CLOVER_ECOMM_PRIVATE_TOKEN` **and** `CLOVER_MERCHANT_ID` |
| Uber delivery        | `UBER_API_KEY`                                                                                |
| Clinic notifications | `CLINIC_NOTIFY_NUMBER` (falls back to `OWNER_NOTIFY_NUMBER`)                                  |

These are the exact variables the adapter selector (`adapters/index.ts`) checks, there is no `CLOVER_API_KEY` or `UBER_CLIENT_ID`/`UBER_CUSTOMER_ID`. Once the variables are present and you **redeploy** (env changes do not apply to an existing deployment), the platform detects them and activates the live adapter automatically. See the [Environment Variables reference](/docs/architecture/environment) for the full list.

## Manual override

Any step in the chain can be triggered manually from the **Orders** screen if automation stalls or you need to reprocess a step.

<Steps>
  <Step title="Open the Orders screen">
    Navigate to `/live` and select the **Orders** tab.
  </Step>

  <Step title="Locate the order">
    Find the pending or committed order you need to act on using the search or filter controls.
  </Step>

  <Step title="Trigger the step manually">
    Open the order and use its actions to resend an invoice, dispatch a delivery, or re-run the reorder chain.
  </Step>
</Steps>

Manual overrides are logged in the activity log with a timestamp so you always have a record of manual interventions.

## Pausing automation

A global automation toggle (in Settings) pauses the whole chain. While paused, no invoice, notification, or delivery fires automatically, useful when you want to take everything manual for a period.
