satim-module - v1.0.0
    Preparing search index...

    Class WebhookHandler

    Zero-trust webhook handler.

    Construct via satim.createWebhookHandler(options); do not instantiate directly (the satim reference is required).

    The per-orderId in-flight lock serialises concurrent invocations for the same orderId; different orderIds run in parallel.

    Index

    Constructors

    Methods

    Constructors

    Methods

    • Verify a webhook callback by re-fetching authoritative state.

      Flow (each step short-circuits with null on failure):

      1. Extract orderId from source via extractOrderId.
      2. Apply rate limit.
      3. Acquire per-orderId in-flight lock.
      4. Run onCheckDuplicate(orderId).
      5. Run onResolveAmount(orderId). Unknown order → null (no gateway call).
      6. satim.confirm(orderId, expectedAmount)verifyAmount runs automatically on success.
      7. onMarkProcessed(orderId) if the response is not pending.
      8. Release lock in finally.

      Postcondition: returns a WebhookResult on success (including duplicate detection), or null when input is invalid, rate limited, or the order is unknown.

      Complexity: dominated by the gateway round trip in step 6 (O(network)). All other steps are O(1) or O(log n) (rate limiter).

      Parameters

      • source: unknown

      Returns Promise<WebhookResult | null>

      Anything satim.confirm() can throw — primarily SatimUnexpectedResponseError on transport failures or amount mismatch. Callers should wrap the call and respond with HTTP 500 on unexpected throws.