Send funds to a customer's card or bank account without a prior transaction using POST /credit.
Audience: Developers integrating server-side credits. A general credit sends funds to an existing payment method without refunding a previous payment.
Use this operation only when the merchant's gateway supports general credits. Direct credits carry increased risk and compliance considerations; prefer a refund against an existing transaction when possible.
Send a test credit
- Create a sandbox account using Test Environments, then copy its secret API key from Stax Pay > Apps > API Keys. Sandbox and live accounts share the same API URL; use a sandbox key to avoid moving real money. Keep this key on your server and out of public repositories.
- Confirm that your sandbox merchant's gateway supports general credits before sending a request.
- Retrieve a saved payment method belonging to that merchant using
GET /payment-method. Copy itsdata[].idvalue and confirm that the payment method can receive credits. Use the payment method ID, not the customer ID or card number. - Save the following example as
credit.pyand runpython3 credit.py. It uses Python 3's standard library, prompts for your credentials, and sends only the two required fields withtotalset to1.00, matching the documented example amount.
Payment method IDs use UUID-shaped strings such as "d3050b19-77d9-44ac-9851-b1d1680a7684". This illustrates the format; enter an ID returned for your own sandbox merchant rather than copying this example value.
import getpass
import json
import sys
import urllib.error
import urllib.request
def main():
# Copy the sandbox secret key from Stax Pay > Apps > API Keys.
api_key = getpass.getpass("Sandbox secret API key: ").strip()
# Use data[].id from GET /payment-method for the same sandbox merchant.
payment_method_id = input("Sandbox payment method ID: ").strip()
if not api_key or not payment_method_id:
print("Enter both an API key and a payment method ID.", file=sys.stderr)
return 1
if input("Confirm you are using a sandbox account (type SANDBOX): ").strip() != "SANDBOX":
print("No request sent.")
return 0
payload = {"payment_method_id": payment_method_id, "total": 1.00}
request = urllib.request.Request(
"https://apiprod.fattlabs.com/credit",
data=json.dumps(payload).encode("utf-8"),
headers={
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
"Accept": "application/json",
},
method="POST",
)
try:
with urllib.request.urlopen(request, timeout=30) as response:
status = response.status
body = response.read().decode("utf-8", errors="replace")
except urllib.error.HTTPError as error:
print(f"HTTP {error.code}: {error.read().decode('utf-8', errors='replace')}", file=sys.stderr)
if error.code == 400:
print("Confirm that the merchant's gateway supports general credits.", file=sys.stderr)
elif error.code == 422:
print("Inspect the validation errors and correct the request fields.", file=sys.stderr)
else:
print("Review the response and verify the credit outcome before retrying.", file=sys.stderr)
return 1
except (urllib.error.URLError, OSError) as error:
print(f"Connection failed: {error}. Verify the credit outcome before retrying.", file=sys.stderr)
return 1
try:
transaction = json.loads(body)
except ValueError:
print(f"HTTP {status}: Empty or invalid JSON. Verify the credit outcome before retrying.", file=sys.stderr)
return 1
if (
not isinstance(transaction, dict)
or transaction.get("success") is not True
or not transaction.get("id")
or transaction.get("type") != "credit"
):
print(f"HTTP {status}: Credit success was not confirmed.", file=sys.stderr)
print(json.dumps(transaction, indent=2), file=sys.stderr)
print("Verify the credit outcome before retrying.", file=sys.stderr)
return 1
print(json.dumps({
"id": transaction["id"],
"success": transaction["success"],
"type": transaction["type"],
"total": transaction.get("total"),
"payment_method_id": transaction.get("payment_method_id"),
}, indent=2))
return 0
if __name__ == "__main__":
try:
sys.exit(main())
except (EOFError, KeyboardInterrupt):
print("\nInput interrupted. If a request was sent, verify the credit outcome before retrying.", file=sys.stderr)
sys.exit(1)A successful request returns HTTP 200 with success: true, type: "credit", and a transaction ID. The script prints these fields from the documented response; your IDs will differ:
{
"id": "85f59225-9a58-4b6e-8aae-f0ffe625e486",
"success": true,
"type": "credit",
"total": 1,
"payment_method_id": "d3050b19-77d9-44ac-9851-b1d1680a7684"
}The example makes one request and does not retry automatically, because repeating a credit can send funds twice. For a timeout, interrupted connection, empty response, or unconfirmed result, verify whether the credit exists before sending another request.
Usage Scenarios
Rebates and Promotions: Issuing funds to a customer as part of a rebate program.
Customer Service Gestures: Providing goodwill credits to resolve customer service issues.
Payouts: Sending funds to customers or partners.
Response Structure
| Code | Response | Reason |
|---|---|---|
| 200 | Success | Returns a transaction object indicating the credit was processed, including transaction ID, type, status, amount, currency, payment method ID, creation timestamp, and any metadata provided. |
| 400 | Bad Request | The merchant's gateway does not support general credits. |
| 422 | Unprocessable Entity | Validation errors occurred. |
Request parameters
Send a JSON object with the required fields first. The example above omits optional metadata to keep the initial request minimal.
| Parameter | Type | Required | Default and constraints |
|---|---|---|---|
payment_method_id | string | Yes | No default is documented. Use an existing payment method belonging to the authenticated merchant and capable of receiving credits. Copy its id from the creation response or data[].id from GET /payment-method. |
total | number (float) | Yes | No default or numeric bounds are documented for this endpoint. The documented example uses 1.00; verify the intended credit amount before submitting. |
meta | object | No | No default is documented. Omit it for the initial test, or include additional information such as a memo string describing the credit. |
Usage Notes
Gateway Support
Verify that the merchant's gateway supports general credits before attempting this operation.
Alternatives
Where possible, issue refunds against existing transactions using the void-or-refund endpoint.
Compliance
Review your anti-money laundering (AML) controls, which help detect and prevent the movement of funds obtained through illegal activity. These controls support your compliance efforts; they do not guarantee compliance. Consult your legal team regarding the specific requirements for issuing credits; this documentation is not legal advice.
Prevent duplicate credits
Idempotency means that retrying the same operation does not create an additional credit. The retrieved request schema for this endpoint does not list idempotency_id; confirm support before relying on it to prevent duplicates.
If support is confirmed, generate an identifier in your application for each new credit and reuse it for retries of that same credit. A UUID-shaped example is "85f59225-9a58-4b6e-8aae-f0ffe625e486"; generate your own value rather than copying this one. You generate this identifier in your application, rather than copying it from the Dashboard.
Until support is confirmed, do not retry automatically. Verify the original credit's outcome before submitting another request.
Additional Considerations
Risk Management
Direct credits carry higher risk. Implement appropriate controls and verification processes.
Customer Communication
Inform customers when credits are issued and provide details about the transaction.
Fees and Costs
Understand any fees associated with issuing credits and factor them into your business processes.
