@cfxlabsinc/b2b-services
    Preparing search index...

    Reconciles a pending redemption against a posted bank transaction: validates amounts, commits the redemption workflow, and records the reconciliation on the bank transaction.

    Lives in withdrawal-services (not redemption-services) because the logic requires BankTransactionService, and a direct dependency from redemption-services onto bank-transaction-services would close a package cycle via virtual-account-services.

    Index

    Constructors

    Methods

    • Parameters

      • args: { bankTransactionId: string; redemptionId: string }

      Returns Promise<
          | { ok: true; value: void }
          | {
              error:
                  | ServiceError<"REDEMPTION_NOT_FOUND", { redemptionId: string }>
                  | ServiceError<"REDEMPTION_NOT_PENDING", { redemptionId: string }>
                  | ServiceError<"INVALID_BANK_TX", { bankTransactionId: string }>
                  | ServiceError<
                      "AMOUNT_MISMATCH",
                      { bankTransactionAmount: string; redemptionAmount: string },
                  >;
              ok: false;
          },
      >

    • Commits the per-withdrawal redemptions of a Metcap ACH-credit batch against its single settlement bank debit.

      Callers pass the complete filed set — every redemption for the batch's withdrawals, any status. Metcap debits the batch gross, so the amount check sums the whole set: a redemption VOIDED by an in-window return still counts toward the sum (its return posts as a separate out-and-back credit) but is never committed. COMMITTED rows from a prior partial run stay in the sum too, so retries converge; only the still-PENDING subset is (re)committed. The reconciliation record (REDEMPTION_IDS / WITHDRAWAL_IDS) is written last and covers the whole filed set — so a retry after an all-committed-but-unrecorded run still converges.

      Commits run sequentially: every redemption debits the same pending ledger account, so we avoid concurrent on-chain movements from one source.

      Parameters

      • args: {
            bankTransactionId: string;
            redemptions: SettlementRedemption[];
            withdrawalIds: string[];
        }

      Returns Promise<
          | { ok: true; value: void }
          | {
              error:
                  | ServiceError<"INVALID_BANK_TX", { bankTransactionId: string }>
                  | ServiceError<
                      "AMOUNT_MISMATCH",
                      { bankTransactionAmount: string; redemptionAmount: string },
                  >;
              ok: false;
          },
      >