Transactions
A transaction is the payable record of a sale. It holds the lines, the buyer, the amounts, and the tax. Every payment collects a transaction.
Read Transactions for the model and the lifecycle. For a walkthrough, read Build a transaction.
The transaction object#
A payable record. It is the source of truth for the amount.
Attributes
- idstring
- accountIdstring
The customer of the transaction. Absent when the transaction has none.
A caller-supplied reference for the transaction. Absent when there is none.
- originstring
Where the transaction came from.
One of:
checkout,account_manual,api - amountSourcestring
Whether the total comes from a supplied amount or from lines.
One of:
amount_only,line_items - currencystring
An ISO 4217 alphabetic currency code.
Pattern
^[A-Z]{3}$. - amountsobject
The subtotal, discount, net, tax, and total of a transaction, in minor units.
- taxStatusstring
not_applicable: no tax applies.pending: tax applies, but Merxian does not have the buyer details to calculate it.calculated:amounts.taxholds the result.One of:
not_applicable,pending,calculated The promotion code applied to the transaction. Absent when there is none.
- capturedAmountinteger
The amount captured by payments, in minor units.
- refundedAmountinteger
The refunded amount, in minor units.
- netCollectedAmountinteger
The captured amount less refunds, in minor units.
- adjustedRequiredAmountinteger
The required amount after adjustments, in minor units.
- remainingCollectibleAmountinteger
What is still collectible, in minor units.
- statusstring
The state of a transaction.
draftaccepts changes.readyis finalized and collectible.completedandcanceledare final.One of:
draft,ready,processing,completed,past_due,canceled - paymentStatusstring
The payment progress of the transaction.
One of:
unpaid,pending,partially_paid,paid,partially_refunded,refunded - lineItemsarray of objects
The lines of the transaction. Empty when the transaction has none.
Child attributes of
lineItems- idstring
- namestring
The name of the product, from the catalog.
The description of the product, from the catalog. Null when the product has none.
- quantityinteger
- taxBehaviorstring
Whether the unit amount includes the tax or excludes it.
One of:
inclusive,exclusive - unitAmountinteger
Minor units.
- subtotalinteger
Minor units.
- discountinteger
Minor units.
- netinteger
Minor units.
- taxinteger
Minor units.
- totalinteger
Minor units.
The product the line resolves to.
The frozen catalog price.
The tax code applied to the line. Absent when there is none.
- adjustmentsarray of objects
The adjustments of the transaction, oldest first. Empty when it has none.
Child attributes of
adjustments- idstring
- typestring
The caller-supplied adjustment type.
- amountinteger
The signed amount, in minor units.
- changesCollectibleAmountboolean
True when the adjustment changes what is still collectible.
Why the adjustment was made. Absent when there is no reason to give.
- effectiveAtstring (date-time)
- actorTypestring
Who made the adjustment, for example
accountorsystem. The ID of the actor, when there is one.
A caller-supplied reference for the adjustment. Absent when there is none.
- createdAtstring (date-time)
When the transaction is due. Absent when it has no due date.
- revisioninteger
Goes up by one each time the transaction changes. Use it with
If-Match. - createdAtstring (date-time)
When the transaction was created.
- updatedAtstring (date-time)
When the transaction was last updated.
- metadataobject
Your own key-value pairs. Empty when the transaction has none.
The response can include fields that this page does not list. Ignore fields that you do not know.
Create a transaction#
POST/
Creates a transaction in the draft state. Give either amount or lines, not both. A draft can change. Finalize it before you collect it.
A retry with the same Idempotency-Key and the same body returns the first result.
Requires the transactions:write scope.
Headers
A unique key for this request, at most 200 characters. A retry with the same key and body returns the first result.
At most 200 characters.
Request body
An ISO 4217 alphabetic currency code.
Pattern
^[A-Z]{3}$.- amountinteger
The gross amount, in minor units. Use it without
lines. - linesarray of objects
The commercial lines. Use them without
amount.Child attributes of
lines- catalogPriceIdstring
A catalog price of the account to resolve the line from.
- productIdstring
A product of the account to resolve the line from.
- customerIdstring
A customer of your account. Values in
buyeroverride the stored customer values for this transaction. - externalReferencestring
A caller-supplied reference for the transaction.
- buyerobject
One-time payer evidence, frozen when no reusable customer is referenced.
- billingAddressobject
- metadataobject
Your own key-value pairs. At most 50 entries. A key has at most 64 characters, a value at most 1024.
- promotionCodestring
A promotion code of the account to apply.
Returns
Errors
| Status | Meaning |
|---|---|
| 400 | The request is not valid. See the error body for the field at fault. |
| 401 | The API key is missing, malformed, revoked, or unknown. |
| 403 | The API key does not hold the scope that this operation requires. |
| 409 | The request conflicts with the current state of the resource, or the idempotency key was used with a different request. |
| 422 | The request is valid, but Merxian cannot apply it to the current data. |
| 500 | An unexpected error occurred. Retry with the same idempotency key. |
| 502 | Merxian could not complete the request. Retry with the same idempotency key. |
| 503 | Merxian could not verify the API key. Retry later. |
The error reference lists the codes in each error body.
Webhook events
This call can cause these events, later and in any order:
Preview a transaction#
POST/
Calculates the transaction that the same create request would make, with its amounts, discounts, and tax. It stores nothing, so it needs no Idempotency-Key.
Requires the transactions:read scope.
Request body
An ISO 4217 alphabetic currency code.
Pattern
^[A-Z]{3}$.- amountinteger
The gross amount, in minor units. Use it without
lines. - linesarray of objects
The commercial lines. Use them without
amount.Child attributes of
lines- catalogPriceIdstring
A catalog price of the account to resolve the line from.
- productIdstring
A product of the account to resolve the line from.
- customerIdstring
A customer of your account. Values in
buyeroverride the stored customer values for this transaction. - externalReferencestring
A caller-supplied reference for the transaction.
- buyerobject
One-time payer evidence, frozen when no reusable customer is referenced.
- billingAddressobject
- metadataobject
Your own key-value pairs. At most 50 entries. A key has at most 64 characters, a value at most 1024.
- promotionCodestring
A promotion code of the account to apply.
Returns
Errors
| Status | Meaning |
|---|---|
| 400 | The request is not valid. See the error body for the field at fault. |
| 401 | The API key is missing, malformed, revoked, or unknown. |
| 403 | The API key does not hold the scope that this operation requires. |
| 422 | The request is valid, but Merxian cannot apply it to the current data. |
| 500 | An unexpected error occurred. Retry with the same idempotency key. |
| 502 | Merxian could not complete the request. Retry with the same idempotency key. |
| 503 | Merxian could not verify the API key. Retry later. |
The error reference lists the codes in each error body.
Retrieve a transaction#
GET/
Returns one transaction. The response does not include payments. Use List the payments of a transaction to read them.
A transaction that does not exist, or that belongs to another account, returns 404.
Requires the transactions:read scope.
Path parameters
The transaction id.
Returns
Errors
| Status | Meaning |
|---|---|
| 401 | The API key is missing, malformed, revoked, or unknown. |
| 403 | The API key does not hold the scope that this operation requires. |
| 404 | The resource does not exist, or it belongs to another account. |
| 500 | An unexpected error occurred. Retry with the same idempotency key. |
| 502 | Merxian could not complete the request. Retry with the same idempotency key. |
| 503 | Merxian could not verify the API key. Retry later. |
The error reference lists the codes in each error body.
List transactions#
GET/
Returns one page of your transactions, newest first.
Requires the transactions:read scope.
Query parameters
- statusstring
Keep only transactions in this state, for example
draftorcompleted. An unknown value fails the request with400.One of:
draft,ready,processing,completed,past_due,canceled - customerIdstring
Keep only transactions of this customer.
- fromDatestring (date-time)
Keep only transactions created at or after this ISO-8601 instant.
- toDatestring (date-time)
Keep only transactions created at or before this ISO-8601 instant.
- limitinteger
How many transactions to return. Defaults to 20.
1 to 100. Default
20. - cursorstring
An opaque cursor taken from a previous response's
pagination.nextCursor.
Returns
200A page of transaction objects, in data, with pagination.
Errors
| Status | Meaning |
|---|---|
| 400 | The request is not valid. See the error body for the field at fault. |
| 401 | The API key is missing, malformed, revoked, or unknown. |
| 403 | The API key does not hold the scope that this operation requires. |
| 500 | An unexpected error occurred. Retry with the same idempotency key. |
| 502 | Merxian could not complete the request. Retry with the same idempotency key. |
| 503 | Merxian could not verify the API key. Retry later. |
The error reference lists the codes in each error body.
Update a draft transaction#
PATCH/
Replaces the commercial content of a draft transaction. You cannot change a transaction after it is finalized.
To prevent lost updates, send the revision that you last read, in If-Match as W/"<revision>" or in expectedRevision. If the transaction changed after that revision, the request returns 409 with the code revision_conflict.
You cannot change a transaction from amount to lines, or from lines to amount.
Requires the transactions:write scope.
Path parameters
The transaction id.
Headers
A unique key for this request, at most 200 characters. A retry with the same key and body returns the first result.
At most 200 characters.
- If-Matchstring
The expected revision as an entity tag, for example
W/"3".
Request body
- expectedRevisioninteger
The revision the caller last saw. The update is refused when it moved on.
- amountinteger
- linesarray of objects
Child attributes of
lines- catalogPriceIdstring
A catalog price of the account to resolve the line from.
- productIdstring
A product of the account to resolve the line from.
- customerIdstring
A customer of your account. Values in
buyeroverride the stored customer values for this transaction. - externalReferencestring
- buyerobject
One-time payer evidence, frozen when no reusable customer is referenced.
- billingAddressobject
- metadataobject
The same rules as on create.
- promotionCodestring
Returns
Errors
| Status | Meaning |
|---|---|
| 400 | The request is not valid. See the error body for the field at fault. |
| 401 | The API key is missing, malformed, revoked, or unknown. |
| 403 | The API key does not hold the scope that this operation requires. |
| 404 | The resource does not exist, or it belongs to another account. |
| 409 | The request conflicts with the current state of the resource, or the idempotency key was used with a different request. |
| 422 | The request is valid, but Merxian cannot apply it to the current data. |
| 500 | An unexpected error occurred. Retry with the same idempotency key. |
| 502 | Merxian could not complete the request. Retry with the same idempotency key. |
| 503 | Merxian could not verify the API key. Retry later. |
The error reference lists the codes in each error body.
Finalize a transaction#
POST/
Moves a draft transaction to ready. Merxian calculates the final amounts, discounts, and tax, and freezes them with the buyer and line details. After this, the payable amount does not change, except through an adjustment.
A ready transaction can be collected.
Requires the transactions:write scope.
Path parameters
The transaction id.
Headers
A unique key for this request, at most 200 characters. A retry with the same key and body returns the first result.
At most 200 characters.
Returns
Errors
| Status | Meaning |
|---|---|
| 400 | The request is not valid. See the error body for the field at fault. |
| 401 | The API key is missing, malformed, revoked, or unknown. |
| 403 | The API key does not hold the scope that this operation requires. |
| 404 | The resource does not exist, or it belongs to another account. |
| 409 | The request conflicts with the current state of the resource, or the idempotency key was used with a different request. |
| 422 | The request is valid, but Merxian cannot apply it to the current data. |
| 500 | An unexpected error occurred. Retry with the same idempotency key. |
| 502 | Merxian could not complete the request. Retry with the same idempotency key. |
| 503 | Merxian could not verify the API key. Retry later. |
The error reference lists the codes in each error body.
Webhook events
This call can cause these events, later and in any order:
Cancel a transaction#
POST/
Cancels a transaction that has not completed. A canceled transaction cannot be collected.
You cannot cancel a transaction that has collected money or that has a payment in progress. Such a request returns 409 with the code not_cancelable.
Requires the transactions:write scope.
Path parameters
The transaction id.
Headers
A unique key for this request, at most 200 characters. A retry with the same key and body returns the first result.
At most 200 characters.
Request bodyOptional
- reasonstring
Why the transaction is canceled. Absent when there is no reason to give.
Returns
Errors
| Status | Meaning |
|---|---|
| 400 | The request is not valid. See the error body for the field at fault. |
| 401 | The API key is missing, malformed, revoked, or unknown. |
| 403 | The API key does not hold the scope that this operation requires. |
| 404 | The resource does not exist, or it belongs to another account. |
| 409 | The request conflicts with the current state of the resource, or the idempotency key was used with a different request. |
| 500 | An unexpected error occurred. Retry with the same idempotency key. |
| 502 | Merxian could not complete the request. Retry with the same idempotency key. |
| 503 | Merxian could not verify the API key. Retry later. |
The error reference lists the codes in each error body.
Webhook events
This call can cause these events, later and in any order:
Add an adjustment#
POST/
Records a signed adjustment on a finalized transaction. When changesCollectibleAmount is true, the adjustment changes adjustedRequiredAmount and remainingCollectibleAmount.
A draft transaction returns 409. Change a draft with Update a draft transaction instead.
Requires the transactions:write scope.
Path parameters
The transaction id.
Headers
A unique key for this request, at most 200 characters. A retry with the same key and body returns the first result.
At most 200 characters.
Request body
The adjustment type. Must not be blank.
The signed amount, in minor units.
True when the adjustment changes what is still collectible.
- reasonstring
Why the adjustment is made.
- effectiveAtstring (date-time)
When the adjustment takes effect. Absent means now.
- sourceReferencestring
A caller-supplied reference for the adjustment.
- correctionReasonstring
Makes the adjustment a commercial correction with a decided tax split. Absent for a plain adjustment.
One of:
refund,credit_note,price_adjustment,return,bad_debt_relief,tax_classification_correction
Returns
Errors
| Status | Meaning |
|---|---|
| 400 | The request is not valid. See the error body for the field at fault. |
| 401 | The API key is missing, malformed, revoked, or unknown. |
| 403 | The API key does not hold the scope that this operation requires. |
| 404 | The resource does not exist, or it belongs to another account. |
| 409 | The request conflicts with the current state of the resource, or the idempotency key was used with a different request. |
| 500 | An unexpected error occurred. Retry with the same idempotency key. |
| 502 | Merxian could not complete the request. Retry with the same idempotency key. |
| 503 | Merxian could not verify the API key. Retry later. |
The error reference lists the codes in each error body.
Webhook events
This call can cause these events, later and in any order: