End-to-End Walkthrough: PreAuth and Capture

A complete third-party integration — PKCE authorization, merchant discovery, creating a PreAuth payment link, and capturing the funds when you're ready.

This guide walks through a full third-party integration end to end: you authorize the user, discover which merchant you're transacting on behalf of, create a PreAuth payment link that holds the customer's funds, and capture (or cancel) the hold when the service has been delivered.

We use a concrete scenario throughout — a booking platform that wants to hold a guest's card at reservation time and only charge the final amount when they actually check out. PreAuth is the right tool for that: it confirms the funds are available without moving them, and lets you decide later whether to capture the full hold, a smaller amount, or nothing at all.

Everything here applies whether you sell rooms, rentals, services, or anything else where the amount you're going to charge isn't final at the moment the customer commits.

The five moving parts

  1. Authorize — Get an access token via PKCE + consent. The user picks which of their businesses you may act on behalf of.
  2. Discover merchants — Your token is bound to a business; that business may have multiple merchants. List them and pick one.
  3. Create the PreAuth link — POST a payment link with paymentIntent: PREAUTH on the chosen merchant.
  4. The customer pays — They open the hosted payment page and authorize the hold. You receive a webhook (or poll) when the hold is in place.
  5. Capture or cancel — When the service is delivered, capture the funds (full or partial). If you decide not to charge, cancel instead.

Prerequisites

  • A registered Securely Connect client with party type THIRD_PARTY. (Second-party flow is similar but skips Steps 1 and 2 — your keys are already business- and merchant-scoped.)
  • At least one redirect URI registered on your client.
  • A way to persist tokens server-side (or in secure browser storage for SPAs).

If you haven't read Second-Party vs Third-Party yet, do that first — the rest of this guide assumes third-party.

Step 1 — Authorize the user

The user lands in your app. They click "Connect to Securely." You send them through the standard PKCE flow against https://auth.securely.io/oauth/authorize. They log in, see the consent screen with your app's name and logo, pick which of their businesses to grant you access to, and return to your redirect_uri with an authorization code.

You exchange the code for tokens at /oauth/token:

curl -X POST https://auth.securely.io/oauth/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=authorization_code" \
  -d "code=THE_CODE_FROM_CALLBACK" \
  -d "redirect_uri=https://your.app/callback" \
  -d "client_id=YOUR_CLIENT_ID" \
  -d "code_verifier=ORIGINAL_VERIFIER"

The response:

{
  "access_token": "eyJhbGciOiJSUzI1NiIs...",
  "token_type": "Bearer",
  "expires_in": 3600,
  "refresh_token": "eyJhbGciOiJSUzI1NiIs..."
}

The access token is a JWT. If you decode it you'll see the business_id claim — that's the business the user chose at the consent screen. Every API call you make with this token will be scoped to that business.

For the full PKCE flow with code samples in four languages, see the Implement PKCE recipe. For why third-party always uses PKCE — even confidential clients — see The PKCE Authorization Code Flow.

📘

Why the access token alone isn't enough

The token tells you which business you're acting for, but payment links live under a specific merchant. A business can own multiple merchants — different locations, different brands, different DBAs. That's why the next step exists.

Step 2 — Discover the merchant

Your token is business-scoped. To create a payment link, you need a merchant ID in the URL path. List the merchants under the user's business and pick the one you want.

curl https://api.securely.io/v2/merchants \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

The response is a list of active merchants the token can access:

[
  {
    "merchantId": 7,
    "chargeName": "Mountain View Lodge",
    "tipsEnabled": false,
    "captureSignatureEnabled": true,
    "createChargeOnDeviceEnabled": true,
    "receiptEnabled": true,
    "address": {
      "address1": "120 Pine Ridge Rd",
      "city": "Boulder",
      "stateCode": "CO",
      "zipCode": "80302",
      "countryCode": "US"
    },
    "virtualTerminalEnabled": true,
    "quickPayEnabled": true,
    "hasTerminals": true
  }
]

There are a few ways to use this:

  • One merchant in the business. Common — most integrations just pick the only entry.
  • Multiple merchants. Render the list to the user and let them pick. Persist their choice so you don't ask again.
  • Programmatic selection. If you can identify the right merchant by chargeName or address, do that — but persist the chosen merchantId so you have a stable handle.

Hold on to the merchantId. You'll use it in Step 3.

📘

The token is the gatekeeper

GET /v2/merchants returns only merchants the access token's business can see. If the token doesn't have a business_id claim, the call returns 403. If the token is missing entirely or invalid, you'll see 401.

Step 3 — Create the PreAuth payment link

Now the actual integration step. You're creating a payment link that places a hold on the customer's funds — it does not move the money yet. The customer will authorize the hold by completing the payment on a Securely-hosted page; you'll capture (or cancel) the hold later.

The key field is paymentIntent: "PREAUTH". If you used AUTH_CAPTURE instead, the funds would move immediately — that's the right choice for ecommerce where the price is final at checkout, but it's wrong for booking flows where the final amount comes later.

curl -X POST https://api.securely.io/v2/merchants/7/payment-links \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "mode": "CHECKOUT",
    "paymentIntent": "PREAUTH",
    "amount": 480.00,
    "redirectUrl": "https://your.app/bookings/B-1042/authorized",
    "cancelUrl":   "https://your.app/bookings/B-1042/cancelled",
    "invoiceNumber": "B-1042",
    "customer": {
      "firstName": "Sarah",
      "lastName":  "Chen",
      "email":     "[email protected]",
      "cellPhone": "+15555550123"
    },
    "metadata": {
      "bookingId": "B-1042",
      "checkIn":   "2026-06-12",
      "checkOut":  "2026-06-15"
    }
  }'

