Add metadata to a transaction
Attach up to 20 string key-value pairs to a transaction, which Preczn stores, returns, and forwards to processors that support metadata.
Metadata is your own key-value data on a transaction, such as an order reference or your internal customer ID. Preczn stores the metadata object that you send, returns it on the transaction, and forwards it to connections that accept custom data.
Use metadata when you need to match a Preczn transaction to a record in your system, or to see your own data in a connection's reporting. metadata is optional. A transaction without it processes the same way.
Before you start, make sure you have the merchant's ID and a payment method, such as a token. See Charge a payment.
Metadata limits
The metadata object must be flat: one level of keys, with string values.
| Rule | Limit |
|---|---|
| Number of keys | 20 |
| Key length | 20 characters |
| Value type | String |
| Value length | 255 characters |
Preczn rejects a transaction whose metadata breaks a rule, with this message:
metadata must be a flat object consisting of no more than 20 keys each of a max length of 20 characters, with only string values of a max length of 255 charactersConvert numbers and booleans to strings before you send them, such as "amountDue": "49.99". Flatten nested data into separate keys, each within the 20-character key limit.
Add metadata to a transaction
To add metadata, complete the following steps:
-
Send
POST /v1/transactionswith ametadataobject.{ "merchantId": "mid_test_{merchantId}", "type": "sale", "amount": 1234, "currency": "USD", "payment": { "token": "tkn_test_{tokenId}" }, "metadata": { "orderId": "{yourOrderId}", "customerRef": "{yourCustomerId}" } } -
Check the response. It returns the
metadataobject that you sent.{ "id": "txn_test_{transactionId}", "type": "sale", "amount": 1234, "authorization": { "status": "A" }, "metadata": { "orderId": "{yourOrderId}", "customerRef": "{yourCustomerId}" } }This response is abbreviated. For every field, see Process Transaction.
To read the metadata later, use Get Transaction or List Transactions. Each transaction returns its own metadata.
Metadata on captures, refunds, and voids
A capture, refund, or void is a separate transaction with its own metadata. Its response returns only the metadata that you sent on that request. It doesn't copy the metadata from the original transaction. If the request has no metadata, the response has none.
To keep your reference on every transaction in a series, send metadata on each request.
Metadata at the connection
Preczn forwards metadata only to connections that have a place for custom data, such as custom fields or user fields. Each connection's guide says whether it receives metadata and how. See Supported connections for the guides.
Some connections accept less data than Preczn does:
- Shorter values. When a connection accepts fewer characters than 255, Preczn shortens the value to fit instead of failing the transaction.
- A cap on all custom data. Some connections limit the combined size of all custom fields on a transaction. When the metadata is larger than that limit, the connection can drop all of it and still approve the payment.
The connection's guide lists its limits. If exact values matter in the connection's reporting, keep them short, or send a short reference key and keep the full value in your system.
Updated about 20 hours ago
