Tally: settlement and reconciliation

Alder Hotels' finance team matches deposits to batches to transactions on GP API, reads interchange and fees, accepts or challenges disputes, and keeps an audit trail.

Open Tally →

The story

Alder Hotels is a fictional four-hotel group. At month end its finance team has to prove that every deposit in the bank matches the batches and transactions behind it, understand what interchange and fees cost, work the open disputes, and show an auditor who did what. Tally is that close, on GP API settlement reporting, through the typed TypeScript SDK.

At a glance
Global Payments verticalSettlement and reconciliation (hospitality finance)
GP API operations16
Live appgpx-tally.pages.dev
StackVite, React, TypeScript, Tailwind; Hono on Cloudflare Pages Functions

Screens

ScreenWhat you doSDK calls
Close30 days of deposits for four hotels, each tied out to its batches and fees. Open a deposit to see the waterfall from sales to the bank, the batch match, every settled transaction with its interchange, scheme and processing fees, and the dispute adjustments. Open a batch to see which folios landed in which depositsettlementReporting.getDepositList, .getDepositSingle, .getSettledTransactions, .getSettledDisputes, batches.getSingleBatch, .getTransactionsWithinBatch
FeesMonthly fees split into interchange, scheme, GP processing, device rental and chargeback fees, the effective rate per month and per hotel, and the card mixsettlementReporting.getMonthlyFeeReportList, reports.getTransactionSummaryReport
DisputesA queue sorted by deadline. Accept a chargeback, or challenge it with evidence, then read the evidence backdisputesApi.getDisputes, .getSingleDispute, .acceptDispute, .challengeDispute, .getDisputeDocument, settlementReporting.getSettledDisputes
AuditGP's own action log as a timeline: batch closes by the PMS night audit, deposit reads, dispute decisions, refusalsactions.getActionList, .getActionSingle

The two variances to investigate

The books reconcile to the cent, except for two deliberate, explained variances:

  1. Timing. The last folio of Alder Harbourside's batch nine nights ago was presented after the 23:30 funding cut-off. That night's deposit is short by the folio; the next morning's deposit is long by the same amount.
  2. Unitemised fee. Alder City Quarter's deposit on the 1st carries a $45.00 device rental (three terminals) on top of the per-transaction fees. The monthly fee report shows it as device rental.

The Wire drawer (bottom of every screen, or press the backtick key) shows every typed SDK call a screen made, each HTTP attempt with headers, request and response bodies, timing, retries and error translation. Its switches rate-limit the next read or expire the access token, to show the SDK's retry and Tally's token refresh.

GP API operations

OperationSDK methodUsed for
Create access tokenaccessToken.getAccessTokenNonce + SHA512 secret, cached
List depositssettlementReporting.getDepositListThe month's deposits
Get a depositsettlementReporting.getDepositSingleOne deposit's totals
Settled transactionssettlementReporting.getSettledTransactionsTransactions in a deposit
Get a batchbatches.getSingleBatchBatch totals
Transactions in a batchbatches.getTransactionsWithinBatchBatch drill-down
Monthly fee reportsettlementReporting.getMonthlyFeeReportListInterchange and fees
Transaction summary reportreports.getTransactionSummaryReportVolume for the effective rate
Settled disputessettlementReporting.getSettledDisputesDisputes that hit a deposit
List disputesdisputesApi.getDisputesOpen disputes
Get a disputedisputesApi.getSingleDisputeReason, amount and deadline
Accept a disputedisputesApi.acceptDisputeAccept the liability
Challenge a disputedisputesApi.challengeDisputeSubmit documents
Get a dispute documentdisputesApi.getDisputeDocumentRead a submitted document
List actionsactions.getActionListThe audit timeline
Get an actionactions.getActionSingleOne action's detail

