Verify A Payment Method

As a developer integrating the Stax API, use POST /verify to check a saved credit card with an authorization (a temporary funds hold) followed by an immediate void (cancellation of that hold), without capturing funds (completing a charge).

This operation is advanced and not recommended for most users. It is primarily used in scenarios where you need to confirm a card's validity without initiating a charge.

Verify a saved credit card

  1. Run Python 3 on your server or local development machine. The example uses only the Python standard library and prompts for your merchant API key without displaying it.
  2. Obtain a payment_method_id belonging to the merchant associated with your API key. You can use the payment_method_id returned in an invoice payment response. The UUID d3050b19-77d9-44ac-9851-b1d1680a7684 illustrates the format; replace it with an ID from your own account, not the sample value.
  3. Save the code below as verify_payment_method.py and run python3 verify_payment_method.py. Enter your merchant API key, payment method ID, and verification amount when prompted. An amount of 1.00 matches the endpoint's example; confirm the amount permitted by your card network before sending the request.

This example sends a real verification request to the production API. Verification may incur network fees or temporarily hold funds. It uses a 30-second timeout and does not automatically retry, to avoid repeating a request whose outcome is unknown.

import getpass
import json
import math
import sys
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen


def main():
    api_key = getpass.getpass("Merchant API key: ").strip()
    # Use payment_method_id from an invoice payment response for this merchant.
    # Example format: "d3050b19-77d9-44ac-9851-b1d1680a7684".
    payment_method_id = input("Payment method ID: ").strip()
    try:
        total = float(input("Verification amount permitted by your card network: "))
    except ValueError:
        print("Enter a numeric amount.", file=sys.stderr)
        return 1
    if not api_key or not payment_method_id:
        print("Enter both your merchant API key and payment method ID.", file=sys.stderr)
        return 1
    if not math.isfinite(total) or total < 0:
        print("Enter a finite, nonnegative amount.", file=sys.stderr)
        return 1

    request = Request(
        "https://apiprod.fattlabs.com/verify",
        data=json.dumps({
            "payment_method_id": payment_method_id,
            "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:
            data = json.load(response)
    except HTTPError as error:
        guidance = {
            400: "Check the card details and available funds.",
            422: "Correct the fields listed in the validation response.",
        }
        print(f"HTTP {error.code}: " + guidance.get(
            error.code, "Inspect the error response before taking further action."
        ), file=sys.stderr)
        print(error.read().decode("utf-8", errors="replace"), file=sys.stderr)
        return 1
    except (URLError, TimeoutError, OSError) as error:
        print(f"Request failed: {error}. Confirm the transaction outcome before retrying.",
              file=sys.stderr)
        return 1
    except (ValueError, UnicodeError):
        print("Unreadable JSON response. Confirm the transaction outcome before retrying.",
              file=sys.stderr)
        return 1

    if not isinstance(data, dict):
        print("Unexpected response. Confirm the transaction outcome before retrying.",
              file=sys.stderr)
        return 1
    if data.get("success") is not True:
        print("Verification was not confirmed: " + str(data.get("message")),
              file=sys.stderr)
        return 1
    if not data.get("id") or data.get("is_voided") is not True:
        print("The response did not confirm both a transaction ID and a void. "
              "Check the transaction before retrying.", file=sys.stderr)
        return 1

    print(json.dumps({
        "id": data["id"],
        "success": data["success"],
        "is_voided": data["is_voided"],
        "payment_method_id": data.get("payment_method_id"),
    }, indent=2))
    return 0


if __name__ == "__main__":
    sys.exit(main())

On success, the API returns HTTP 200. The script prints the following fields from the documented response; your IDs will differ:

{
  "id": "2f2c2b7f-ae85-45af-8120-f05c242cedfe",
  "success": true,
  "is_voided": true,
  "payment_method_id": "d3050b19-77d9-44ac-9851-b1d1680a7684"
}

Treat verification as complete only when the response confirms success and the void. For HTTP 422, correct the fields named in the error response; do not retry an unchanged request. If a connection fails or the response is unreadable, confirm the transaction outcome before sending another verification.

Optional: Choose a verification use case

Account Setup: Verifying a customer's card when they add it to their account.

Fraud Prevention: Checking card validity before processing large transactions.

Subscription Trials: Ensuring the card is valid before starting a trial period.


Response Structure

CodeResponseReason
200SuccessReturns a transaction object indicating that the verification was successful, including transaction ID, type, status, amount, currency, payment method ID, creation timestamp, and any metadata provided.
400Bad RequestVerification failed due to invalid card details or insufficient funds.
422Unprocessable EntityValidation errors occurred.

Set verification parameters

ParameterTypeRequiredDefault and constraints
payment_method_idstringYesNo default. Use an existing payment method for the merchant associated with your API key. Example format: d3050b19-77d9-44ac-9851-b1d1680a7684. Obtain your actual value from the invoice payment response described above.
totalnumber (float)YesNo default. Use a minimal amount permitted by your card network, such as 0.00 or 1.00. The endpoint example uses 1; the specification does not state numeric limits.
metaobjectNo, according to the request schemaNo default. Include additional information relevant to the verification. The specification also includes a validation example reporting meta as required; if you receive that error, include a JSON object and inspect any remaining validation errors.

Usage Notes

Alternative Methods

For most cases, it's sufficient to perform a minimal charge or pre-authorization to verify a card.

Fees

Verification transactions may incur network fees.

Idempotency

The current POST /verify specification does not document an idempotency_id parameter or its format. Confirm support before relying on idempotency (handling repeated requests without creating duplicate operations). The example does not send this undocumented parameter or automatically retry requests.


Additional Considerations

Customer Experience

Be aware that some banks may place a temporary hold on funds, which could confuse customers.

Regulatory Compliance

Use card verification to support your compliance efforts, not as a guarantee of compliance. Consult your legal team regarding requirements for card verification in your jurisdiction.

Not for ACH

Verification is applicable only to credit cards, not ACH transactions.

Body Params
float
required

A float that is required and will be the amount a customer is charged

string
required

An existing payment_method_id within Stax.

meta
object

Meta can contain any json object

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