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

# Manually trigger a settlement run

> Runs the end-of-day settlement for a specified date on demand.
This is idempotent – if the date has already been successfully settled,
the existing record is returned without reprocessing.

**Use cases**:
- Re-running a failed batch (e.g. after a database outage).
- Settling a back-date after delayed transaction processing.
- Smoke-testing the settlement pipeline in staging.

The scheduled job automatically covers yesterday at 23:59 UTC;
this endpoint is for operational override only.




## OpenAPI

````yaml /openapi/idaas.openapi.json post /v1/settlement/run
openapi: 3.0.3
info:
  title: IDaaS – Identity as a Service API
  description: >
    ## Overview

    IDaaS provides globally unique, portable identity **tags** that travel with
    users across applications.  Each tag is a short handle (e.g. `@alice`) that
    can carry verified claims, participate in cross-application payments, and be
    federated to external identity providers.


    ## Key Capabilities

    - **Tags** – create, transfer, disable, and attach claims to identity
    handles.

    - **Cross-application payments** – send money from any tag on Application
    A   to any tag on Application B; each application has a single escrow
    wallet   tracked for end-of-day settlement.

    - **Ledger** – every completed payment produces an immutable double-entry  
    `DEBIT` / `CREDIT` pair recorded against application wallets.

    - **Webhooks** – real-time callbacks with HMAC-SHA256 signatures and  
    automatic retry (up to 3 attempts with exponential back-off).

    - **Settlement** – a scheduled end-of-day job aggregates daily wallet  
    movements and emits `SETTLEMENT_BATCH` Kafka events.


    ## Authentication

    1. Register an application: `POST /v1/applications`

    2. Exchange credentials for a JWT: `POST /v1/auth/token`

    3. Include the JWT as `Authorization: Bearer <token>` on all protected
    calls.


    ## Rate Limits

    | Endpoint | Limit |

    |---|---|

    | `POST /v1/auth/token` | 10 req / min per IP |

    | `POST /v1/transactions` | 60 req / min per application |

    | All other | 300 req / min per IP |
  contact:
    name: ReflexPay Platform Team
    url: https://yourflexpay.com
    email: integration@yourflexpay.com
  license:
    name: Proprietary
    url: https://yourflexpay.com/terms
  version: 1.0.0
servers:
  - url: https://staging-idaas.yourflexpay.com/api
    description: Staging
  - url: https://idaas.yourflexpay.com/api
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Authentication
    description: Exchange client credentials for a JWT access token.
  - name: Encryption
    description: >
      JWE payload encryption – end-to-end security for API request bodies and
      webhook payloads.

      Each application receives an EC P-256 keypair at registration:

      - IDaaS encrypts **outbound webhooks** with the application's public key.

      - Applications encrypt **inbound request bodies** with the IDaaS public
      key.

      Algorithm: ECDH-ES+A256KW + A256GCM (JSON Web Encryption, RFC 7516).

      Use `GET /v1/keys/idaas` to fetch the IDaaS public key.

      Use `POST /v1/applications/keys/rotate` to rotate your application
      keypair.
  - name: Wallet
    description: View application escrow wallet balance and paginated ledger statement.
  - name: Subjects
    description: Manage the real-world entities (users / organisations) behind tags.
  - name: Tags
    description: Create, transfer, disable and resolve globally unique identity tags.
  - name: Claims
    description: Attach and revoke verifiable claims on tags.
  - name: Consent
    description: Issue and manage user consent tokens for claim federation.
  - name: Transactions
    description: Initiate, accept/reject, and query cross-application tag-to-tag payments.
  - name: Settlement
    description: Query end-of-day settlement batches and per-application net positions.
  - name: Webhooks
    description: >-
      Inspect outbound webhook delivery records for transactions. Each
      transaction has at most two webhook records: one RECEIVER (sent on
      initiation) and one SENDER (sent on acceptance/rejection/expiry).
externalDocs:
  description: IDaaS GitHub Repository
  url: https://github.com/reflexpay/idaas
