Cancelar reserva
O cancelamento de uma reserva ocorre quando, por algum motivo, o pagamento de uma compra não é aprovado e a reserva do valor precisa retornar para o limite do cartão do cliente ou quando um comprador desiste da compra.
Para cancelar uma reserva utilize um dos códigos disponíveis abaixo.
<?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"}'
A resposta trará o seguinte resultado
{
...
"status": "cancelled",
"status_detail": "by_collector",
...
"captured": false,
...
}