GOAT Network
GOAT Flow

Checkout

This guide connects an existing application to hosted crypto checkout on Mainnet or Testnet3, using a TypeScript backend and browser frontend. You will create a session for an application order, send the buyer to checkout, and read the payment result on your backend.

The snippets are integration functions, not a complete web application. Your application supplies login, order storage, and HTTP routes. For a fixed-price QuickPay product, you can open the product page without writing session-creation code. The page can offer Crypto, Card, or both, depending on the methods enabled for your merchant account and selected for that product. See Product checkout.

1. Prepare the merchant

Choose an environment. The SDKs and integration steps below are the same for both:

EnvironmentUseMerchant Portal
MainnetReal paymentsMainnet Merchant Portal
Testnet3Integration testingTestnet3 Merchant Portal

Merchant approval, receiving configuration, PayKit activation, API credentials, and fee balance are specific to each environment. Complete these steps in the portal for your selected environment:

  1. Register and obtain approval for an enabled DIRECT merchant.
  2. Configure a receiving address for an available crypto chain/token. In updated portals, activate PayKit under Payment Setup → PayKit Settings (the underlying capability is still named QuickPay in the API). Check the fees and merchant fee-balance requirements.
  3. Create API credentials under Developer → API & Checkout Settings and save the secret on your backend. Older portal labels are shown in the Merchant Guide.

Fund the buyer's wallet with a token enabled for your merchant and native gas on the same chain. On GOAT, gas is paid in BTC. For Testnet3, get test BTC from the faucet. Find the RPC and explorer for each environment in Networks and RPC. Mainnet payments use real funds. Portal instructions are in the Merchant Guide.

2. Install and configure

Use Node.js 18 or later on the backend. Install in the corresponding applications:

# Backend
npm install goatflow-sdk-server@0.4.0
# Frontend
npm install goatflow-checkout@0.2.0

Set backend environment variables using one of the following configurations. Supply the credentials and merchant ID from that environment.

Mainnet

GOATX402_API_URL=https://flow-api.goat.network
GOATX402_CHECKOUT_ORIGIN=https://flow-quickpay.goat.network
GOATX402_API_KEY=your_mainnet_api_key
GOATX402_API_SECRET=your_mainnet_api_secret
GOATX402_MERCHANT_ID=your_mainnet_merchant_id

Testnet3

GOATX402_API_URL=https://flow-api.testnet3.goat.network
GOATX402_CHECKOUT_ORIGIN=https://flow-quickpay.testnet3.goat.network
GOATX402_API_KEY=your_testnet_api_key
GOATX402_API_SECRET=your_testnet_api_secret
GOATX402_MERCHANT_ID=your_testnet_merchant_id

Your backend checks the session URL against GOATX402_CHECKOUT_ORIGIN before sending the checkout ID and origin to the browser. Step 5 uses the same origin to read the session status.

Keep the API secret out of frontend environment variables and browser bundles. Use credentials, products, and checkout origins from the same environment; see the environment table.

3. Create and save a session on the backend

import { GoatFlowClient, GoatFlowError, type CheckoutSession } from 'goatflow-sdk-server'

const checkoutOrigin = new URL(process.env.GOATX402_CHECKOUT_ORIGIN!).origin
const flow = new GoatFlowClient({
  baseUrl: process.env.GOATX402_API_URL!,
  apiKey: process.env.GOATX402_API_KEY!,
  apiSecret: process.env.GOATX402_API_SECRET!,
})

export function checkoutForBrowser(session: Pick<CheckoutSession, 'checkoutId' | 'url'>) {
  const url = new URL(session.url)
  if (url.protocol !== 'https:' || url.origin !== checkoutOrigin || url.username || url.password) {
    throw new Error('Checkout URL does not match the configured payment site')
  }
  return { action: 'checkout', checkoutId: session.checkoutId, origin: checkoutOrigin }
}

export async function createPaymentSession(
  paymentIntentId: string,
  serverPrice: string,
  saveSession: (session: CheckoutSession) => Promise<void>,
) {
  const session = await flow.createCheckoutSession({
    checkoutType: 'DIRECT',
    paymentRails: ['crypto'],
    price: serverPrice, // Decimal price from your server's cart, e.g. '9.99'.
    clientReferenceId: paymentIntentId,
  })
  await saveSession(session)
  return checkoutForBrowser(session)
}

Connect this function to your own authenticated route, for example POST /api/orders/:id/checkout. That route must:

  1. Load the application order and check that the signed-in buyer owns it.
  2. Read its price from your database and allocate one stable payment-intent ID. Serialize creation for that intent so double-clicks cannot create two payments.
  3. Call createPaymentSession once for a new intent. Supply a saveSession callback that saves checkoutId, url, expiresAt, environment, and expected price against the order. If saving or URL validation fails, withhold the link and reconcile the attempt before creating a replacement.
  4. On repeat requests, call checkoutForBrowser on the saved session only if it is still payable. Otherwise return { action: 'status', message: '…' } with the current buyer-facing order status, such as “Confirming payment” or “Paid”. Reconcile expired or unresolved attempts before replacing them.

A duplicate clientReferenceId returns a conflict, not the previous session. If creation times out or the response is lost, mark the attempt unresolved and reconcile it; do not generate a new ID and immediately request payment again. The SDK has no lookup by client reference or session-renewal helper. See published SDK limits.

This example omits return URLs. To add successUrl or cancelUrl, first configure Checkout return URLs.

4. Open checkout in the browser

import { GoatCheckout } from 'goatflow-checkout'

export async function startPayment(businessOrderId: string, statusLine: HTMLElement) {
  const response = await fetch(
    `/api/orders/${encodeURIComponent(businessOrderId)}/checkout`,
    { method: 'POST', credentials: 'same-origin' },
  )
  if (!response.ok) throw new Error('Could not start checkout')
  const result = await response.json()
  if (result?.action === 'status' && typeof result.message === 'string' && result.message) {
    statusLine.textContent = result.message
    return
  }
  if (result?.action !== 'checkout' || typeof result.checkoutId !== 'string' ||
      !result.checkoutId || typeof result.origin !== 'string' || !result.origin) {
    throw new Error('Unexpected checkout response')
  }
  const checkout = GoatCheckout({ origin: result.origin })
  checkout.redirectToCheckout({ checkoutId: result.checkoutId })
}

Call startPayment from your Pay button with the order ID and the element where buyers see their order status. Use your framework's authentication and CSRF protection on the application route from step 3.

Open hosted checkout in a top-level tab or window. Iframe embedding is unsupported. A full-page redirect works after the asynchronous session request. If using a popup instead, open() must run synchronously inside a user gesture; see the browser SDK.

5. Read the payment result on the backend

Load the checkout ID and environment saved in step 3. Use the matching backend configuration for that environment and the saved ID, not an ID supplied by the browser. The session's status endpoint supplies the linked order_id after crypto binding. Then read that order through the authenticated server SDK:

// Same backend module as step 3. This example is for the crypto rail only.
export async function readCryptoPayment(checkoutId: string) {
  const statusUrl = new URL(
    `/checkout/v1/sessions/${encodeURIComponent(checkoutId)}/status`,
    checkoutOrigin,
  )
  const response = await fetch(
    statusUrl,
    { signal: AbortSignal.timeout(15_000), redirect: 'error' },
  )
  if (!response.ok) throw new Error(`Checkout status failed: ${response.status}`)
  const session: unknown = await response.json()
  if (!session || typeof session !== 'object' || !('status' in session) ||
      typeof session.status !== 'string' || !session.status) {
    throw new Error('Invalid checkout status')
  }
  if (!('order_id' in session)) return { checkoutStatus: session.status }
  if (typeof session.order_id !== 'string' || !session.order_id) {
    throw new Error('Invalid checkout order ID')
  }

  const order = await flow.getOrderStatus(session.order_id)
  if (order.merchantId !== process.env.GOATX402_MERCHANT_ID ||
      order.orderId !== session.order_id) {
    throw new Error('Payment does not match this merchant session')
  }
  const result = { checkoutStatus: session.status, order }
  if (order.status !== 'INVOICED') return result
  const deadline = Date.now() + 60_000
  for (const delayMs of [0, 1_000, 2_000]) {
    if (delayMs > 0) await new Promise(resolve => setTimeout(resolve, delayMs))
    // Reserve the published SDK's 30-second request timeout before each read.
    if (Date.now() + 30_000 > deadline) break
    try {
      const proof = await flow.getOrderProof(order.orderId)
      return { ...result, proof }
    } catch (error) {
      if (!(error instanceof GoatFlowError && error.status === 404)) throw error
    }
  }
  return { ...result, needsReconciliation: true }
}

The raw status call is an HTTP endpoint, not an SDK method. Its response and deployment boundary are documented in Checkout status. Treat the opaque checkout ID as a bearer capability and keep it out of logs.

Run confirmation in a backend job and save the result for the buyer's order-status page. When the Crypto session has no order_id, readCryptoPayment returns its session state in checkoutStatus.

  • For OPEN, show “Awaiting payment” and check again later.
  • For EXPIRED or CANCELLED, show “Checkout expired” or “Checkout cancelled” and stop polling this session. Reconcile any reported transfer before offering another payment.

If the status request fails, keep the last known state or show “Checking payment status” on the first read. Retry transient errors and investigate persistent errors before requesting another payment.

Confirm the Crypto payment. When the authenticated order reaches INVOICED, verify its proof against the saved purchase. See payment order statuses. For Card, follow the Card payment checks.

The example retries a proof 404 only for the verified order. If it returns needsReconciliation, record that state on the purchase and check the saved order ID and environment. Show “Confirming payment” on refresh without restarting the retry window.

Once the proof is available, match its order and transaction to the saved purchase. Verify the merchant, chain, and token contract. Use your trusted receiving address and token decimals for that chain and token to compare proof.payload.to_addr and proof.payload.amount_wei with the expected recipient and price in base units. The proof's signature is a digest, not a signed attestation; see Read proof.

After those checks pass, record the completed payment once. A browser callback or return URL only updates the UI. If using webhooks, implement the deployment-confirmed verification contract.

6. Verify the complete path

  • Complete a payment in your selected environment and find the same order in that environment's Merchant Portal. Mainnet payments use real funds.
  • Confirm your backend records the payment against the correct purchase.
  • Repeat the status read and replay a notification. Both should leave one payment record.
  • On Testnet3, test cancellation, expiry, a payment that arrives after expiry, and a lost API response. Reconcile each result without requesting a second payment.
  • Before accepting Mainnet payments, complete the launch checks with Mainnet merchant setup, credentials, receiving configuration, and fee balance.

Other integration options

Card payments: use the same backend session creation and hosted-page flow with the Card fields and prerequisites. Identify the saved Card session or payment order on your backend, then check its completion status or verify a completion event.

Custom crypto UI: use the custom wallet example. See Go server SDK setup for Go support and Card limitations.

Custom Card form: Initialize the Card payment attempt, then build and submit the form with Stripe Elements.

React components: the PayKit React SDK is not publicly released. Use the hosted-page walkthrough above with the published Checkout SDK, or obtain a deployment-approved React build before planning an embedded integration.

Return URLs and recovery: configure Checkout return URLs before setting them. Detailed reference/retry behavior and expiry rules are maintained in the API Reference.

On this page