Skip to documentation
Documentation

Developer guide · 6 min

Integrate wholesale checkout and updates

These routes are defined in the source supplied with this release. Apply the new migration and verify your deployed OpenAPI schema before connecting a storefront.

Authoritative checkout contract

Link to /shop/checkout?wholesaleOrder=<wholesale-order-id>. Fetch GET /wholesale/orders/:id for the authenticated buyer. Require the current issued invoice to be accepted before requesting POST /wholesale/orders/:id/checkout.

The backend creates or recovers a collection order for the exact invoice and requested balance. Use its paymentOrderId with the existing Stripe or M-Pesa endpoints. Provider callbacks allocate funds into the invoice ledger; they do not grant wholesale fulfillment.

Never send catalog totals from the browser or recreate an invoice as retail cart lines. Preserve the wholesaleOrder query parameter through checkout recovery and remove provider secrets from the URL.

Private receipts

POST /wholesale/orders/:orderId/payment-claims/:claimId/receipts accepts multipart/form-data with one receipt file. Downloads use GET /wholesale/orders/:orderId/receipts/:receiptId. Admin equivalents begin /admin/wholesale. Ownership and active roles are checked in the service.

The new migration stores bounded receipt bytes in a private PostgreSQL column excluded from normal projections. Images are decoded and re-encoded. File metadata is returned without bytes; downloads are forced attachments with no-store and nosniff. Include receipt storage in retention and database-capacity planning.

Notification setup

GET/PATCH /wholesale/notification-preferences persists opt-in, phone number and a revision guard. GET /wholesale/notifications returns customer updates; GET /admin/wholesale/notifications returns operations updates and per-channel delivery states.

Configure WHOLESALE_FRONTEND_ORIGIN, issuer fields, the existing Mailgun service and email queue. Default branded HTML works without uploading templates. Optional Mailgun templates and upload instructions are included in mailgun/.

WhatsApp uses WHOLESALE_WHATSAPP_ENABLED, WHOLESALE_WHATSAPP_TEMPLATE, WHOLESALE_WHATSAPP_LANGUAGE and the shared WHATSAPP_ACCESS_TOKEN, WHATSAPP_PHONE_NUMBER_ID and WHATSAPP_GRAPH_VERSION. Keep it disabled until Meta approves the utility template and credentials are ready.

Outbox and operational checks

Channel jobs are independent. Email uses a stable queue job ID; WhatsApp timeouts become REVIEW to avoid blind duplicate sends. Queued and provider-accepted states must never be displayed as delivered.

Apply 1793444400000-WholesaleExperience_migration after the existing wholesale migration. Production synchronize remains false. Run the included validation and staging smoke checks before deployment.