AI resources

Refund of transactions with Pix

When receiving payments with Pix, it is possible that the need to perform refund operations may arise. If necessary, it is possible that refunds remain in process (contingency) due to an error during transaction processing, for example, in communication with Bacen.

By default, these errors are reported to the person making the request as a 400 - Bad Request, which can make it difficult to understand the status of the refund until the payment changes to the refunded status (if approved).

For a clearer response, just send the header X-Render-In-Process-Refunds: true along with the refund creation request, that way, the response will include the status 201 - Created and the field status with value in_process.

The header can also be included in requests to get refund list and to search for a specific refund. In those cases, if applicable, the response will bring the same status value as mentioned above.

<?php
  use MercadoPago\Client\Payment\PaymentRefundClient;
  MercadoPagoConfig::setAccessToken("YOUR_ACCESS_TOKEN");
  
  $client = new PaymentRefundClient();
  $refund = $client->refund($payment_id, 20);
  echo $refund->id;
?>

Response examples (some fields have been omitted)

Json
{
 "id": 1150873004,
 "payment_id": 23443394602,
 "amount": 20,
 "metadata": {},
 "source": {
     "id": "475845652",
     "name": "Test Test",
     "type": "collector"
 },
 "date_created": "2022-06-24T16:09:03.944-04:00",
 "unique_sequence_number": null,
 "refund_mode": "standard",
 "adjustment_amount": 0,
 "status": "in_process",
 "reason": "1",
 "labels": [
     "hidden",
     "contingency"
 ],
 "amount_refunded_to_payer": 20,
 "e2e_id": "D00000000202312220000abcdefghijklm",
 "partition_details": []
}