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

# Create Sub-Merchant Under A Master Merchant

> Creates a **sub-merchant** whose `parent_vendor_id` points to the given master merchant.

- Master merchant must be a vendor with `parent_vendor_id = null`
- Sub-merchant user role is `subvendor` (not `vendor`)
- Sub-merchants also receive default Ethereum, TRON, and Solana wallets (best-effort)
- Returns **409** when **email** or **phone_number** conflicts. No sub-merchant row and no wallets are created.




## OpenAPI

````yaml /openapi.yaml post /api/v1/auth/merchants/{merchant_id}/sub-merchants
openapi: 3.1.0
info:
  title: EmaalCoin API
  description: >
    EmaalCoin API reference. These APIs power cryptocurrency exchange between
    USDT and Fiat trading.


    - **On-Ramp**: Buy USDT with fiat (KES) via mobile money (STK Push for
    Kenya)

    - **Off-Ramp**: Sell USDT for KES with mobile money payout (Kenya)

    - **Ethereum, TRON, and Solana**: Multi-chain wallet support

    - **Merchant Offers**: Create and manage trading offers

    - **OTC Flows**: Bank and mobile money deposits/withdrawals for merchants

    - **Pricing engine**: FX quotes and fee profiles for quote-backed orders and
    transfers

    - **P2P/B2B transfers**: Internal and external stablecoin sends (USDT/USDC)
    with optional pricing snapshots

    - **Stablecoin swaps**: Treasury-backed two-leg USDT ↔ USDC conversion with
    BitGo confirmation, inventory reservation, and automatic refunds

    - **Multisig**: Collaborative and platform-managed multisig flows for
    high-value B2B
  version: 1.1.0
servers:
  - url: https://crypto.westminister.tech
    description: Production API (requires DNS for this hostname).
  - url: http://13.42.110.185:8080
    description: >-
      UAT on EC2 (direct). Use this base when building proof PDF URLs if the
      production hostname does not resolve.
security: []
tags:
  - name: Pricing
    description: >-
      Commercial pricing profiles and FX rate quotes (admin). Used with orders
      and transfers for auditable snapshots.
  - name: Transfers
    description: >-
      P2P and B2B stablecoin transfers (USDT/USDC). Optional fiat-equivalent
      pricing fields. B2B multisig behavior depends on wallet registration
      (synchronous completion vs proposal flow).
  - name: Stablecoin Swaps
    description: >-
      Treasury-backed USDT ↔ USDC conversions for BitGo provider-managed wallets
      on `tron`, `ethereum`, or `solana`. Collection confirms before treasury
      payout starts. Completion requires both legs and dual-asset balance
      synchronization.
  - name: Multisig
    description: >-
      Multisig wallet registration and TRON proposal/confirm flows
      (vendor/admin).
  - name: Escrow Wallets
    description: Escrow pool wallet metadata for off-ramp and operations.
  - name: Users
    description: >-
      User-related operations (registration, lookup, updates, counts, status
      changes)
  - name: Wallets-Users
    description: User wallet operations (create, manage, query balances)
  - name: Offers
    description: Offer operations (create, read, list, counts)
  - name: Orders
    description: Order operations (create, update, list, counts, stats)
  - name: Payment
    description: Payment initiation operations
  - name: Merchants
    description: >
      Merchant (vendor) onboarding and hierarchy operations.

      USE **GET /API/V1/AUTH/MERCHANTS** WITH **PAGE_ID** AND **PAGE_SIZE** TO
      PAGE MASTER VENDORS.

      USE **GET /API/V1/AUTH/MERCHANTS/{MERCHANT_ID}** FOR ONE MASTER VENDOR,
      **MERCHANT_WALLETS**, AND ALL **SUBVENDOR** ROWS WITH **WALLETS** (FULL
      TREE).
  - name: OTC Deposits
    description: >
      OTC fiat-to-crypto deposits (bank or mobile money). Rows live in
      **`otc_deposits`**. Merchants create drafts or one-shot deposits.
      **admin**, **otc_officer**, or **treasury** list all deposits.

      B2B bank flow uses draft, quote, submit, proof, assign, claim, settlement,
      and audit. **`credited_to_address`** is the merchant on-chain wallet
      treasury credits (resolved from the default wallet for
      **`requested_network`** on the master merchant ledger user or any
      **sub-vendor** under that merchant).

      **`GET /api/v1/auth/otc/deposits`** backfills missing
      **`credited_to_address`**/**`to_wallet_id`** when a wallet can be
      resolved. One-shot **`POST /api/v1/auth/otc/deposits`** persists the
      payout address when **`requested_network`** is sent.

      Bank proof PDFs upload via `POST .../proof` and are viewed at **`GET
      /otc-deposits-proof/{deposit_id}/{file}.pdf`** (relative
      **`proof_url`**/**`file_url`** plus API base URL).

      Merchants may edit tab-1 draft fields with **`PATCH
      /api/v1/auth/otc/deposits/{id}/draft`** while **`status`** is **`draft`**.
  - name: OTC Withdrawals
    description: >-
      OTC crypto-to-fiat withdrawals (bank or mobile money). Merchants create.
      Admin approves and executes.
  - name: OTC Config
    description: OTC display config (bank details, mobile money paybill) for merchant UI
  - name: Fiat Currencies
    description: >
      Shared platform **fiat_currencies** catalog. **GET
      /api/v1/auth/fiat-currencies** lists active rows for UI pickers. **GET
      /api/v1/auth/fiat-currencies/admin** lists all rows including inactive
      (admin). Admin manages rows with **GET
      /api/v1/auth/fiat-currencies/{id}**, **POST
      /api/v1/auth/fiat-currencies**, **PATCH
      /api/v1/auth/fiat-currencies/{id}**, and **DELETE
      /api/v1/auth/fiat-currencies/{id}**. Use for OTC, pricing, orders,
      remittance, and backoffice — not under **`/otc/...`**. Prefer **PATCH**
      with **`is_active: false`** over delete when a currency is referenced.
  - name: Countries
    description: >-
      Shared platform **countries** catalog. Public **GET /api/v1/countries**
      lists active rows for pickers. Auth **GET /api/v1/auth/countries** returns
      the same active catalog. Admin manages rows with **GET
      /api/v1/auth/countries/admin**, **GET /api/v1/auth/countries/{id}**,
      **POST /api/v1/auth/countries**, **PATCH /api/v1/auth/countries/{id}**,
      and **DELETE /api/v1/auth/countries/{id}**.
  - name: Files
    description: Authenticated file uploads for OTC receipts and proof artifacts.