The flow: closing the month

  1. Token. Tally mints an access token with accessToken.getAccessToken.
  2. Deposits. settlementReporting.getDepositList lists the month's deposits; settlementReporting.getDepositSingle gives one deposit's totals.
  3. Batches. For each batch in the deposit, batches.getSingleBatch gives its totals and batches.getTransactionsWithinBatch its transactions.
  4. Match. settlementReporting.getSettledTransactions lists what settled; Tally matches deposit to batches to transactions and draws the variance waterfall (fees, refunds, disputes, adjustments).
  5. Fees. settlementReporting.getMonthlyFeeReportList breaks down interchange and fees; with the volume from reports.getTransactionSummaryReport it gives the effective rate.
  6. Disputes. disputesApi.getDisputes and disputesApi.getSingleDispute show each case; the team accepts with disputesApi.acceptDispute or challenges with documents via disputesApi.challengeDispute, and settlementReporting.getSettledDisputes shows the ones already in a deposit.
  7. Audit. actions.getActionList and actions.getActionSingle show who did what, and when.

The prompt

Build Tally, the month-end close console for Alder Hotels' finance team, on Global Payments' GP API.

First, install the Global Payments Context Plugin and use it for all GP API code:
npx context-plugins install https://gpx-apimatic-poc.pages.dev/__downloads/plugin.zip

What to build:
- React, TypeScript and Tailwind, with a Hono API on Cloudflare Pages. GP's look, with a real dark mode.
- Close: drill down from a deposit to its batches to their transactions, with a match and variance waterfall.
- Fees: the monthly fee breakdown and the effective rate.
- Disputes: read each one, accept it or challenge it with documents. Audit: a timeline of actions on the account.
- A drawer that shows every GP API call: the typed SDK call, the request and response, timing and retries.

Must get right:
- The access token: nonce + SHA512 secret, cached, refreshed once on a 401. The sandbox host is chosen explicitly.
- Amounts are minor units as strings: never lose a cent in the match, and show the variance rather than hide it.
- Accept or challenge a dispute only while it is open and before its deadline; every write carries an
  idempotency key.

Done when: it builds cleanly, the tests pass, and a README explains how to set it up.

Code: the typed SDK

From server/tally.ts. Opening a deposit for the close: the deposit, its settled transactions and its settled disputes are read in parallel, then each batch behind it, so Tally can match deposit to batches to transactions and draw the variance waterfall.

export async function depositDetail(env: Env, id: string): Promise<DepositDetail> {
  if (!/^DEP_[A-Za-z0-9_]{4,40}$/.test(id)) throw new HttpError(400, "That is not a GP deposit id.");
  return run(async () => {
    const g = gp(env);
    const dreq = { id };
    const sreq = { accountName: accountName(env), depositId: id, pageSize: 50 };
    const [d, mine, sd] = await Promise.all([
      g.call("settlementReporting.getDepositSingle", dreq, (c) => c.settlementReporting.getDepositSingle(dreq)),
      settled(env, { depositId: id }), // settlementReporting.getSettledTransactions
      g.call("settlementReporting.getSettledDisputes", sreq, (c) => c.settlementReporting.getSettledDisputes(sreq)),
    ]);
    const home = homeBatch(id);
    const ids = [...new Set([home, ...mine.map((t) => t.batchId)])].filter(Boolean);
    const batches = await Promise.all(ids.map(async (bid) => {
      const b = await g.call("batches.getSingleBatch", { id: bid }, (c) => c.batches.getSingleBatch({ id: bid }));
      return { id: bid, status: b.status ?? "", amount: minor(b.amount), count: b.batchTransactionCount ?? 0 };
    }));
    const match = matchBatches(batches, mine);
    const row = depositRow(d as GpDeposit, mine, /* batch split */ match.map((b) => ({ id: b.id, home: b.id === home, here: b.inDeposit, elsewhere: b.elsewhere })));
    return { ...row, waterfall: waterfall(row, row.itemisedFees), batchesMatch: match /* … */ };
  });
}

Open Tally → · All use cases

On this page