Cadence: patient billing for healthcare
Northgate Dental Group keeps patients as payers on GP API, stores cards on file with explicit consent, sends pay-by-link invoices for treatment plans, offers installments, runs scheduled charges and refunds.
The story
Northgate Dental Group is a fictional three-clinic dental practice. Its billing team keeps each patient as a payer, stores a card on file only with the patient's explicit consent, prices treatment plans with installment options, sends a pay-by-link invoice the patient can pay from a phone, runs scheduled merchant-initiated charges against the stored card, and refunds when a plan changes. Cadence does that on GP API, through the typed TypeScript SDK.
| At a glance | |
|---|---|
| Global Payments vertical | Healthcare patient billing |
| GP API operations | 17 |
| Live app | gpx-cadence.pages.dev |
| Stack | Vite, React, TypeScript, Tailwind; Hono on Cloudflare Pages Functions |
Screens
| Screen | What you do | SDK calls |
|---|---|---|
| Patients | Search 40 patients across 3 clinics, add or edit a payer, save a card with consent, withdraw consent, and read the patient's consent ledger: every permission and every charge it covered | payers.getPayersList, .getPayer, .createPayer, .editPayer, paymentMethodsApi.createPaymentMethod, .listPaymentMethods, consents.createConsent, .getConsentsList, .cancelConsent, transactionsApi.getSaleAndRefundTransactions |
| Treatment plan | Build a plan from procedures, price it, compare pay-in-full with 3, 6, 12 and 24-month Visa Installments, and send a pay-by-link by text or email with a phone preview of the message and the hosted checkout | installments.getAvailableInstallmentPlans, links.createLink, payers.getPayersList, payers.getPayer |
| Collections | See the collections rhythm (six weeks back, six ahead), collect due installments on the stored card under consent, retry declines, track pay-by-links and refund payments | transactionsApi.createSaleOrRefundTransaction, .getSaleAndRefundTransactions, .createRefundTransactionFromSale, consents.getConsentsList, paymentMethodsApi.listPaymentMethods, links.getListOfLinks, links.getLink |
The Wire drawer (bottom of every screen, or press the backtick key) shows every typed SDK call a screen made, each HTTP attempt with its headers (masked bearer, X-GP-Version, X-GP-Idempotency), request and response bodies (card numbers masked), timing, retries and how an error was translated. Two switches break the next request on purpose: a 429 rate limit and an expired token.
What a visitor creates (patients, cards, consents, links, charges, refunds) is kept per browser session, so visitors never see each other's changes.
Test cards
| Card | Behaviour |
|---|---|
| 4263 9700 0000 5262 | Saves and approves |
| 5425 2300 0000 4415 | Saves and approves (Mastercard) |
| 4000 0000 0000 0002 | Saves; the issuer declines its charges |
GP API operations
| Operation | SDK method | Used for |
|---|---|---|
| Create access token | accessToken.getAccessToken | Nonce + SHA512 secret, cached |
| Create a payer | payers.createPayer | Register a patient |
| List payers | payers.getPayersList | Patient search |
| Get a payer | payers.getPayer | Patient profile |
| Edit a payer | payers.editPayer | Update contact details |
| Create payment method | paymentMethodsApi.createPaymentMethod | Store a card on file |
| List payment methods | paymentMethodsApi.listPaymentMethods | Cards on file |
| Create a consent | consents.createConsent | Record the patient's consent to store and charge the card |
| List consents | consents.getConsentsList | The consent ledger |
| Cancel a consent | consents.cancelConsent | Withdraw consent |
| Installment plans | installments.getAvailableInstallmentPlans | Compare installment options |
| Create a link | links.createLink | Pay-by-link for a treatment plan |
| List links | links.getListOfLinks | Link status in Collections |
| Get a link | links.getLink | One link's status |
| Create sale or refund | transactionsApi.createSaleOrRefundTransaction | Scheduled merchant-initiated charge |
| List sales and refunds | transactionsApi.getSaleAndRefundTransactions | Collections history |
| Refund a sale | transactionsApi.createRefundTransactionFromSale | Refund when a plan changes |
The flow: from a new patient to a scheduled charge
- Token. Cadence mints an access token with
accessToken.getAccessToken. - Patient.
payers.createPayerregisters the patient;payers.getPayershows the profile. - Card on file, with consent.
paymentMethodsApi.createPaymentMethodstores the card, andconsents.createConsentrecords the patient's explicit consent;consents.getConsentsListshows the ledger. - Treatment plan.
installments.getAvailableInstallmentPlansprices the plan's installment options. - Pay-by-link.
links.createLinkcreates a payment link for the plan; the phone-style preview shows what the patient receives, andlinks.getLinkfollows its status. - Scheduled charges. On each due date,
transactionsApi.createSaleOrRefundTransactioncharges the stored card as a merchant-initiated transaction, only while the consent is active. - Refund. If the plan changes,
transactionsApi.createRefundTransactionFromSalerefunds the charge;consents.cancelConsentstops future charges.
The prompt
Build Cadence, the patient billing console for Northgate Dental Group, 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.
- Patients: each patient is a GP payer, with cards on file and a consent ledger (store a card only with consent).
- Treatment plan: price a plan, compare installment options, send a pay-by-link with a phone-style preview.
- Collections: scheduled merchant-initiated charges on stored cards, the status of every link, refunds.
- 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.
- Never charge a stored card without an active consent, never refund more than was charged, and every write
carries an idempotency key.
- Show GP's own reason on a refusal, 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
From server/billing.ts. A scheduled installment is a merchant-initiated charge on the stored card. Before calling GP, Cadence checks that the installment was not already collected and that the patient has an active consent covering the amount; the charge then carries the consent id and the stored-credential model.
// a merchant-initiated charge needs the patient's ACTIVE consent, for at least this amount
const consent = consents.find((c) => c.status === "ACTIVE");
if (!consent) {
const msg = "This patient has no active consent for stored-card charges. Send a pay-by-link instead, or record consent first.";
guard(call, { reference, amount: String(amount) }, msg);
throw new HttpError(422, msg, { outcome: "not_sent", code: "NO_CONSENT" });
}
const req = {
xGpIdempotency: `cd:ins:${input.intentId}`,
body: {
accountName: accountName(env), channel: "CNP" as const, country: "US", captureMode: "AUTO" as const,
amount: String(amount), currency: "USD" as const, reference,
description: `${plan.treatment}: installment ${input.k} of ${plan.count}`,
checkForDuplicate: "YES" as const, merchantCategoryCode: "8021",
initiator: "MERCHANT" as const,
storedCredential: {
model: "INSTALLMENT" as const,
sequence: input.k === plan.count ? ("LAST" as const) : ("SUBSEQUENT" as const),
contractReference: plan.id,
},
paymentMethod: { id: card.id, entryMode: "ECOM" as const, consent: { id: consent.id } },
},
};
const res = await g.call(call, req, (c) => c.transactionsApi.createSaleOrRefundTransaction(req));
if (res.status === "DECLINED") note(`Declined by the issuer: ${res.paymentMethod?.result ?? ""} ${res.paymentMethod?.message ?? ""}`.trim());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.
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.