Capture a Pre-Auth Transaction

Captures funds from a pre-authorized transaction. This converts a pre-authorization into a completed charge.

Capture a payment after placing a temporary hold on a customer's card (a pre-authorization).

This reference is for developers integrating with the Stax API. Capturing converts the pre-authorization into a completed charge.

Prepare your capture request

  1. Copy your sandbox merchant API key from Stax Pay > Apps > API Keys. A sandbox is a test environment that does not move real money. Sandbox and live keys use the same base URL; your key determines the environment.
  2. Copy the id from the API response for the pre-authorization you want to capture. For example, "d4db6c3b-4a96-48b6-a08b-551326fada40" illustrates the transaction ID format; use your own sandbox transaction's ID.
  3. Confirm that the pre-authorization has not expired or been canceled, and choose a capture total that does not exceed the authorized amount.
  4. Run the example below with Python 3. It uses only the standard library, prompts for credentials without displaying the key, and asks you to confirm before sending the capture request. Keep your key out of client-side code and public repositories.

Send a capture request

The example sends an explicit total and does not automatically retry: repeating a payment request after a connection failure could duplicate an operation whose result you have not yet confirmed.

import getpass
import json
import socket
import sys
from decimal import Decimal, InvalidOperation
from urllib.error import HTTPError, URLError
from urllib.parse import quote
from urllib.request import Request, urlopen


def main():
    # Find your sandbox key in Stax Pay > Apps > API Keys.
    api_key = getpass.getpass("Sandbox merchant API key: ").strip()
    # Copy id from your pre-authorization's API response, not a sample ID.
    # Example format: d4db6c3b-4a96-48b6-a08b-551326fada40
    transaction_id = input("Sandbox pre-authorization transaction ID: ").strip()
    total = input("Total to capture (not above the authorized amount): ").strip()
    if not api_key or not transaction_id:
        sys.exit("Provide an API key and a transaction ID.")
    try:
        amount = Decimal(total)
        if not amount.is_finite() or amount <= 0:
            raise ValueError
    except (InvalidOperation, ValueError):
        sys.exit("Enter a positive, finite capture total.")

    confirmation = input(f"Capture {total} for {transaction_id}? Type CAPTURE: ")
    if confirmation != "CAPTURE":
        sys.exit("Canceled; no request was sent.")

    request = Request(
        "https://apiprod.fattlabs.com/transaction/"
        + quote(transaction_id, safe="") + "/capture",
        data=json.dumps({"total": total}).encode("utf-8"),
        headers={
            "Authorization": "Bearer " + api_key,
            "Content-Type": "application/json",
            "Accept": "application/json",
        },
        method="POST",
    )
    try:
        with urlopen(request, timeout=30) as response:
            transaction = json.load(response)
    except HTTPError as error:
        details = error.read().decode("utf-8", errors="replace")
        sys.exit(f"HTTP {error.code}: {details}\nReview the error before retrying.")
    except (URLError, TimeoutError, socket.timeout) as error:
        sys.exit(f"Connection error: {error}. Check the transaction before retrying.")
    except (ValueError, UnicodeError):
        sys.exit("Invalid JSON response. Check the transaction before retrying.")

    if not isinstance(transaction, dict):
        sys.exit("Unexpected response format. Check the transaction before retrying.")
    print(json.dumps({key: transaction.get(key) for key in (
        "id", "success", "is_captured"
    )}, indent=2))
    if transaction.get("success") is not True:
        sys.exit("Capture success was not confirmed. Check the transaction before retrying.")
    if transaction.get("is_captured") != 1:
        sys.exit("Capture status was not confirmed. Check the transaction before retrying.")
    print("Capture confirmed.")


if __name__ == "__main__":
    main()

For the transaction in the endpoint's documented successful response, the script prints:

{
  "id": "d4db6c3b-4a96-48b6-a08b-551326fada40",
  "success": true,
  "is_captured": 1
}
Capture confirmed.

Your transaction ID will differ. Confirm both success: true and is_captured: 1; an HTTP success status alone is not enough to confirm the payment outcome.

Usage Scenarios

Hospitality Industry: Charging a customer upon checkout after their stay.

Car Rentals: Capturing funds after the rental period ends and final charges are calculated.

E-commerce with Delayed Shipping: Capturing payment once an item is shipped.


Response Structure

CodeResponseAction
200SuccessCheck the returned transaction's success and is_captured fields to confirm capture.
400Bad requestCheck the capture total and whether the pre-authorization has expired or already been captured.
404Not FoundCheck that transactionid identifies a pre-authorization belonging to your merchant account.
422Unprocessable EntityReview the validation errors. The endpoint's documented example returns {"id": ["The selected id is invalid."]} for an invalid ID.

For 401, check your merchant API key. After a connection failure or an unexpected response, inspect the transaction before submitting another capture.


Detailed Parameter Descriptions

ParameterLocationTypeRequirements and constraints
transactionidURL pathstringRequired. Use the id from the pre-authorization's API response. The pre-authorization must not be expired or canceled. No default.
totalJSON bodystringAmount to capture; it cannot exceed the original pre-authorization amount. The specification does not mark this field as required or document a default. Send it explicitly, as in the example.

The capture specification does not document amount or meta as request fields. Use total for the capture amount.


Usage Notes

Partial Captures

You can capture less than the pre-authorized amount if necessary. Remaining funds may be released or require a void operation.

Multiple Captures

Some processors allow multiple partial captures against a single pre-authorization. Verify if this is supported.

Timing

Pre-authorizations have a validity period (typically 7 days). Capture within this timeframe.

Avoid duplicate capture requests

Idempotency means that repeating a request does not repeat its effect. The capture specification does not document an idempotency_id request field, so do not assume that adding one prevents duplicate captures. Check the transaction after an uncertain result before sending another capture request.


Additional Considerations

Remaining Funds

After a partial capture, remaining pre-authorized funds may need to be released.

Communication with Customer

Inform customers when captures occur, especially if the captured amount differs from the pre-authorized amount.

Compliance

Review your processor's policies and card network requirements for pre-authorizations and captures to support your compliance efforts. Consult your legal team regarding specific requirements.

Path Params
string
required
Body Params
string

Amount that you would like to capture

Responses

Language
Credentials
Bearer
JWT
LoadingLoading…
Response
Click Try It! to start a request and see the response here! Or choose an example:
application/json