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.
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 vertical | Settlement and reconciliation (hospitality finance) |
| GP API operations | 16 |
| Live app | gpx-tally.pages.dev |
| Stack | Vite, React, TypeScript, Tailwind; Hono on Cloudflare Pages Functions |
Screens
| Screen | What you do | SDK calls |
|---|---|---|
| Close | 30 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 deposit | settlementReporting.getDepositList, .getDepositSingle, .getSettledTransactions, .getSettledDisputes, batches.getSingleBatch, .getTransactionsWithinBatch |
| Fees | Monthly fees split into interchange, scheme, GP processing, device rental and chargeback fees, the effective rate per month and per hotel, and the card mix | settlementReporting.getMonthlyFeeReportList, reports.getTransactionSummaryReport |
| Disputes | A queue sorted by deadline. Accept a chargeback, or challenge it with evidence, then read the evidence back | disputesApi.getDisputes, .getSingleDispute, .acceptDispute, .challengeDispute, .getDisputeDocument, settlementReporting.getSettledDisputes |
| Audit | GP's own action log as a timeline: batch closes by the PMS night audit, deposit reads, dispute decisions, refusals | actions.getActionList, .getActionSingle |
The two variances to investigate
The books reconcile to the cent, except for two deliberate, explained variances:
- 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.
- 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
| Operation | SDK method | Used for |
|---|---|---|
| Create access token | accessToken.getAccessToken | Nonce + SHA512 secret, cached |
| List deposits | settlementReporting.getDepositList | The month's deposits |
| Get a deposit | settlementReporting.getDepositSingle | One deposit's totals |
| Settled transactions | settlementReporting.getSettledTransactions | Transactions in a deposit |
| Get a batch | batches.getSingleBatch | Batch totals |
| Transactions in a batch | batches.getTransactionsWithinBatch | Batch drill-down |
| Monthly fee report | settlementReporting.getMonthlyFeeReportList | Interchange and fees |
| Transaction summary report | reports.getTransactionSummaryReport | Volume for the effective rate |
| Settled disputes | settlementReporting.getSettledDisputes | Disputes that hit a deposit |
| List disputes | disputesApi.getDisputes | Open disputes |
| Get a dispute | disputesApi.getSingleDispute | Reason, amount and deadline |
| Accept a dispute | disputesApi.acceptDispute | Accept the liability |
| Challenge a dispute | disputesApi.challengeDispute | Submit documents |
| Get a dispute document | disputesApi.getDisputeDocument | Read a submitted document |
| List actions | actions.getActionList | The audit timeline |
| Get an action | actions.getActionSingle | One action's detail |
The flow: closing the month
- Token. Tally mints an access token with
accessToken.getAccessToken. - Deposits.
settlementReporting.getDepositListlists the month's deposits;settlementReporting.getDepositSinglegives one deposit's totals. - Batches. For each batch in the deposit,
batches.getSingleBatchgives its totals andbatches.getTransactionsWithinBatchits transactions. - Match.
settlementReporting.getSettledTransactionslists what settled; Tally matches deposit to batches to transactions and draws the variance waterfall (fees, refunds, disputes, adjustments). - Fees.
settlementReporting.getMonthlyFeeReportListbreaks down interchange and fees; with the volume fromreports.getTransactionSummaryReportit gives the effective rate. - Disputes.
disputesApi.getDisputesanddisputesApi.getSingleDisputeshow each case; the team accepts withdisputesApi.acceptDisputeor challenges with documents viadisputesApi.challengeDispute, andsettlementReporting.getSettledDisputesshows the ones already in a deposit. - Audit.
actions.getActionListandactions.getActionSingleshow 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 /* … */ };
});
}