# Create cancellation This endpoint allows the cancellation of a purchase for a specific payment, provided the payment status is `in_process`, `pending`, or `authorized`. Upon success, the request will return a status code 200. **PUT** `/v1/payments/{payment_id}` ## Request parameters ### Path - `payment_id` (string, required) Payment Identification Number (ID). - `status` (String, optional) Payment Status - This field exclusively accepts the status `canceled`. ## Response parameters - `id` (number, optional) Payment identifier. - `date_created` (string, optional) Cancelation creation date. - `date_approved` (string, optional) Cancelation approved date. - `date_last_updated` (string, optional) Last updated date. - `date_of_expiration` (string, optional) Expiration date. - `money_release_date` (string, optional) Money release date. - `operation_type` (string, optional) Operation type. - `issuer_id` (number, optional) Issuer identifier. - `payment_method_id` (string, optional) Payment method identifier. - `payment_type_id` (string, optional) Payment type identifier. - `status` (string, optional) Cancellation status. - `status_detail` (string, optional) Status detail - This field provides the details of the reason for the payment cancellation and is directly linked to the `status` parameter. - `currency_id` (string, optional) Currency identifier. - `description` (string, optional) Description of the canceled product/service. - `live_mode` (string, optional) This parameter indicates Whether the chargeback will be processed in sandbox or in production mode. If TRUE, then the chargeback will be processed in production mode. If FALSE, then the chargeback will be processed in sandbox mode. - `sponsor_id` (string, optional) Sponsor identifier. - `authorization_code` (string, optional) Authorization code. - `money_release_schema` (string, optional) Money release schema. - `taxes_amount` (number, optional) Tax amount. - `counter_currency` (string, optional) Counter currency. - `brand_id` (string, optional) Brand identifier. - `shipping_amount` (number, optional) Shipping amount. - `pos_id` (string, optional) POS identifier. - `store_id` (string, optional) Store identifier. - `integrator_id` (string, optional) Integrator identifier. - `platform_id` (string, optional) Platform identifier. - `corporation_id` (string, optional) Corporation identifier. - `collector_id` (number, optional) Collector number identifier. - `payers` (array, optional) List of payers. - `payers[].first_name` (string, optional) First name. - `payers[].last_name` (string, optional) Last name. - `payers[].email` (string, optional) Payer e-mail. - `payers[].type` (string, optional) Payer type. - `payers[].identification` (array, optional) List of identification. - `payers[].identification[].number` (string, optional) Identification number. - `payers[].identification[].type` (string, optional) Identification type. - `payers[].phone` (array, optional) List of phones. - `payers[].phone[].area_code` (string, optional) Area code. - `payers[].phone[].number` (string, optional) Phone number. - `payers[].phone[].extension` (string, optional) Extension - `payers[].entity_type` (string, optional) Entity type. - `payers[].id` (string, optional) Identifier - `payers[].operator_id` (string, optional) Operator identifier. - `marketplace_owner` (string, optional) Marketplace owner. - `metadata` (array, optional) Contains payment metadata that is sent to us in the payment post - `additional_info` (array, optional) List of additional information. - `additional_info[].items` (array, optional) List of items. - `additional_info[].items[].id` (string, optional) Identifier - `additional_info[].items[].title` (string, optional) Item title. - `additional_info[].items[].description` (string, optional) Description - `additional_info[].items[].picture_url` (string, optional) Picture URL. - `additional_info[].items[].category_id` (string, optional) Category identifier. - `additional_info[].items[].quantity` (string, optional) Quantity - `additional_info[].items[].unit_price` (string, optional) Unit pric. - `order` (array, optional) List of orders. - `order[].type` (string, optional) Order type - `order[].id` (string, optional) Order identifier. - `external_reference` (string, optional) External reference. - `transaction_amount` (number, optional) Transaction amount. - `transaction_amount_refunded` (number, optional) Transaction amount refunded. - `coupon_amount` (number, optional) Coupon amount. - `differential_pricing_id` (string, optional) Differential pricing identifier. - `deduction_schema` (string, optional) Deduction schema. - `barcode` (array, optional) List of barcode. - `barcode[].content` (string, optional) Barcode numbering. - `installments` (number, optional) Number of installments. - `transaction_details` (array, optional) List of transaction details. - `transaction_details[].payment_method_reference_id` (string, optional) Payment method reference identifier. - `transaction_details[].verification_code` (string, optional) Verification code. - `transaction_details[].net_received_amount` (number, optional) Net received amount. - `transaction_details[].total_paid_amount` (number, optional) Total paid amount. - `transaction_details[].overpaid_amount` (number, optional) Overpaid amount. - `transaction_details[].external_resource_url` (string, optional) External resource url. - `transaction_details[].installment_amount` (number, optional) Installment amount. - `transaction_details[].financial_institution` (string, optional) Financial institution. - `transaction_details[].payable_deferral_period` (string, optional) Payable deferral period. - `transaction_details[].acquirer_reference` (string, optional) Acquirer reference. - `fee_details` (array, optional) List of fee details. - `charges_details` (array, optional) List of charges details. - `captured` (boolean, optional) Captured flag. - `binary_mode` (boolean, optional) Binary mode flag. - `call_for_authorize_id` (string, optional) Call for authorize identifier - `statement_descriptor` (string, optional) Statement descriptor. - `card` (array, optional) List of cards. - `notification_url` (string, optional) Notification URL. - `refunds` (array, optional) List of refunds. - `processing_mode` (string, optional) Processing mode. - `merchant_account_id` (string, optional) Merchant account identifier. - `merchant_number` (string, optional) Merchant number. - `acquirer_reconciliation` (array, optional) List of acquirer reconciliation. - `point_of_interaction` (array, optional) List of point of interaction. - `point_of_interaction[].type` (string, optional) Type. - `point_of_interaction[].business_info` (array, optional) List of business information. - `point_of_interaction[].business_info[].unit` (string, optional) Unit. - `point_of_interaction[].business_info[].sub_unit` (string, optional) Sub unit ## Errors | Status | Error | Description | | ------- | ------- | ----------- | | 400 | 2018 | The action requested is not valid for the current payment state - This error occurs when an attempt is made to change a payment's status to canceled when the initial status is not 'in_process', 'pending', or 'authorized. | | 400 | 2016 | Invalid Status for Update - This error occurs when, for example, an attempt is made to change the status of a payment from `in_process` to `approved`. This request only accepts the status `canceled`. Please review the parameter submitted and make a new request with the correct value. | | 400 | 4017 | Status attribute can't be null - If this error appears, please review the `status` parameter to ensure that it is set to `canceled` and not left empty. Confirm the status is correctly populated before submitting a new request. | | 401 | 5 | Must provide your access token - This error is displayed when an attempt is made to make a request without sending the Access Token. Please check the request parameters and ensure the necessary information is provided. | | 401 | Unauthorized | Invalid access token - If this error appears, please review the Access Token provided in your request to ensure it is correct. After verifying the token, submit a new request. | | 403 | 4 | Forbidden - The caller is not authorized to access this resource. This error occurs when attempting to change a payment status from `authorized` to `approved`. The same issue arises when trying to change a payment status from `in_process` to `rejected` or `approved`, or from `authorized` to `approved`. In this case, ensure the status being set is strictly `canceled` and submit a new request. | | 404 | 2000 | Payment not found - This error is returned when the payment ID entered is incorrect or does not exist. Please review the `payment_id` parameter and ensure that the number entered is correct. | ## Request example ### cURL ```bash curl -X PUT \ 'https://api.mercadopago.com/v1/payments/{payment_id}' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer ' \ -d '{ "status": "canceled" }' ``` ### Node.js ```javascript import MercadoPago, { Payment } from 'mercadopago'; const client = new MercadoPago({ accessToken: 'TEST-703********22370-01********2405a0c3********7232f7a5********0082888' }); const payment = new Payment(client); payment.cancel({ id: '18552260055' }).then(console.log).catch(console.log); ``` ### PHP ```php "); $client = new PaymentRefundClient(); $payment = $client->cancel(18552260055); ?> ``` ### Python ```python sdk = mercadopago.SDK("ENV_ACCESS_TOKEN") payment_data = { "status": "canceled" } payment_response = sdk.payment().update(payment_id, payment_data) payment = payment_response["response"] ``` ### Java ```java MercadoPagoConfig.setAccessToken("TEST-703********22370-01********2405a0c3********7232f7a5********0082888"); PaymentClient client = new PaymentClient(); Payment paymentCanceled = client.cancel(18552260055L); ``` ### .Net ```csharp MercadoPagoConfig.AccessToken = "TEST-703********22370-01********2405a0c3********7232f7a5********0082888"; var client = new PaymentClient(); payment = client.Cancel(18552260055); ``` ### Ruby ```text sdk = Mercadopago::SDK.new('YOUR_ACCESS_TOKEN') payment_data = { "status": "canceled" } payment = sdk.payment.update("payment_id", payment_data) ``` ## Response example ```json { "id": 18746874919, "date_created": "2021-12-10T17:13:23.000-04:00", "date_approved": null, "date_last_updated": "2021-12-10T17:31:34.000-04:00", "date_of_expiration": "2021-12-13T22:59:59.000-04:00", "money_release_date": null, "operation_type": "regular_payment", "issuer_id": null, "payment_method_id": "bolbradesco", "payment_type_id": "ticket", "status": "canceled", "status_detail": "by_collector", "currency_id": "BRL", "description": "Meu produto", "live_mode": null, "sponsor_id": null, "authorization_code": null, "money_release_schema": null, "taxes_amount": 0, "counter_currency": null, "brand_id": null, "shipping_amount": 0, "pos_id": null, "store_id": null, "integrator_id": null, "platform_id": null, "corporation_id": null, "collector_id": null, "payers": [ { "first_name": null, "last_name": null, "email": "test@testuser.com", "type": "collector", "identification": [ { "number": null, "type": null } ], "phone": [ { "area_code": null, "number": null, "extension": null } ], "entity_type": null, "id": "1003743392", "operator_id": null } ], "marketplace_owner": null, "metadata": [ null ], "additional_info": [ { "items": [ { "id": null, "title": null, "description": null, "picture_url": null, "category_id": null, "quantity": null, "unit_price": null } ] } ], "order": [ { "type": "mercadopago", "id": "3754501423" } ], "external_reference": "firstname@gmail.com", "transaction_amount": 75.76, "transaction_amount_refunded": 0, "coupon_amount": 0, "differential_pricing_id": null, "deduction_schema": null, "barcode": [ { "content": "23791883300000075763380250600221946300633330" } ], "installments": 1, "transaction_details": [ { "payment_method_reference_id": "6002219463", "verification_code": "6002219463", "net_received_amount": 0, "total_paid_amount": 75.76, "overpaid_amount": 0, "external_resource_url": "https://www.mercadopago.com/mlb/payments/beta/ticket/helper?payment_id=18746874919&payment_method_reference_id=6002219463&caller_id=1003743392&hash=6a8c570f-9c39-4a5c-9b55-85ae1b724bf", "installment_amount": 0, "financial_institution": null, "payable_deferral_period": null, "acquirer_reference": null } ], "fee_details": [ null ], "charges_details": [ null ], "captured": true, "binary_mode": true, "call_for_authorize_id": null, "statement_descriptor": null, "card": [ null ], "notification_url": "https://webhook.site/17a3a5ce-28d4-4b4f-ba3f-a7595c17c6d8", "refunds": [ null ], "processing_mode": "aggregator", "merchant_account_id": null, "merchant_number": null, "acquirer_reconciliation": [ null ], "point_of_interaction": [ { "type": "Unspecified", "business_info": [ { "unit": null, "sub_unit": null } ] } ] } ```