Suppliers & Payouts
Suppliers are the activity providers. Registration is deliberately minimal — email and password only — and the business profile is filled in after verification. A supplier must be verified and not suspended to run a public storefront, and every payout is checked against confirmed bookings in a serializable transaction.
Lifecycle
register → verify email → complete profile → get verified by admin → publish activities
│ │
└── resend verification └── suspended: login and supplier routes rejectedRegistration and login
| Method | Endpoint | Auth | Purpose |
|---|---|---|---|
| POST | /supplier/register | Public | Create an account and send verification email |
| GET | /supplier/verify/:token | Public | Verify email and log the supplier in |
| POST | /supplier/resend-verification | Public | Resend the verification email |
| POST | /supplier/login | Public | Login |
| POST | /supplier/logout | Public | Clear auth cookies |
| PATCH | /supplier/update-password | Supplier | Change password |
Registration accepts only email and password, creates the row with verificationRequestedAt, and returns 201 plus a nextVerificationIn hint of 120 seconds. If the email cannot be sent the account still exists and the response includes a warning instead of failing.
Verification tokens are JWTs signed with JWT_SECRET (subject email-verification) and expire in 1 day. GET /supplier/verify/:token validates the token, marks the supplier isVerified = true with verifiedAt, and issues a supplier session token (JWT_EXPIRY, from JWT_SECRET) via the same auth cookies as login, so the supplier lands signed in.
POST /api/v1/supplier/login
Content-Type: application/json
{ "email": "guide@example.com", "password": "secret" }Login sets two cookies with the same token:
| Cookie | httpOnly | Consumer |
|---|---|---|
supplier_auth_token | Yes | Express supplierAuthMiddleware |
auth_token | No | Frontend server components and middleware |
A suspended supplier gets 403 at login and is rejected by every supplier route.
Profile
| Method | Endpoint | Auth | Purpose |
|---|---|---|---|
| GET | /supplier/me | Supplier | Current supplier row |
| PATCH | /supplier/me | Supplier | Update profile fields |
| GET | /supplier/:id | Supplier | Supplier details |
| GET | /supplier | Admin | All suppliers, including private fields |
| PATCH | /supplier/:id | Admin | Verify or suspend |
| GET | /supplier/activities | Supplier | Own activities |
| GET | /supplier/bookings | Supplier | Bookings on own activities |
| GET | /supplier/reviews | Supplier | Paginated reviews on own activities |
PATCH /supplier/me validates against UpdateSupplierSchema. It accepts the business fields (type, fullName, phone, address, legalName, professionalLicenseNumber, companyDescription, companyLogo, publicBrand, businessRepresentingWebsite, bio, languages, license) and regenerates username from fullName as <slug>-<supplierId>.
GET /supplier is admin-only because the row includes email, phone, address and licence number. The public profile is a separate, deliberately narrower endpoint.
Public profile and contact
| Method | Endpoint | Auth | Purpose |
|---|---|---|---|
| GET | /supplier/public/:id | Public | Public storefront |
| POST | /supplier/public/:id/contact | Turnstile | Reveal email and phone |
:id may be the bare supplierId or the generated username. supplierIdFromSlug extracts the trailing 21-character nanoid, so /supplier/public/everest-guides-abc123... works too.
The public profile returns supplierId, username, fullName, type, companyLogo, bio, companyDescription, isVerified, only published + approved activities, up to 20 recent reviews, and aggregate stats (totalActivities, totalReviews, averageRating). A suspended supplier returns 404.
Contact details are not in the profile. POST /supplier/public/:id/contact verifies the Turnstile token for action supplier_contact and only then returns { email, phone }. This keeps the address out of scrapers while still letting a serious traveller make contact.
Revenue
GET /supplier/revenue (supplier auth) aggregates every CONFIRMED booking on the supplier's activities.
commission = round(gross × PLATFORM_COMMISSION_RATE)
net = gross − commission
withdrawn = sum(PAID payouts)
pending = sum(PENDING payouts)
withdrawable = max(0, net − withdrawn − pending)Defaults: PLATFORM_COMMISSION_RATE=0.3 (30%) and MIN_PAYOUT_AMOUNT=50. Both are validated at boot; the rate must be between 0 and 1.
The response includes:
| Field | Meaning |
|---|---|
gross, commission, net | Lifetime totals across confirmed bookings |
withdrawn, pendingPayout, withdrawable | Balance split by payout status |
bookingCount, travellerCount | Volume |
monthly | Last 12 UTC months, zero-filled, oldest first |
topActivities | Up to 8 activities sorted by gross |
currency, commissionRate, minPayoutAmount | Rates the UI should display instead of hardcoding |
Commission is rounded per booking and then summed, while each month's totals are rounded once. monthly buckets by the booking's startDate, not by payment date.
One currency per supplier
Stripe Checkout currently hardcodes USD, so the report assumes a single currency. A supplier selling in both USD and NPR would need per-currency balances.
Payouts
| Method | Endpoint | Auth | Purpose |
|---|---|---|---|
| GET | /supplier/payouts | Supplier | Paginated payout history |
| POST | /supplier/payouts | Supplier | Request a withdrawal |
POST /api/v1/supplier/payouts
Content-Type: application/json
{ "amount": 250, "note": "October withdrawal" }Rules enforced by requestPayout:
- Amount must be a positive number with at most two decimals and must be at least
MIN_PAYOUT_AMOUNT. - The balance check and the insert run in one
SERIALIZABLEtransaction, so two concurrent requests cannot both spend the same balance. - A
PENDINGpayout reserves funds immediately; it is subtracted fromwithdrawablejust like a paid one. - If the amount exceeds the balance the response is
409with the currentavailablefigure. - A serialization conflict (
P2034) returns409with "Balance changed, please try again".
Payouts are created PENDING and are marked PAID or REJECTED out of band. There is no supplier-facing cancel endpoint.
Supplier-auth middleware
supplierAuthMiddleware reads only supplier_auth_token, verifies it with JWT_SECRET, loads the supplier, and rejects a missing row or isSuspended = true. This is stricter than the shared authMiddleware, which also accepts user and admin cookies for legacy routes.