Get a Payment Method By ID

Retrieves the payment method matching the given id.

Retrieve a stored payment method's non-sensitive details from your server-side Stax API integration using its unique ID.

Audience: Developers integrating with the Stax API. You can retrieve the card brand, last four digits, expiration date, and metadata without retrieving the full card number or security code.

Retrieve a payment method

  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. Identify a payment method belonging to the merchant associated with your API key. For example, use the payment_method_id in an invoice payment response. The example ID 6ba7babe-9906-4e7e-b1a5-f628c7badb61 illustrates the format; use an ID from your own account.
  3. Save the following code as get_payment_method.py, run python3 get_payment_method.py, and enter your API key and payment method ID when prompted. The request uses a 30-second timeout so a stalled connection does not wait indefinitely.
import getpass
import json
import sys
from urllib.error import HTTPError, URLError
from urllib.parse import quote
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: "6ba7babe-9906-4e7e-b1a5-f628c7badb61".
    payment_method_id = input("Payment method ID: ").strip()
    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

    request = Request(
        "https://apiprod.fattlabs.com/payment-method/"
        + quote(payment_method_id, safe=""),
        headers={
            "Authorization": "Bearer " + api_key,
            "Accept": "application/json",
        },
        method="GET",
    )
    try:
        with urlopen(request, timeout=30) as response:
            data = json.load(response)
    except HTTPError as error:
        guidance = {
            400: "Check the payment method ID.",
            401: "Check your merchant API key.",
            404: "Check that the payment method exists for this merchant.",
            422: "The selected ID is invalid; use a payment method ID for this merchant.",
            500: "Retry later with exponential backoff.",
        }
        print(
            f"HTTP {error.code}: "
            + guidance.get(error.code, "Inspect the error response before retrying."),
            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}", file=sys.stderr)
        return 1
    except (ValueError, UnicodeError):
        print("The API returned an unreadable JSON response.", file=sys.stderr)
        return 1

    if not isinstance(data, dict) or not data.get("id"):
        print("The response does not contain a payment method ID.", file=sys.stderr)
        return 1

    print(json.dumps({
        "id": data["id"],
        "card_type": data.get("card_type"),
        "card_last_four": data.get("card_last_four"),
    }, indent=2))
    if data.get("deleted_at"):
        print("This payment method has a deletion timestamp; do not treat retrieval as proof it is active.")
    return 0


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

On success, the API returns HTTP 200. The script prints these fields; values vary by payment method, and missing card fields appear as null:

{
  "id": "6ba7babe-9906-4e7e-b1a5-f628c7badb61",
  "card_type": "visa",
  "card_last_four": "1111"
}

Retrieval confirms that you received the payment method details, not that the method is eligible for a payment. The specification's sample record includes a deletion timestamp and an expired card, so the script also prints a warning for that record.

For an invalid ID, the specification documents HTTP 422 with this response:

{
  "id": [
    "The selected id is invalid."
  ]
}
Payment Method Details

Obtain complete payment method information by ID including card type and metadata.

Card Type Detection

Check card type and prepaid status using bin_type and meta.prepaid fields.

Management Integration

Useful for managing payment methods and verifying details before processing.

What You Can Do

  • Obtain payment method details by ID - Get comprehensive information about stored payment methods
  • Check card type and prepaid status - Determine if cards are debit/credit and prepaid
  • Verify payment method details - Useful for managing payment methods before processing
  • Check card-present tokenization source - Tokenization replaces sensitive card details with a stored reference you can use for payments. Use meta.isCpTokenized and meta.tokenType to identify whether the payment method came from a card-present transaction (a payment at a physical terminal) and which provider processed it.
Path Params
string
required
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