Tideline: café payments
A payments console for Copperline, a three-café chain, on GP API. 3-D Secure checkout, capture, refund and void, batch close, and dispute defence, with every typed SDK call in the Wire drawer.
The story
Copperline is a fictional chain of three cafés. Its operations lead needs one console to take a card payment, manage it through its life, settle the day and defend it if a customer disputes it. Tideline does that on GP API, through the TypeScript SDK that APIMatic generated from GP's own OpenAPI files, and shows every GP API call as it happens.
The Sandbox holds seven days of fictional trading: 3 cafés, about 400 transactions and 6 disputes.
| At a glance | |
|---|---|
| Global Payments vertical | Merchant payments (hospitality, café) |
| GP API operations | 18 |
| Live app | gpx-tideline.pages.dev |
| Stack | Vite, React 18, TypeScript, Tailwind; Hono on Cloudflare Pages Functions |
Screens
| Screen | What you do | SDK calls |
|---|---|---|
| Pulse | Today's money flow (attempted → declined, voided, awaiting capture → captured → refunded), the approval rate, the week by card brand and the dispute inbox | transactionsApi.getSaleAndRefundTransactions, reports.getTransactionSummaryReport, disputesApi.getDisputes |
| Checkout Lab | Take a card-not-present payment. A sequence diagram draws each call: token, tokenize, 3DS check, frictionless or challenge, result, sale. Test-card chips force each path | accessToken.getAccessToken, paymentMethodsApi.createPaymentMethod, authenticationsApi.check3DsAvailability, .initiate3Ds, .get3DsResult, transactionsApi.createSaleOrRefundTransaction |
| Ledger | Capture authorizations, refund (full or partial), void, and close the day's batch | transactionsApi.getSaleAndRefundTransactions, .getSingleSaleOrRefundTransaction, .captureSaleTransaction, .createRefundTransactionFromSale, .reverseTransaction, batches.closeBatch, batches.getSingleBatch |
| Disputes | Read the reason, watch the deadline, pick evidence and challenge | disputesApi.getDisputes, .getSingleDispute, .challengeDispute |
The Wire drawer (bottom of every screen, or press the backtick key) shows each typed SDK call, every HTTP attempt with its headers (X-GP-Version, X-GP-Idempotency, a masked bearer token), the request and response bodies with card numbers masked, timing, retries and how any error was translated. Two switches break the next request on purpose: GP rate-limits the next read (429 with Retry-After, retried once by the SDK) and Access token expires (401, Tideline mints a new token and retries once).
Test cards
| Card | Path |
|---|---|
| 4263 9700 0000 5262 | Frictionless 3DS, approved |
| 4012 0010 3848 8884 | 3DS challenge (any 6 digits approve; Cancel fails it) |
| 4012 0010 3714 1112 | 3DS fails, so the sale is not sent |
| 4111 1111 1111 1111 | Not enrolled, sale without 3DS |
| 4000 0000 0000 0002 | Declined by the issuer (HTTP 200, status DECLINED) |
GP API operations
| Operation | SDK method | Used for |
|---|---|---|
| Create access token | accessToken.getAccessToken | Nonce + SHA512 secret, cached, refreshed a minute before expiry |
| Create payment method | paymentMethodsApi.createPaymentMethod | Tokenize the card |
| List payment methods | paymentMethodsApi.listPaymentMethods | Find a token by reference after a lost answer |
| Check 3DS availability | authenticationsApi.check3DsAvailability | Is the card enrolled? |
| Initiate 3DS | authenticationsApi.initiate3Ds | Frictionless or challenge |
| Get 3DS result | authenticationsApi.get3DsResult | Re-read on the server before every sale |
| Create sale or refund | transactionsApi.createSaleOrRefundTransaction | Charge now or authorize only |
| List sales and refunds | transactionsApi.getSaleAndRefundTransactions | Pulse, Ledger, lookups by reference |
| Get a sale or refund | transactionsApi.getSingleSaleOrRefundTransaction | Sale detail before capture, refund or void |
| Capture a sale | transactionsApi.captureSaleTransaction | Capture an authorization, once |
| Refund a sale | transactionsApi.createRefundTransactionFromSale | Full or partial refund |
| Reverse a transaction | transactionsApi.reverseTransaction | Void in an open batch |
| Close batch | batches.closeBatch | Close the day |
| Get a batch | batches.getSingleBatch | The day's batch totals |
| Transaction summary report | reports.getTransactionSummaryReport | The week by card brand |
| List disputes | disputesApi.getDisputes | Dispute inbox |
| Get a dispute | disputesApi.getSingleDispute | Reason and deadline |
| Challenge a dispute | disputesApi.challengeDispute | Submit evidence |
The flow: a 3-D Secure checkout
- Token. Tideline mints an access token with
accessToken.getAccessToken(a fresh nonce,secret = SHA512(nonce + app key)) and caches it; the SDK asks the cache on every attempt. - Tokenize.
paymentMethodsApi.createPaymentMethodsends the card to GP once; Tideline keeps only thePMT_…token. - Check 3DS.
authenticationsApi.check3DsAvailabilitywith the token, amount and currency tells whether the card is enrolled. - Initiate 3DS.
authenticationsApi.initiate3Dswith the browser data returns either a frictionless result orCHALLENGE_REQUIREDwith the issuer's challenge URL. - Result.
authenticationsApi.get3DsResultreturns the authentication status, ECI and liability shift. - Sale. The server re-reads the 3DS result, refuses the sale if it did not pass or the amount changed, then calls
transactionsApi.createSaleOrRefundTransactionwith the authentication id, a reference and anX-GP-Idempotencykey. - Later. The sale is captured, refunded or voided on the Ledger, settled with
batches.closeBatch, and defended withdisputesApi.challengeDisputeif disputed.
Rules Tideline enforces before calling GP
| Rule | Where |
|---|---|
| Capture only an authorized sale, and only once | server/ledger.ts capture() |
| Refund at most what was captured minus what is already refunded | server/ledger.ts refund() |
| No sale without a passing 3DS result for the same amount when the card is enrolled (re-read on the server) | server/checkout.ts sale() |
| Challenge a dispute only while it is with the merchant and before its deadline | server/disputes.ts challenge() |
Every write sends a reference and X-GP-Idempotency derived from the intent | all write routes |
| A write whose answer is lost is re-read by its reference before Tideline answers "unknown" | each write's catch |
The prompt
This is the prompt given to Claude Code, with the Context Plugin installed, to build Tideline:
Build Tideline, a payments console for our café chain (Copperline, three cafés) 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: GP blue on calm paper, and a real dark mode.
- Checkout: tokenize a card, check 3-D Secure, run frictionless or a challenge, read the result, then sell (charge now or authorize only).
- Ledger: today's sales with their lifecycle; capture, full or partial refund, void; close the day's batch.
- Pulse: today's money flow, approval rate, the week by card brand. Disputes: deadlines, reason, evidence, challenge.
- A drawer that shows every GP API call: the typed SDK call, the request and response, timing and retries.
- GP app id and key go in .dev.vars. With none, run on built-in Sandbox data through the same SDK.
Must get right:
- The access token: nonce + SHA512 secret, cached, refreshed once on a 401. The sandbox host is chosen explicitly.
- Never capture twice, never refund more than was captured, never sell without a passing 3DS result, and every write carries an idempotency key.
- Show GP's own reason on a refusal, its Retry-After on a rate limit, and a decline as a decline.
Done when: it builds cleanly, the tests pass, and a README explains how to set it up.Code: the typed SDK
The client, from server/gp/client.ts: one GlobalPaymentsApiClient per isolate, with the Sandbox host chosen explicitly and the token cache as the bearer provider.
import { GlobalPaymentsApiClient, ServerEnvironment } from "global-payments-api";
import type { ClientOptions } from "global-payments-api";
const options: ClientOptions = {
// Host chosen explicitly: a client with no options talks to production.
serverEnvironment: ServerEnvironment.Environment2, // https://apis.sandbox.globalpay.com/ucp
// The token cache is the bearer provider. The SDK asks it on every attempt.
bearerAuth: (signal) => tokens.get(signal),
// GETs retry once (429/5xx, honouring Retry-After). POSTs are never re-sent.
retry: { maxRetries: 1, timeout: 15_000, delay: 500 },
// Off: createPaymentMethod carries the card number, so no request body is logged.
logging: { level: "off", logRequestBody: false },
// The one transport seam: tests and the Wire recorder plug in here.
fetch: tap((req) => fetch(req)),
};
const client = new GlobalPaymentsApiClient(options);The sale, from server/checkout.ts: a typed request with the 3DS authentication attached, and a lost answer settled by looking the sale up by its reference.
const reference = `CPL-${input.storeId}-${input.ticket}`;
const req = {
xGpIdempotency: `tl:sale:${input.storeId}-${input.ticket}`,
body: {
accountName: accountName(env),
channel: "CNP" as const,
country: "US",
captureMode: input.capture,
amount,
currency: "USD",
reference,
paymentMethod: {
id: input.paymentMethodId,
entryMode: "ECOM" as const,
...(enrolled ? { authentication: { id: input.authId } } : {}),
},
},
};
try {
const res = await g.call("transactionsApi.createSaleOrRefundTransaction", req,
(c) => c.transactionsApi.createSaleOrRefundTransaction(req));
return { txn: toTxn(res), declined: res.status === "DECLINED" };
} catch (err) {
if (isUnknownOutcome(err)) {
// No answer: search by the reference we sent before saying "unknown".
const found = await g.call("transactionsApi.getSaleAndRefundTransactions", { reference, type: "SALE" },
(c) => c.transactionsApi.getSaleAndRefundTransactions({ reference, type: "SALE" }))
.then((r) => r.transactions?.find((t) => t.reference === reference));
if (found) return { txn: toTxn(found), declined: found.status === "DECLINED" };
}
throw translate(err, { write: true });
}Use cases
Four sample apps built on GP API with the Global Payments Context Plugin and the typed TypeScript SDK, one per Global Payments vertical.
Assembly: embedded payments for platforms
Fieldhouse, a booking-software platform, boards independent fitness studios as sub-merchants on GP API, takes payments on their behalf, splits each payment, holds risky funds and pays studios out.