paths:
  /v1/settlement/run:
    post:
      tags:
        - Settlement
      summary: Manually trigger a settlement run
      description: |
        Runs the end-of-day settlement for a specified date on demand.
        This is idempotent – if the date has already been successfully settled,
        the existing record is returned without reprocessing.

        **Use cases**:
        - Re-running a failed batch (e.g. after a database outage).
        - Settling a back-date after delayed transaction processing.
        - Smoke-testing the settlement pipeline in staging.

        The scheduled job automatically covers yesterday at 23:59 UTC;
        this endpoint is for operational override only.
      operationId: triggerSettlement
      parameters:
        - name: date
          in: query
          description: >-
            Date to settle (ISO-8601 format, e.g. 2025-03-03). Defaults to
            yesterday UTC if omitted.
          required: false
          schema:
            type: string
            format: date
      responses:
        '200':
          description: Settlement run completed (or already completed for this date)
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/ApiResponseSettlementRecordResponse'
        '400':
          description: Invalid date format
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/ApiResponseSettlementRecordResponse'
        '500':
          description: Settlement run failed – error details in response
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/ApiResponseSettlementRecordResponse'
components:
  schemas:
    ApiResponseSettlementRecordResponse:
      type: object
      properties:
        success:
          type: boolean
        message:
          type: string
        errorCode:
          type: string
        data:
          $ref: '#/components/schemas/SettlementRecordResponse'
        errors:
          type: array
          items:
            type: string
        timestamp:
          type: string
          format: date-time
    SettlementRecordResponse:
      type: object
      properties:
        id:
          type: string
          description: Unique settlement record ID
          format: uuid
        settlementDate:
          type: string
          description: Calendar date (UTC) covered by this settlement batch
          format: date
          example: '2025-03-03'
        currency:
          type: string
          description: ISO 4217 currency code
          example: NGN
        totalCredited:
          type: number
          description: Total amount credited across all applications on this date
          example: 250000
        totalDebited:
          type: number
          description: Total amount debited across all applications on this date
          example: 250000
        transactionCount:
          type: integer
          description: Total count of completed transactions included in this batch
          format: int32
        applicationCount:
          type: integer
          description: Number of application wallets included in this batch
          format: int32
        status:
          type: string
          description: Lifecycle status of this batch
          enum:
            - PENDING
            - COMPLETED
            - FAILED
        errorMessage:
          type: string
          description: Error message if the batch failed (null when COMPLETED)
        createdAt:
          type: string
          description: ISO-8601 creation timestamp
          format: date-time
        entries:
          type: array
          description: Per-application net position lines
          items:
            $ref: '#/components/schemas/SettlementEntryResponse'
      description: >-
        End-of-day settlement batch aggregating all completed transaction
        movements
    SettlementEntryResponse:
      type: object
      properties:
        id:
          type: string
          description: Unique entry ID
          format: uuid
        applicationId:
          type: string
          description: UUID of the application
          format: uuid
        applicationName:
          type: string
          description: Name of the application
          example: WalletApp
        walletId:
          type: string
          description: UUID of the application's escrow wallet
          format: uuid
        currency:
          type: string
          description: ISO 4217 currency code
          example: NGN
        totalCredited:
          type: number
          description: Total incoming accepted payments for the settlement period
          example: 150000
        totalDebited:
          type: number
          description: Total outgoing accepted payments for the settlement period
          example: 100000
        netAmount:
          type: number
          description: >-
            Net position (totalCredited − totalDebited). Positive = net
            creditor.
          example: 50000
        openingBalance:
          type: number
          description: Wallet balance at the start of the settlement date
        closingBalance:
          type: number
          description: Wallet balance at the end of the settlement date
        transactionCount:
          type: integer
          description: Number of completed transactions included in this entry
          format: int32
        createdAt:
          type: string
          description: ISO-8601 timestamp when this entry was created
          format: date-time
      description: Per-application net position within an end-of-day settlement batch
  securitySchemes:
    bearerAuth:
      type: http
      description: >
        Obtain a token from `POST /v1/auth/token` using your `client_id` and
        `client_secret`, then enter `Bearer <token>` here.
      scheme: bearer
      bearerFormat: JWT

````