paths:
  /api/v1/auth/merchants/{merchant_id}/sub-merchants:
    post:
      tags:
        - Merchants
      summary: Create Sub-Merchant Under A Master Merchant
      description: >
        Creates a **sub-merchant** whose `parent_vendor_id` points to the given
        master merchant.


        - Master merchant must be a vendor with `parent_vendor_id = null`

        - Sub-merchant user role is `subvendor` (not `vendor`)

        - Sub-merchants also receive default Ethereum, TRON, and Solana wallets
        (best-effort)

        - Returns **409** when **email** or **phone_number** conflicts. No
        sub-merchant row and no wallets are created.
      parameters:
        - name: merchant_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: Master merchant ID.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - email
                - phone_number
                - first_name
                - last_name
                - password
                - kyc_status
              properties:
                email:
                  type: string
                  format: email
                phone_number:
                  type: string
                first_name:
                  type: string
                last_name:
                  type: string
                password:
                  type: string
                  format: password
                kyc_status:
                  type: string
                  enum:
                    - pending
                    - approved
                    - rejected
                is_active:
                  type: boolean
                pin:
                  type: string
                  pattern: ^[0-9]{6}$
            example:
              email: merchant1.branch1@gmail.com
              phone_number: '+254700000002'
              first_name: Bob
              last_name: Branch
              password: secret
              kyc_status: pending
              is_active: true
              pin: '654321'
      responses:
        '201':
          description: Sub-merchant created
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  sub_merchant:
                    $ref: '#/components/schemas/Merchant'
                  wallets:
                    type: array
                    items:
                      $ref: '#/components/schemas/MerchantWalletSummary'
                  warning:
                    type: string
                    description: >-
                      Present when one or more default wallets failed. Create
                      missing wallets manually.
                  wallet_errors:
                    type: array
                    items:
                      $ref: '#/components/schemas/DefaultWalletFailure'
              example:
                message: Sub-merchant created successfully with default wallets
                sub_merchant:
                  id: f004fba4-7b6c-423a-983b-fdc283f8a1ab
                  email: merchant1.branch1@gmail.com
                  phone_number: '+254700000002'
                  first_name: Bob
                  last_name: Branch
                  role: subvendor
                  kyc_status: pending
                  is_active: true
                  parent_vendor_id: a2aeca1d-9686-4158-b4be-d0a3fd04760e
                wallets:
                  - id: 74b2bdea-8cf1-4fbf-9b28-5c48a56bda6b
                    network: ethereum
                    address: 1.4545186821318902e+47
                    is_default: true
                    wallet_type: hot
                  - id: 2f7e7c32-9623-4ca4-8733-fd07449bd6b8
                    network: tron
                    address: TXpgi7XLZEQQgC7pR1iKuRsKyesskZkEqM
                    is_default: false
                    wallet_type: hot
                  - id: b2c3d4e5-f6a7-8901-bcde-f12345678901
                    network: solana
                    address: 9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM
                    is_default: false
                    wallet_type: hot
        '409':
          description: Email or phone_number already registered
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
              example:
                error: phone_number is already registered
      security:
        - bearerAuth: []
components:
  schemas:
    Merchant:
      type: object
      description: Merchant user summary (master **vendor** or **subvendor** branch).
      properties:
        id:
          type: string
          format: uuid
        email:
          type: string
          format: email
        phone_number:
          type: string
        first_name:
          type: string
        last_name:
          type: string
        role:
          type: string
          enum:
            - vendor
            - subvendor
        kyc_status:
          type: string
        is_active:
          type: boolean
        parent_vendor_id:
          type: string
          format: uuid
          nullable: true
          description: >-
            Null for master merchants. Set to the master vendor id for
            sub-merchants.
    MerchantWalletSummary:
      type: object
      properties:
        id:
          type: string
          format: uuid
        network:
          type: string
          enum:
            - ethereum
            - tron
            - solana
        address:
          type: string
        alias:
          type: integer
          format: int64
        is_default:
          type: boolean
        wallet_type:
          type: string
    DefaultWalletFailure:
      type: object
      description: Per-network error when default wallet provisioning fails for one chain.
      properties:
        network:
          type: string
          enum:
            - ethereum
            - tron
            - solana
        error:
          type: string
          description: Error message from the failed wallet create attempt.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: PASETO

````