# Cancel a transaction This endpoint allows you to cancel a scheduled transaction using the reference ID obtained from its creation response. The cancellation is intended to allow the interruption of incorrect or undesired payment operations before financial settlement and is irreversible, in order to preserve operational integrity and ensure full traceability for auditing purposes. Only transactions that have not yet been processed ("pending" and "in_process") can be canceled. In case of success, the request will return a response with status 204. **PUT** `/v1/payouts/{payout_id}/transactions/{transaction_id}/cancel` ## Request parameters ### Header - `X-Idempotency-Key` (string, required) This feature allows you to safely retry requests without the risk of accidentally performing the same action more than once. This is useful for avoiding errors, such as creating two identical transactions, for example. To ensure that each request is unique, it's important to use an exclusive value in the header of your request. We suggest using a UUID V4 or random strings. It is important to note that, starting from 2024/01/01, sending this parameter will become mandatory in all requests. - `X-signature` (string, required) Request signature with the encrypted body in base 64 with the public and private keys of the integrator. It is required only in a productive environment. - `X-enforce-signature` (boolean, optional) Boolean to indicate whether the integrator will or will not send the signature. It must be "false" for test environments, and "true" for production environments, when the signature is mandatory. - `X-test-token` (boolean, optional) Boolean to indicate if the request will be a test ("true") or not ("false"). Always required as "true" when it's a test request. When using this header, it's possible to use "X-enforce-signature" as "true" and use "X-signature" to test the encrypted body validation. ### Path - `payout_id` (string, required) Identifier of the payout for which you wish to consult the transaction, returned in the response to its creation within the "id" field - `transaction_id` (string, required) Identifier of the transaction for which you wish to consult, returned in the response to its creation within the "id" field - `comments` (string, optional) Clear justification for the cancellation (avoid including sensitive personal information). This field is fundamental for history and audit. - `deleted_by` (string, optional) Unique identification of who performed the cancellation (user, system, etc). This field is fundamental for history and audit. ## Response parameters This endpoint has no response body. ## Errors | Status | Error | Description | | ------- | ------- | ----------- | | 400 | invalid_payout_id | Invalid data was sent in the request body. The payout was not found. Try sending the request again, validating all fields. | | 400 | invalid_transaction_id | Invalid data was sent in the request body. The transaction was not found. Try sending the request again, validating all fields. | | 400 | invalid_signature | Invalid data was sent in the request body. Check if the secret was generated correctly and is registered with Mercado Pago. Also check if the body you are sending is the one that was encrypted. | | 400 | idempotency_key_required | Invalid data was sent in the request body. The idempotency key ("idempotency_key") is missing. Try sending the request again, validating all fields. | | 401 | invalid_token | The value sent as Access Token is incorrect. Please check and try again with the correct value. | | 403 | forbidden | No permission to access the resource. | | 404 | not_found | Payout not found. Please check if you provided the correct payout ID. | | 412 | precondition_failed | The status of the transaction does not allow its cancelation. Only transactions with "status=pending" or "status=in_process" can be canceled. | | 500 | internal_server_error | An unexpected error occurred on the server. Try the request again. | | 502 | bad_gateway | An error occurred in the integration with an external service. Try the request again. | ## Request example ### cURL ```bash curl -X PUT \ 'https://api.mercadopago.com/v1/payouts/{payout_id}/transactions/{transaction_id}/cancel' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer ' \ -d '{ "comments": "delete because the payment was canceled", "deleted_by": "user_123" }' ```