A few field choices to think about:

  • amount — set this to the maximum you might charge. The hold pre-authorizes up to this amount. You can capture less, but never more.
  • mode: CHECKOUT — the customer drives the payment on a Securely-hosted page. (Use CHARGE mode if an agent at a counter is going to run the customer through a terminal instead
  • metadata — anything you put here is echoed back on the response and allowed during future searches. Use it to correlate Securely's records with your own (booking IDs, reservation references, etc.).

The response includes the linkId you'll need for capture:

{
  "linkId": "pl_2x9a3kd0",
  "businessId": 42,
  "merchantId": 7,
  "amount": 480.00,
  "invoiceNumber": "B-1042",
  "customerId": 871,
  "paymentIntent": "PREAUTH",
  "mode": "CHECKOUT",
  "redirectUrl": "https://your.app/bookings/B-1042/authorized",
  "cancelUrl":   "https://your.app/bookings/B-1042/cancelled",
  "metadata": {
    "bookingId": "B-1042",
    "checkIn":   "2026-06-12",
    "checkOut":  "2026-06-15"
  }
}

Store the linkId against your booking record. It's the handle you'll use to capture or cancel.

Step 4 — The customer authorizes the hold

You share the hosted payment page URL with the customer (built from linkId). They open it, see a Securely-styled payment form, pick a payment method, and confirm. At that moment, Securely places the hold on their card — the bank confirms the funds are available and reserves them.

The customer is redirected to your redirectUrl on success or cancelUrl if they bail out.

📘

Authorized ≠ captured

When the customer completes this page, the money has not moved. The card issuer has just reserved up to amount in the customer's available balance. You still have to capture (Step 5) to actually move funds to the merchant.

You'll know the hold landed because the customer hits your redirectUrl. For a more reliable signal — especially if the customer closes their browser before being redirected — use webhooks or poll the payment link by ID.

🚧

PreAuth holds expire

Card networks expire authorizations after a card-network-defined window (often 7 days, sometimes shorter for certain card types). If you wait too long to capture, the hold will lapse and the capture will fail. If your business window is longer than a week, build a "re-authorize" path: cancel the existing hold and create a fresh PreAuth link before the original expires.

Step 5 — Capture the funds

Service delivered, customer checked out, time to charge. Capture the hold:

curl -X POST https://api.securely.io/v2/payment-links/pl_2x9a3kd0/capture \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{}'

With an empty body, the full authorized amount is captured. To capture less — say the guest didn't use the minibar, so the final bill came in under the hold — pass the actual amount:

curl -X POST https://api.securely.io/v2/payment-links/pl_2x9a3kd0/capture \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "amount": 412.50 }'

The capture amount must be greater than zero and no more than the amount you originally authorized in Step 3. If you need to charge more, you'll need to authorize a separate transaction for the overage.

The response is a PayResponse:

{
  "success": true,
  "ccTransactionId": 50182,
  "amount": 412.50,
  "unratedAmount": 412.50,
  "status": "CAPTURED"
}

A non-success response includes a declineDetail block with consumer-facing and merchant-facing messages, an error code, and flags telling you whether a retry is worth offering:

{
  "success": false,
  "amount": 0,
  "errorMessage": "Card declined",
  "declineDetail": {
    "consumerTitle": "We couldn't complete the charge",
    "consumerBody":  "Please contact your card issuer.",
    "merchantTitle": "Decline at capture",
    "merchantBody":  "Issuer declined the capture for an expired hold.",
    "showRetry": false,
    "showGoToSettings": false,
    "errorCode": "EXPIRED_AUTHORIZATION"
  }
}

Capture endpoint notes worth knowing:

  • The path is /v2/payment-links/{linkId}/capture — no merchantId in the path. The link already knows which merchant it belongs to.
  • The payment link must have paymentIntent: PREAUTH and be in ACTIVE status. Capturing an already-captured or cancelled link will fail.

Alternative — cancel without capturing

If you decide not to charge at all — the guest didn't show, the rental was free as a goodwill gesture, the trip was cancelled — release the hold instead of capturing it:

curl -X POST https://api.securely.io/v2/payment-links/pl_2x9a3kd0/cancel \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Response:

{ "success": true }

The hold is released back to the customer immediately on Securely's side. Their bank typically reflects the released funds within a day or two, depending on the issuer.

Cancelling is the right move when you're certain you won't capture. If there's any chance you might still want partial funds, capture the partial amount instead — once cancelled, the link can't be reactivated.

What can go wrong

SymptomLikely cause
401 on GET /v2/merchantsMissing or expired access token. Refresh and retry. See Recipe: Refresh an Access Token Correctly.
403 on GET /v2/merchantsThe access token has no business_id claim. This happens if the token came from a flow that didn't go through consent. Re-run authorization.
Empty merchants listThe business has no active merchants. Confirm with the business that they've completed merchant setup.
Capture returns 400 / link not in expected stateThe link was already captured, cancelled, or its hold has expired. Each link is single-use.
Capture succeeds but success: falseThe issuer declined at capture time (the original hold may have expired, or the card was flagged after the original authorization). Read declineDetail for specifics.

Where to go from here



Did this page help you?