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
- 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.
- Identify a payment method belonging to the merchant associated with your API key. For example, use the
payment_method_idin an invoice payment response. The example ID6ba7babe-9906-4e7e-b1a5-f628c7badb61illustrates the format; use an ID from your own account. - Save the following code as
get_payment_method.py, runpython3 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."
]
}Obtain complete payment method information by ID including card type and metadata.
Check card type and prepaid status using bin_type and meta.prepaid fields.
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.isCpTokenizedandmeta.tokenTypeto identify whether the payment method came from a card-present transaction (a payment at a physical terminal) and which provider processed it.
Data Security & Compliance
Sensitive Data Exclusion: This endpoint excludes full card numbers and security codes to support your PCI DSS (Payment Card Industry Data Security Standard) compliance efforts. Excluding these fields does not establish that your integration meets all applicable requirements; consult your compliance team about your integration's requirements.
What's Included:
- Card brand and type
- Last four digits
- Expiration date
- Metadata and status
- Customer association
What's Excluded:
- Full card numbers
- CVV/Security codes
- Other sensitive payment data
Card Information Details
Debit or Credit Indicator: Use bin_type field to determine if the card is "DEBIT" or "CREDIT".
Prepaid Card Check: Use meta.prepaid field to check if the card is prepaid.
Card-Present Tokenization: For payment methods tokenized from a card-present (terminal) transaction, meta.isCpTokenized is true and meta.tokenType identifies the tokenization provider (e.g. "blockchyp"). Other tokenization flows omit both fields from meta; check for their presence before reading them.
Payment Method Status: Always check the status field to ensure the payment method is active before processing.
Customer Verification: Verify the customer_id to confirm ownership of the payment method.
Integration Tips
Updating Payment Methods: Use Update a Payment Method to change a stored payment method. In its endpoint notation, {id} represents the payment method ID; replace it with your own ID, as in PUT /payment-method/6ba7babe-9906-4e7e-b1a5-f628c7badb61. This GET endpoint only retrieves details.
Before Processing: Always retrieve and verify payment method details before attempting to process payments.
Error Handling: Implement proper error handling for cases where payment methods don't exist or are inactive.
HTTP Response Codes
| Code | Response | Reason |
|---|---|---|
| 200 | Success | Returns a payment method object with details. |
| 400 | Bad Request | Invalid payment method ID format. |
| 401 | Unauthorized | Authentication failed. |
| 404 | Not Found | A payment method does not exist. |
| 422 | Unprocessable Entity | The selected payment method ID is invalid. |
| 500 | Internal Server Error | An unexpected error occurred on the server. |
Error Handling Best Practices
400 Bad Request: Validate payment method ID format before making the request. IDs should follow the expected format pattern.
401 Unauthorized: Ensure your API credentials are valid and included in the request headers.
404 Not Found: The payment method may have been deleted or the ID may be incorrect. Double-check the ID and consider implementing fallback logic.
422 Unprocessable Entity: Use a payment method ID associated with the merchant whose API key authenticates your request. Inspect the id array in the error response for the validation message.
500 Internal Server Error: Implement retry logic with exponential backoff for temporary server issues.
Security Considerations
- PCI DSS Compliance Efforts: This endpoint excludes sensitive information to support your compliance efforts, not to guarantee compliance. Consult your compliance team to identify applicable requirements.
- Data Protection: This endpoint never returns full card numbers or security codes
- Access Control: Verify customer ownership before displaying payment method details
