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
- 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.
- Obtain a
payment_method_idbelonging to the merchant associated with your API key. You can use thepayment_method_idreturned in an invoice payment response. The UUIDd3050b19-77d9-44ac-9851-b1d1680a7684illustrates the format; replace it with an ID from your own account, not the sample value. - Save the code below as
verify_payment_method.pyand runpython3 verify_payment_method.py. Enter your merchant API key, payment method ID, and verification amount when prompted. An amount of1.00matches 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
| Code | Response | Reason |
|---|---|---|
| 200 | Success | Returns 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. |
| 400 | Bad Request | Verification failed due to invalid card details or insufficient funds. |
| 422 | Unprocessable Entity | Validation errors occurred. |
Set verification parameters
| Parameter | Type | Required | Default and constraints |
|---|---|---|---|
payment_method_id | string | Yes | No 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. |
total | number (float) | Yes | No 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. |
meta | object | No, according to the request schema | No 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.
