Retrieves a non-paginated data array of all non-deleted payment methods associated with a customer.
Retrieve a customer's saved, non-deleted payment methods from your server-side integration to display their payment options.
This API reference is for developers. Authenticate with the merchant's secret API key and use a customer ID associated with that merchant.
Retrieve all payment methods for a specific customer with detailed information.
Access payment method details without exposing sensitive information.
Perfect for customer account management and payment option displays.
Retrieve saved payment methods
- Install Python 3 to run this server-side example; it uses only the standard library.
- Copy your secret API key from Stax Pay > Apps > API Keys. Use a sandbox API key for testing, and keep the key out of browser code and public repositories.
- Copy the customer's
idfrom a customer API response, such as Get a Customer's Information. Use it as the requiredcustomerIdpath parameter (a string with no default). The UUID35e4cfa9-d87e-45fc-84da-a6bdce2c3330illustrates the ID format; replace it with an ID from your merchant account. - Save the following code as
list_payment_methods.py, runpython3 list_payment_methods.py, and enter your API key and customer ID at the prompts. The example hides your API key and prints only payment method IDs and types rather than the full customer record.
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("Stax secret API key: ").strip()
# Copy the customer's id from a customer API response; no Dashboard path is assumed.
# Example format: 35e4cfa9-d87e-45fc-84da-a6bdce2c3330
customer_id = input("Customer ID: ").strip()
if not api_key or not customer_id:
print("Enter both an API key and a customer ID.", file=sys.stderr)
return 1
url = (
"https://apiprod.fattlabs.com/customer/"
+ quote(customer_id, safe="")
+ "/payment-method"
)
request = Request(
url,
headers={
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
"Accept": "application/json",
},
method="GET",
)
try:
with urlopen(request, timeout=30) as response:
methods = json.load(response)
except HTTPError as error:
guidance = {
400: "Check the customer ID format.",
401: "Check your merchant API key.",
404: "Check that the customer exists.",
422: "Check that the customer ID belongs to this merchant.",
500: "Retry later if the server error persists.",
}
print(
f"HTTP {error.code}: "
+ guidance.get(error.code, "Review the API response status before retrying."),
file=sys.stderr,
)
return 1
except (URLError, TimeoutError, OSError) as error:
print(f"Connection failed: {error}", file=sys.stderr)
return 1
except (ValueError, UnicodeError):
print("The API returned an invalid JSON response.", file=sys.stderr)
return 1
if not isinstance(methods, list) or any(
not isinstance(method, dict)
or not isinstance(method.get("id"), str)
or not isinstance(method.get("method"), str)
for method in methods
):
print("Unexpected response: expected an array of payment methods.", file=sys.stderr)
return 1
if not methods:
print("No saved payment methods.")
return 0
print(f"Retrieved {len(methods)} payment method(s).")
for method in methods:
print(f"{method['id']}: {method['method']}")
return 0
if __name__ == "__main__":
try:
sys.exit(main())
except (EOFError, KeyboardInterrupt):
print("\nInput cancelled.", file=sys.stderr)
sys.exit(1)For the documented sample response, the script prints:
Retrieved 2 payment method(s).
7e3a83ea-6770-41f7-9b28-7ea1a3ae33e7: card
403e043d-2971-4062-adc7-7e64f7882786: bankA successful request returns HTTP 200 with an array of payment method objects. If the array is empty, the script prints No saved payment methods.; if the request fails, it prints an error and exits with a nonzero status.
Usage Guidelines
Customer Validation: Use the customerId path parameter to identify an existing customer associated with your merchant API key. Payment method objects use customer_id to identify the associated customer.
Ordering: Expect the API to return payment methods by created_at in descending order (newest first).
Non-Paginated Response: This endpoint returns all payment methods without pagination.
Important Considerations
Data Privacy: Restrict access to customer payment method details to support your compliance efforts. Consult your legal team regarding specific privacy requirements; this guidance does not establish compliance.
Error Handling: Handle failed requests separately from successful responses with an empty array. Display an empty state when the customer has no saved payment methods; check the customer ID and merchant API key when a request fails.
Security: Do not expose sensitive payment method details to unauthorized parties.
Response Structure
| Code | Response | Reason |
|---|---|---|
| 200 | Success | Returns an array of payment method objects associated with the customer. |
| 400 | Bad Request | Invalid customerId path parameter format. |
| 401 | Unauthorized | Authentication failed. |
| 404 | Not Found | The customer does not exist. |
| 422 | Unprocessable Entity | The selected ID is invalid; inspect the response's id array. |
| 500 | Internal Server Error | An unexpected error occurred on the server. |
