Cancelar reserva
La cancelación de una reserva se produce cuando, por algún motivo, no se aprueba el pago de una compra y se debe devolver el valor de la reserva al límite de la tarjeta del cliente, o cuando un comprador desiste de la compra.
Para cancelar una reserva, utiliza uno de nuestros códigos disponibles a continuación.
<?php
use MercadoPago\Client\Payment\PaymentClient;
MercadoPagoConfig::setAccessToken("YOUR_ACCESS_TOKEN");
$client = new PaymentClient();
$request_options = new RequestOptions();
$request_options->setCustomHeaders(["X-Idempotency-Key: <SOME_UNIQUE_VALUE>"]);
$payment = $client->cancel($payment_id, $request_options);
echo $payment->status;
?>
import { MercadoPagoConfig, Payment } from 'mercadopago';
const client = new MercadoPagoConfig({ accessToken: 'YOUR_ACCESS_TOKEN' });
const payment = new Payment(client);
payment.cancel({
id: '<PAYMENT_ID>',
requestOptions: {
idempotencyKey: '<IDEMPOTENCY_KEY>'
},
}).then(console.log).catch(console.log);
MercadoPagoConfig.setAccessToken("ENV_ACCESS_TOKEN");
Long paymentId = 123456789L;
PaymentClient client = new PaymentClient();
client.cancel(paymentId);
require 'mercadopago'
sdk = Mercadopago::SDK.new(ENV_ACCESS_TOKEN)
request = {
status: 'canceled'
}
payment_response = sdk.payment.update(payment_id, request)
payment = payment_response[:response]
using MercadoPago.Client.Payment;
using MercadoPago.Config;
using MercadoPago.Resource.Payment;
MercadoPagoConfig.AccessToken = "ENV_ACCESS_TOKEN";
var client = new PaymentClient();
Payment payment = await client.CancelAsync(paymentId);
import mercadopago
sdk = mercadopago.SDK("ENV_ACCESS_TOKEN")
payment_data = {
"status": "cancelled"
}
payment_response = sdk.payment().update(payment_id, payment_data)
payment = payment_response["response"]
package main
import (
"context"
"fmt"
"github.com/mercadopago/sdk-go/pkg/config"
"github.com/mercadopago/sdk-go/pkg/payment"
)
func main() {
accessToken := "{{ACCESS_TOKEN}}"
cfg, err := config.New(accessToken)
if err != nil {
fmt.Println(err)
return
}
client := payment.NewClient(cfg)
resource, err := client.Cancel(context.Background(), <PAYMENT_ID>)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(resource)
}
curl -X PUT \
'https://api.mercadopago.com/v1/payments/PAYMENT_ID' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer ENV_ACCESS_TOKEN' \
-d '{"status": "cancelled"}'
La respuesta devolverá el siguiente resultado
{
...
"status": "cancelled",
"status_detail": "by_collector",
...
"captured": false,
...
}