Update specific fields of a manually created transaction.
Use PUT /transaction/{id}/ to update the customer or invoice associated with a manually created transaction.
Audience: Developers integrating with the Stax API.
Key Features
- Associate a customer or invoice with a manually created transaction.
- Correct supported details without changing the original payment amount or currency.
Update a customer association
- Obtain a merchant API key and keep it out of client-side code and public repositories. Use a sandbox key for testing; sandbox and live keys use the same base URL.
- Copy the transaction's
idfrom an existing transaction response for your merchant account. For example,"6f49149d-69a1-48e6-bec5-d63eb5816118"illustrates the ID format; do not use the example ID as your own. Select a manually created transaction, not a transaction created from an invoice orPOST /charge. - Copy the intended customer's
idfrom an existing customer object, such as thecustomer.idfield in a transaction response. The documented example is"d45ee88c-8b27-4be8-8d81-77dda1b81826"; use your intended customer's actual ID. - Run the following example with Python 3. It uses only the standard library, prompts for your values, and sends only
customer_idto limit the update to the customer association.
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 the id from an existing transaction response for this merchant.
transaction_id = input("Manually created transaction ID: ").strip()
# Use the intended customer's id from an existing customer object.
customer_id = input("Customer ID to associate: ").strip()
if not all((api_key, transaction_id, customer_id)):
sys.exit("Provide an API key, transaction ID, and customer ID.")
request = Request(
"https://apiprod.fattlabs.com/transaction/"
+ quote(transaction_id, safe="") + "/",
data=json.dumps({"customer_id": customer_id}).encode("utf-8"),
headers={
"Authorization": "Bearer " + api_key,
"Accept": "application/json",
"Content-Type": "application/json",
},
method="PUT",
)
try:
with urlopen(request, timeout=30) as response:
transaction = json.load(response)
except HTTPError as error:
if error.code == 422:
details = error.read().decode("utf-8", errors="replace")
sys.exit("Update rejected. Check the IDs and confirm the "
"transaction is manually created. API response: " + details)
if error.code == 401:
sys.exit("Authentication failed. Check your merchant API key.")
sys.exit(f"Update failed with HTTP {error.code}.")
except (URLError, TimeoutError, OSError) as error:
sys.exit(f"Connection failed: {error}. Retrieve the transaction "
"to check its current association before retrying.")
except (ValueError, UnicodeError):
sys.exit("The API did not return valid JSON. Retrieve the "
"transaction to verify the association before retrying.")
if not isinstance(transaction, dict):
sys.exit("Unexpected response format. Retrieve the transaction "
"to verify the association.")
if (transaction.get("id") != transaction_id
or transaction.get("customer_id") != customer_id):
sys.exit("The response did not confirm the requested association. "
"Retrieve the transaction and check its customer_id.")
print("Customer association confirmed.")
print(json.dumps({"id": transaction["id"],
"customer_id": transaction["customer_id"]}, indent=2))
if __name__ == "__main__":
main()After HTTP 200, the script verifies that the returned id and customer_id match your inputs. For the IDs shown above, the expected output is:
Customer association confirmed.
{
"id": "6f49149d-69a1-48e6-bec5-d63eb5816118",
"customer_id": "d45ee88c-8b27-4be8-8d81-77dda1b81826"
}Your output contains your own IDs. Confirming the association verifies this update; it does not indicate whether the original payment succeeded.
Usage Notes
Immutable Fields: Certain fields, such as amount, currency, status, and type cannot be modified.
Validation: Send a JSON object with the supported fields below. The endpoint specification does not declare default values or additional format constraints for these strings.
| Parameter | Location | Type | Required | Value |
|---|---|---|---|---|
id | Path | string | Yes | ID of the manually created transaction to update. |
customer_id | JSON body | string | No | ID of the customer to associate with the transaction. |
invoice_id | JSON body | string | No | ID of the invoice to associate with the transaction. |
Response Structure
| Code | Response | Reason |
|---|---|---|
| 200 | Success | Returns the updated transaction object. Verify that the returned association matches your request. |
| 400 | Bad Request | Invalid request parameters or attempting to modify immutable fields. |
| 401 | Unauthorized | Authentication failed. |
| 404 | Not Found | Transaction ID does not exist or cannot be updated. |
| 422 | Validation Error | Check the response body for invalid values or this transaction is immutable. Use a manually created transaction for this operation. |
| 500 | Internal Server Error | An unexpected error occurred on the server. |
Important Considerations
Recommended recordkeeping: Keep a history of transaction changes (an audit trail) so you can review corrections later. This recommendation supports your compliance efforts; it does not replace applicable compliance requirements. Consult your legal team regarding specific requirements.
Data Integrity: Preserve the meaning of the original transaction when correcting its customer or invoice association.
Customer Communication: If changes impact the customer (e.g., receipt information), consider notifying them accordingly.
