# Going live

The order matters. Each step is short; the point is not skipping any.

Going live **is** the pilot: load the twenty pilot clients, not everyone. The first
night's run bills and chases every client on file, so whoever is loaded on day one
is who gets invoiced and reminded on day one.

---

## Day 0 — the server

1. **Install.** On a fresh Ubuntu server, with PHP 8.3, MariaDB or MySQL, nginx and
   `wkhtmltopdf`:

       sudo DB_PASS='a-strong-password' APP_URL='https://billing.caresoft.co.in' bash deploy/install.sh

   It refuses to run against a database that already holds CareBill.

2. **Web server.** Copy `deploy/nginx.conf`, change the three marked lines, then
   `certbot --nginx -d billing.caresoft.co.in`. The web root must be `public/` —
   never the project folder.

3. **Prove nothing private is public:**

       php tools/smoke_test.php --web

   Every private path must say *refused*. If any says anything else, stop and fix the
   web root before anything else happens.

4. **Cron:** `crontab -u www-data deploy/crontab.txt`

## Day 0 — the accounts

5. Sign in as `admin@caresoft.co.in` / `Caresoft@123`. You will be made to change it.
6. Turn on two-factor sign-in (Security). Save the recovery codes somewhere offline.
7. Add a **second admin** — ideally outside the accounts team — and have them do the same.
   Without two admins, no write-off, credit note or bank change can ever be approved.
8. Add the rest of the team with the narrowest role that fits. Your CA gets **Auditor**.

## Day 0 — the business

9.  **Brand details** (Brands → Caresoft HIS): GSTIN, PAN, bank account, signatory.
    Check the preview — the next invoice number should read `CSPL/yy/mm/0001`.
10. **Settings:** sending window, escalation and management email addresses.
    Leave mail on **log** for now.
11. **Import the twenty pilot clients** (Setup → Import data): clients, then services,
    then opening balances. Do a trial run first; it shows what would be created.
12. Put the **TAN** on every pilot client who deducts TDS.
13. **Readiness** (Setup → Readiness) should show nothing under *fix first*.

## Day 0 — the three providers

**Amazon SES**
- Verify the sending domain, with DKIM and SPF records, and request production access so
  you are out of the SES sandbox.
- Create an SNS topic for bounces and complaints, subscribed to
  `https://billing.caresoft.co.in/mailhook.php?key=…` (the key is in Settings). This is what
  lets CareBill stop mailing a dead address before SES counts it against you.
- SES suspends accounts whose bounce or complaint rate climbs. The warm-up ramp and the
  suppression list exist for exactly that; leave them on.

**WhatsApp Cloud API**
- Phone number id and permanent token in Settings; webhook to `/wahook.php` with your verify
  token, subscribed to `messages`.
- Get the reminder templates approved by Meta, and put each approved name on the matching
  template in Setup → Templates. Outside 24 hours of a client's last message, only approved
  templates can be sent.

**CCAvenue**
- Settings → Payments: provider **CCAvenue**, merchant id, access code, working key, mode
  **Test** first. Test and live keys are different.
- Register `https://billing.caresoft.co.in` with CCAvenue as the website, and
  `https://billing.caresoft.co.in/ccavenue.php` as the return address.
- In test mode, pay an invoice end to end with CCAvenue's test card. The receipt should
  appear within a minute; if the page says *being confirmed*, the sweep will record it within
  half an hour.
- Switch to **Live**, and make one real payment of a small amount against a real invoice of
  your own before any client sees a Pay button.

**Razorpay (UPI)**
- Key id, Key secret and a Webhook secret of your choosing in Settings → Payments. In
  Razorpay's dashboard, add a webhook to `https://billing.caresoft.co.in/webhook.php` for
  `payment_link.paid`, with the same secret.
- Tick both methods under *Offer clients*. Test mode first, then one small real UPI payment.

**SMS (optional)** — register the sender, entity and each template on DLT first; put the DLT
template id on each SMS template. Leave the driver on *Log only* until they are approved.

**Tally (optional)** — turn on Tally's HTTP server, set the address and company name, and put
each client's Tally ledger name on them where it differs from their legal name. Press *Send to
Tally now* for one day's invoices and check them in Tally before turning the nightly sync on.

## Days 1–3 — dry run, mail still on log

14. Each morning, before anything else:
    - **Outbox** — read what *would* have gone out. Wrong names, wrong amounts, the wrong
      tone for a particular hospital: this is where you catch it, while it costs nothing.
    - **Worklist** — what the system thinks needs a person.
    - **Invoices → drafts** — what it wants to bill.
15. Fix templates, contacts and rules until three mornings in a row look right.

## Day 4 — switch mail on

16. Settings → mail driver: `ses` (or `smtp` for your own server). Keep the daily cap low;
    the warm-up ramp raises it on its own.
17. Send yourself a test first. Then let the queue run.
18. `php tools/smoke_test.php` — the mail line should no longer warn.

## Every week

- The smoke test runs itself on Monday mornings (in the crontab) and writes to
  `storage/logs/smoke.log`. Read it.
- Integrity (Setup → Integrity) — anything under *does not add up* is a real problem.
- Deliverability — bounce and complaint rates.

## Things that must never happen on the live server

- Running anything in `tools/` other than `smoke_test.php`. The others write to the
  database and several clear it. They refuse to run unless the config says `env => test`
  **and** the command sets `CAREBILL_ENV=test` — keep it that way.
- Changing the numbering once live invoices exist.
- Loading `sql/schema.sql` or `sql/seed.sql` into the live database. Upgrades use the
  individual migrations listed in INSTALL.md.
