PayFanout API reference
    Preparing search index...

    Interface CompletionHandlerOptions

    interface CompletionHandlerOptions {
        log?: (message: string) => void;
        onCompleted?: (
            info: PaymentInfo,
            ctx: CompletionHandlerContext,
        ) => void | Promise<void>;
        resolveSession: (
            sessionRef: string,
            request: Request,
        ) => ResolvedCompletionSession | Promise<ResolvedCompletionSession>;
    }
    Index
    log?: (message: string) => void

    Observability hook; exceptions it throws are swallowed.

    onCompleted?: (
        info: PaymentInfo,
        ctx: CompletionHandlerContext,
    ) => void | Promise<void>

    Runs after a successful completion, before the response is sent — persist status, link pspPaymentId to your domain record. The payment has already completed at the PSP; a throw here becomes a 500 so the host notices and reconciles (keep it lightweight and reliable).

    resolveSession: (
        sessionRef: string,
        request: Request,
    ) => ResolvedCompletionSession | Promise<ResolvedCompletionSession>

    Maps the opaque reference the client sent (the session token / clientSecret itself) to the tenant-scoped PaymentService + session. Read the request's headers/URL here for tenant scoping — the body is already parsed and must not be read again. Throw a PayFanoutError to reject (e.g. invalidRequest for an unknown reference, session_expired for a stale one); it is mapped to the matching HTTP status.