Skip to content

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 ​

text
register → verify email → complete profile → get verified by admin → publish activities
                │                                   │
                └── resend verification             └── suspended: login and supplier routes rejected

Registration and login ​

MethodEndpointAuthPurpose
POST/supplier/registerPublicCreate an account and send verification email
GET/supplier/verify/:tokenPublicVerify email and log the supplier in
POST/supplier/resend-verificationPublicResend the verification email
POST/supplier/loginPublicLogin
POST/supplier/logoutPublicClear auth cookies
PATCH/supplier/update-passwordSupplierChange 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.

http
POST /api/v1/supplier/login
Content-Type: application/json

{ "email": "guide@example.com", "password": "secret" }

Login sets two cookies with the same token:

CookiehttpOnlyConsumer
supplier_auth_tokenYesExpress supplierAuthMiddleware
auth_tokenNoFrontend server components and middleware

A suspended supplier gets 403 at login and is rejected by every supplier route.

Profile ​

MethodEndpointAuthPurpose
GET/supplier/meSupplierCurrent supplier row
PATCH/supplier/meSupplierUpdate profile fields
GET/supplier/:idSupplierSupplier details
GET/supplierAdminAll suppliers, including private fields
PATCH/supplier/:idAdminVerify or suspend
GET/supplier/activitiesSupplierOwn activities
GET/supplier/bookingsSupplierBookings on own activities
GET/supplier/reviewsSupplierPaginated 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 ​

MethodEndpointAuthPurpose
GET/supplier/public/:idPublicPublic storefront
POST/supplier/public/:id/contactTurnstileReveal 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.

text
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:

FieldMeaning
gross, commission, netLifetime totals across confirmed bookings
withdrawn, pendingPayout, withdrawableBalance split by payout status
bookingCount, travellerCountVolume
monthlyLast 12 UTC months, zero-filled, oldest first
topActivitiesUp to 8 activities sorted by gross
currency, commissionRate, minPayoutAmountRates 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 ​

MethodEndpointAuthPurpose
GET/supplier/payoutsSupplierPaginated payout history
POST/supplier/payoutsSupplierRequest a withdrawal
http
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 SERIALIZABLE transaction, so two concurrent requests cannot both spend the same balance.
  • A PENDING payout reserves funds immediately; it is subtracted from withdrawable just like a paid one.
  • If the amount exceeds the balance the response is 409 with the current available figure.
  • A serialization conflict (P2034) returns 409 with "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.

Built with VitePress