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.

Open Tideline →

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 verticalMerchant payments (hospitality, café)
GP API operations18
Live appgpx-tideline.pages.dev
StackVite, React 18, TypeScript, Tailwind; Hono on Cloudflare Pages Functions

Screens

ScreenWhat you doSDK calls
PulseToday's money flow (attempted → declined, voided, awaiting capture → captured → refunded), the approval rate, the week by card brand and the dispute inboxtransactionsApi.getSaleAndRefundTransactions, reports.getTransactionSummaryReport, disputesApi.getDisputes
Checkout LabTake 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 pathaccessToken.getAccessToken, paymentMethodsApi.createPaymentMethod, authenticationsApi.check3DsAvailability, .initiate3Ds, .get3DsResult, transactionsApi.createSaleOrRefundTransaction
LedgerCapture authorizations, refund (full or partial), void, and close the day's batchtransactionsApi.getSaleAndRefundTransactions, .getSingleSaleOrRefundTransaction, .captureSaleTransaction, .createRefundTransactionFromSale, .reverseTransaction, batches.closeBatch, batches.getSingleBatch
DisputesRead the reason, watch the deadline, pick evidence and challengedisputesApi.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

CardPath
4263 9700 0000 5262Frictionless 3DS, approved
4012 0010 3848 88843DS challenge (any 6 digits approve; Cancel fails it)
4012 0010 3714 11123DS fails, so the sale is not sent
4111 1111 1111 1111Not enrolled, sale without 3DS
4000 0000 0000 0002Declined by the issuer (HTTP 200, status DECLINED)

GP API operations

OperationSDK methodUsed for
Create access tokenaccessToken.getAccessTokenNonce + SHA512 secret, cached, refreshed a minute before expiry
Create payment methodpaymentMethodsApi.createPaymentMethodTokenize the card
List payment methodspaymentMethodsApi.listPaymentMethodsFind a token by reference after a lost answer
Check 3DS availabilityauthenticationsApi.check3DsAvailabilityIs the card enrolled?
Initiate 3DSauthenticationsApi.initiate3DsFrictionless or challenge
Get 3DS resultauthenticationsApi.get3DsResultRe-read on the server before every sale
Create sale or refundtransactionsApi.createSaleOrRefundTransactionCharge now or authorize only
List sales and refundstransactionsApi.getSaleAndRefundTransactionsPulse, Ledger, lookups by reference
Get a sale or refundtransactionsApi.getSingleSaleOrRefundTransactionSale detail before capture, refund or void
Capture a saletransactionsApi.captureSaleTransactionCapture an authorization, once
Refund a saletransactionsApi.createRefundTransactionFromSaleFull or partial refund
Reverse a transactiontransactionsApi.reverseTransactionVoid in an open batch
Close batchbatches.closeBatchClose the day
Get a batchbatches.getSingleBatchThe day's batch totals
Transaction summary reportreports.getTransactionSummaryReportThe week by card brand
List disputesdisputesApi.getDisputesDispute inbox
Get a disputedisputesApi.getSingleDisputeReason and deadline
Challenge a disputedisputesApi.challengeDisputeSubmit evidence

The flow: a 3-D Secure checkout

  1. 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.
  2. Tokenize. paymentMethodsApi.createPaymentMethod sends the card to GP once; Tideline keeps only the PMT_… token.
  3. Check 3DS. authenticationsApi.check3DsAvailability with the token, amount and currency tells whether the card is enrolled.
  4. Initiate 3DS. authenticationsApi.initiate3Ds with the browser data returns either a frictionless result or CHALLENGE_REQUIRED with the issuer's challenge URL.
  5. Result. authenticationsApi.get3DsResult returns the authentication status, ECI and liability shift.
  6. Sale. The server re-reads the 3DS result, refuses the sale if it did not pass or the amount changed, then calls transactionsApi.createSaleOrRefundTransaction with the authentication id, a reference and an X-GP-Idempotency key.
  7. Later. The sale is captured, refunded or voided on the Ledger, settled with batches.closeBatch, and defended with disputesApi.challengeDispute if disputed.

Rules Tideline enforces before calling GP

RuleWhere
Capture only an authorized sale, and only onceserver/ledger.ts capture()
Refund at most what was captured minus what is already refundedserver/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 deadlineserver/disputes.ts challenge()
Every write sends a reference and X-GP-Idempotency derived from the intentall 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 });
}

Open Tideline → · All use cases

On this page