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.

Open Assembly →

The story

Fieldhouse is a fictional booking-software platform for independent fitness studios. It acts as an ISV / PayFac: it boards each studio as a sub-merchant, takes class and membership payments on the studio's behalf, splits every payment between the studio and Fieldhouse's platform fee, holds funds when a payment looks risky, and pays studios out. Assembly is the platform operator's console for all of that on GP API, through the typed TypeScript SDK.

At a glance
Global Payments verticalEmbedded payments for platforms (ISV / PayFac)
GP API operations18
Live appgpx-assembly.pages.dev
StackVite, React, TypeScript, Tailwind; Hono on Cloudflare Pages Functions

Screens

ScreenWhat you doSDK calls
OnboardingSee every studio in a boarding pipeline, open one to read its boarding timeline and what GP holds on file, board a new studio (address lookup, business, owner), edit or resubmit details, upload a verification document and watch GP verify itmerchants.getMerchants, .getMerchantSingle, .addressLookup, .boardMerchant, .editMerchant, accounts.getMerchantAccounts, fileProcessing.createUrl, .uploadFile, .getFileDetails
Payments & splitsCharge a booking for a studio with a sandbox test card, set the platform fee, and see the split drawn as money flowing to the studio and to Fieldhouse. Reverse all or part of any splittransactionsApi.createSaleOrRefundTransaction, .splitTransaction, transfers.listTransfers, .reverseExistingSplit
Risk holdsFieldhouse's own rules score last week's bookings; hold a payment so it does not fund, or release ittransactionsApi.holdTransaction, .releaseTransaction, transfers.listTransfers
PayoutsA six-week payout calendar per studio: splits landing each day and every payout; pay out the available balance now, or top a studio upfunds.listFunds, .fundMerchant, accounts.getMerchantAccounts, transfers.listTransfers

The Wire drawer (bottom of every screen, or press the backtick key) shows every typed SDK call a screen made, with the HTTP request and response, timing, retries and how any error was translated. It can make GP rate-limit the next read or expire the access token, to show the retry and refresh paths. Ctrl+K / ⌘K jumps to a screen, a studio (MER_…) or a payment (TRN_…).

GP API operations

OperationSDK methodUsed for
Create access tokenaccessToken.getAccessTokenPlatform credentials: nonce + SHA512 secret, cached
Address lookupmerchants.addressLookupValidate the studio's address while boarding
Board a merchantmerchants.boardMerchantCreate the studio as a sub-merchant
List merchantsmerchants.getMerchantsThe studio roster
Get a merchantmerchants.getMerchantSingleBoarding status and details
Edit a merchantmerchants.editMerchantUpdate studio details
Create upload URLfileProcessing.createUrlGet a URL for a KYC document
Upload a filefileProcessing.uploadFileSend the KYC document
Get file detailsfileProcessing.getFileDetailsDocument review status
List merchant accountsaccounts.getMerchantAccountsThe studio's transaction and funding accounts
Create sale or refundtransactionsApi.createSaleOrRefundTransactionTake a payment for the studio
Split a transactiontransactionsApi.splitTransactionStudio share and platform fee
List transferstransfers.listTransfersThe split graph
Reverse a splittransfers.reverseExistingSplitUndo a split
Hold a transactiontransactionsApi.holdTransactionHold risky funds
Release a transactiontransactionsApi.releaseTransactionRelease after review
Fund a merchantfunds.fundMerchantPay the studio out
List fundsfunds.listFundsPayout history

The flow: from a new studio to its first payout

  1. Token. Fieldhouse mints a platform access token with accessToken.getAccessToken.
  2. Board. The wizard validates the studio's address with merchants.addressLookup, then boards it with merchants.boardMerchant.
  3. KYC. For each document, fileProcessing.createUrl returns an upload URL, fileProcessing.uploadFile sends the file and fileProcessing.getFileDetails tracks its review. merchants.getMerchantSingle drives the status timeline.
  4. Accounts. Once the studio is active, accounts.getMerchantAccounts returns the accounts payments and payouts use.
  5. Pay. A member pays for a class: transactionsApi.createSaleOrRefundTransaction on the studio's account.
  6. Split. transactionsApi.splitTransaction moves the platform fee to Fieldhouse and the rest to the studio; transfers.listTransfers draws the split, and transfers.reverseExistingSplit undoes one.
  7. Hold. A risky payment is held with transactionsApi.holdTransaction and released with transactionsApi.releaseTransaction.
  8. Payout. funds.fundMerchant pays the studio, and funds.listFunds lists its payouts.

The prompt

Build Assembly, the operator console for Fieldhouse, our booking-software platform for independent fitness
studios, on Global Payments' GP API. We are a PayFac: each studio is a sub-merchant.

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.
- Onboarding: a boarding wizard for a studio (address lookup, details, KYC document upload) and a status timeline.
- Payments & Splits: take a payment for a studio, split it between the studio and our platform fee, show the
  split, reverse a split.
- Risk holds: hold a payment's funds and release them. Payouts: fund a studio and list its payouts.
- 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 split more than the payment, never fund a studio that is not active, and every write carries an
  idempotency key.
- Show GP's own reason on a refusal.

Done when: it builds cleanly, the tests pass, and a README explains how to set it up.

Code: the typed SDK

From server/payments.ts. A studio payment is taken on the studio's behalf (the paymentFacilitator block names the sub-merchant), and only a captured payment is split: the studio's share to its funds account, Fieldhouse's fee to the platform's. Each write carries an X-GP-Idempotency key derived from the intent, so a repeat is the same request.

// the studio must be live and have a funds account before money is taken for it
const s = await studio(env, input.studioId);
if (s.status !== "ACTIVE" || !s.fundsAccount) {
  const msg = `${s.name} is ${s.status.toLowerCase().replace("_", " ")}. Only an active studio can take payments.`;
  guard("transactionsApi.createSaleOrRefundTransaction", { studio: s.id }, msg);
  throw new HttpError(422, msg, { outcome: "not_sent" });
}

const reference = `FH-${input.intentId.slice(0, 12).toUpperCase()}`;
const req = {
  xGpIdempotency: `asm:sale:${input.intentId}`,
  body: {
    accountName: accountName(env),
    channel: "CNP" as const,
    type: "SALE" as const,
    // amount, currency, reference, description, paymentMethod …
    paymentFacilitator: {
      name: PLATFORM.name,
      subMerchantReference: s.id,
      subMerchantName: s.name.slice(0, 50),
      subMerchantCountry: "US",
    },
  },
};
const sale = await g.call("transactionsApi.createSaleOrRefundTransaction", req,
  (c) => c.transactionsApi.createSaleOrRefundTransaction(req));
if (sale.status !== "CAPTURED") return { declined: sale.status === "DECLINED", status: String(sale.status) };

const fee = feeFor(input.amount, input.feeBps);
const split = {
  id: sale.id ?? "",
  xGpIdempotency: `asm:split:${input.intentId}`,
  body: {
    transfers: [
      { recipientAccountId: s.fundsAccount.id, amount: String(input.amount - fee), reference: `${reference}-S`, description: "Studio share" },
      ...(fee > 0 ? [{ recipientAccountId: PLATFORM.fmaId, amount: String(fee), reference: `${reference}-F`, description: "Fieldhouse platform fee" }] : []),
    ],
  },
};
const res = await g.call("transactionsApi.splitTransaction", split, (c) => c.transactionsApi.splitTransaction(split));

Open Assembly → · All use cases

On this page