Payment Metadata
metadata is key-value data you can attach when you create a payment, to link it to a record in your own system (for example an order reference or a branch code). You send it in the payment create request and read it back in the payment query. This page describes the rules of the field, its error codes, and common situations.
Use in the request
Section titled “Use in the request”metadata is an optional field of the POST /v1/payments request. Values can only be strings.
{ "amount": 125050, "partnerTxCode": "ORD-2026-8841", "terminalId": "trm_3Kd9x", "returnUrl": "https://yourstore.example/payment/result", "metadata": { "orderRef": "ORD-2026-8841", "store": "izmir-01" }}The create response (201 and 200) does not include metadata. You read the data you sent from the Get Payment endpoint.
Rules and limits
Section titled “Rules and limits”| Rule | Value |
|---|---|
| Field type | A key-value object. Every value must be a string; numbers, booleans, null, arrays, and nested objects are not accepted. |
| Number of rows | At most 20 keys. |
| Key name | 1-40 characters. Starts with an English letter; contains only English letters, digits, underscore (_), hyphen (-), and dot (.). Each key is used once. |
| Value length | At most 255 Unicode characters (code points). Bytes and UTF-16 units are not what is counted. |
| Empty value | An empty value, or one made only of spaces, is not accepted. |
| Characters | Control characters, invisible formatting characters (for example the zero-width space), and digit-like characters such as superscripts, fractions, or circled digits are not accepted. |
| Total size | The sum of the UTF-8 byte counts of all keys and values is at most 2048 bytes. Non-ASCII characters take more than one byte. |
| Immutability | metadata is written when the payment is created and cannot be updated afterward. |
These format and limit rules apply whether content screening is on or off. A violation returns 400 metadata_invalid.
You send metadata only in the payment create request. Payment links do not accept metadata.
Data you cannot write
Section titled “Data you cannot write”metadata is for tracking; it must not carry personal data, card data, or account numbers. Content screening is on by default for accounts. In this default screening mode, LydiaGate checks for obvious forms and rejects them with 400 metadata_sensitive_data_not_allowed:
- Key names that name an identity number, tax number, phone number, e-mail address, full name, card data, account data, or access credentials such as a password or API key (for example
phone,email,apiKey, orstoreKey).expiryis rejected only when it is the whole key; names such ascouponExpiryare allowed. - Values that contain a LydiaGate API key, a phone number, an e-mail address, or an IBAN. The masked visible ID of an API key (the shortened form shown in the panel) is not rejected; the full key is.
- Numbers that cannot be told apart from a national ID number or a card number. A digits-only value of 13-19 digits (spaces, hyphens, and dots are not counted) is rejected by default. Some digits-only values of 11 and 12 digits are treated as an ID or phone number and rejected.
The check catches obvious forms; the content of metadata is your responsibility.
Reading
Section titled “Reading”metadata appears in the payment query response: GET /v1/payments/{paymentCode} and GET /v1/payments?partnerTxCode=…. The data you sent returns as an object; keys are listed in ascending order by name (the order you sent is not preserved). For payments created without metadata, the field is present in the response with the value null. If the feature is turned off later, previously stored metadata can still be read.
metadata is not part of these surfaces: the create response, payment lists, and the webhook body. When you receive a webhook, read the payment’s metadata from the query endpoint.
Replay safety
Section titled “Replay safety”metadata is part of the partnerTxCode idempotency comparison. The comparison only happens while an active payment holds the same partnerTxCode. A 200 replay needs two more conditions:
- The request comes from the same interface that created the payment (a payment created through the API is replayed through the API).
- The other compared fields are also the same (
terminalId,amount,installment,captureMode). For the full list, see what counts as “the same request”.
| Scenario | Response |
|---|---|
Active payment + same request with the same metadata (key order may differ) |
200 OK + idempotentReplay: true |
Active payment + different metadata (a different value or key, or metadata added or removed) |
409 duplicate_partner_tx_code |
Active payment + same metadata, but another compared field (terminalId, amount, installment, captureMode) or the interface differs |
409 duplicate_partner_tx_code |
Active payment + only a field outside the comparison differs (e.g. returnUrl, description) |
200 OK + idempotentReplay: true (the first payment’s values stay in effect) |
The earlier payment is failed or expired |
The code is free again. The same request creates a new payment: 201 Created. The metadata is stored again for the new payment. |
When you get 409, do not generate a new partnerTxCode; doing so risks a second charge for the same order. Read the existing payment with GET /v1/payments?partnerTxCode=….
Errors
Section titled “Errors”Three error codes are specific to the metadata field:
| Code | HTTP | Meaning |
|---|---|---|
metadata_not_enabled |
422 |
You sent a non-empty metadata, but the feature is not enabled for your account. No payment is created. |
metadata_invalid |
400 |
The format or limits of metadata are invalid. The error.metadataViolation field gives the reason. |
metadata_sensitive_data_not_allowed |
400 |
In the default screening mode, a key name or a value matched the rule on data you cannot write. The error.metadataViolation field gives the reason. This code is not returned if content screening is off for your account. |
Format and limit errors (metadata_invalid) are returned even if the feature is not enabled for your account, and whether content screening is on or off.
The metadata_invalid and metadata_sensitive_data_not_allowed responses carry two extra fields. These fields appear only for these two codes; other errors do not include them in the body.
{ "error": { "code": "metadata_sensitive_data_not_allowed", "message": "Payment metadata rejected (card_number): …", "traceId": "trc_9f12ab", "metadataViolation": "card_number", "metadataIndex": 2 }}| Field | Description |
|---|---|
metadataViolation |
The reason for the rejection; one of the 17 values in the table below. |
metadataIndex |
Which member of the metadata object you sent the rejection belongs to. It is 0-based and follows the order you sent (0-19). It appears only for rejections that belong to a single member; it does not appear for rejections about the object as a whole (the “None” rows in the table). |
The response does not echo the offending key or value; the message text is fixed for each rejection and is in English. Locate the faulty row with metadataIndex in the object you sent.
If a request has more than one violation, the response reports only one. Which one is returned is not fixed; fix the violation and resend the request. New metadataViolation values may be added in the future; for a value you do not recognize, act on error.code.
metadataViolation |
code |
metadataIndex |
Meaning |
|---|---|---|---|
not_an_object |
metadata_invalid |
None | metadata must be a key-value object. |
repeated_member |
metadata_invalid |
None | metadata was sent more than once in the request. |
too_many_keys |
metadata_invalid |
None | More than 20 keys were sent. |
duplicate_key |
metadata_invalid |
Present | The same key was used more than once. |
key_invalid |
metadata_invalid |
Present | The key name breaks the rule (does not start with a letter, contains an invalid character, or exceeds 40 characters). |
value_not_string |
metadata_invalid |
Present | The value is not a string. |
value_blank |
metadata_invalid |
Present | The value is empty or made only of spaces. |
value_too_long |
metadata_invalid |
Present | The value exceeds 255 Unicode characters. |
value_invalid_characters |
metadata_invalid |
Present | The value contains invisible or unsupported characters. |
total_size_exceeded |
metadata_invalid |
None | The total size of keys and values exceeds 2048 bytes. |
forbidden_key |
metadata_sensitive_data_not_allowed |
Present | The key name names an identity, tax number, phone, e-mail, full name, card, account data, or an access credential (password, API key). |
national_id |
metadata_sensitive_data_not_allowed |
Present | The value contains a number that cannot be told apart from a national ID number. Use a separate reference instead of the number. |
card_number |
metadata_sensitive_data_not_allowed |
Present | The value is a 13-19 digit number or contains a number that cannot be told apart from a card number. Use a separate reference instead of the number. |
phone_number |
metadata_sensitive_data_not_allowed |
Present | The value contains a phone number. |
email |
metadata_sensitive_data_not_allowed |
Present | The value contains an e-mail address. |
iban |
metadata_sensitive_data_not_allowed |
Present | The value contains an IBAN. |
api_key |
metadata_sensitive_data_not_allowed |
Present | The value contains an API key, which must not be sent. |
For the general list of error codes, see Error Codes.