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.

Open Cadence →

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 verticalHealthcare patient billing
GP API operations17
Live appgpx-cadence.pages.dev
StackVite, React, TypeScript, Tailwind; Hono on Cloudflare Pages Functions

Screens

ScreenWhat you doSDK calls
PatientsSearch 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 coveredpayers.getPayersList, .getPayer, .createPayer, .editPayer, paymentMethodsApi.createPaymentMethod, .listPaymentMethods, consents.createConsent, .getConsentsList, .cancelConsent, transactionsApi.getSaleAndRefundTransactions
Treatment planBuild 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 checkoutinstallments.getAvailableInstallmentPlans, links.createLink, payers.getPayersList, payers.getPayer
CollectionsSee 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 paymentstransactionsApi.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

CardBehaviour
4263 9700 0000 5262Saves and approves
5425 2300 0000 4415Saves and approves (Mastercard)
4000 0000 0000 0002Saves; the issuer declines its charges

GP API operations

OperationSDK methodUsed for
Create access tokenaccessToken.getAccessTokenNonce + SHA512 secret, cached
Create a payerpayers.createPayerRegister a patient
List payerspayers.getPayersListPatient search
Get a payerpayers.getPayerPatient profile
Edit a payerpayers.editPayerUpdate contact details
Create payment methodpaymentMethodsApi.createPaymentMethodStore a card on file
List payment methodspaymentMethodsApi.listPaymentMethodsCards on file
Create a consentconsents.createConsentRecord the patient's consent to store and charge the card
List consentsconsents.getConsentsListThe consent ledger
Cancel a consentconsents.cancelConsentWithdraw consent
Installment plansinstallments.getAvailableInstallmentPlansCompare installment options
Create a linklinks.createLinkPay-by-link for a treatment plan
List linkslinks.getListOfLinksLink status in Collections
Get a linklinks.getLinkOne link's status
Create sale or refundtransactionsApi.createSaleOrRefundTransactionScheduled merchant-initiated charge
List sales and refundstransactionsApi.getSaleAndRefundTransactionsCollections history
Refund a saletransactionsApi.createRefundTransactionFromSaleRefund when a plan changes

The flow: from a new patient to a scheduled charge

  1. Token. Cadence mints an access token with accessToken.getAccessToken.
  2. Patient. payers.createPayer registers the patient; payers.getPayer shows the profile.
  3. Card on file, with consent. paymentMethodsApi.createPaymentMethod stores the card, and consents.createConsent records the patient's explicit consent; consents.getConsentsList shows the ledger.
  4. Treatment plan. installments.getAvailableInstallmentPlans prices the plan's installment options.
  5. Pay-by-link. links.createLink creates a payment link for the plan; the phone-style preview shows what the patient receives, and links.getLink follows its status.
  6. Scheduled charges. On each due date, transactionsApi.createSaleOrRefundTransaction charges the stored card as a merchant-initiated transaction, only while the consent is active.
  7. Refund. If the plan changes, transactionsApi.createRefundTransactionFromSale refunds the charge; consents.cancelConsent stops 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());

Open Cadence → · All use cases

On this page