> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wepayout.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Unique Refund

> Returns the refund using its unique identifier

# Get Unique Refund

Returns the refund using its unique identifier.

## Path Parameters

<ParamField path="refundId" type="integer" required>
  The unique ID of the refund to retrieve.

  Example: `1234`
</ParamField>

## Response

<ResponseField name="id" type="integer">
  Refund ID.
</ResponseField>

<ResponseField name="payin_id" type="integer">
  ID of the payin (payin) that was refunded.
</ResponseField>

<ResponseField name="status_id" type="integer">
  Current status of the refund.

  Status codes:

  * `2`: REQUESTED
  * `4`: PAID (refund completed)
  * `5`: ERROR
</ResponseField>

<ResponseField name="user" type="object">
  User object.

  <Expandable title="User">
    <ResponseField name="id" type="integer">
      User ID who made the refund request.
    </ResponseField>

    <ResponseField name="name" type="string">
      User name who made the refund request.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="status_id" type="integer">
  Refund status ID.
</ResponseField>

<ResponseField name="name" type="string">
  Refund status name.
</ResponseField>

<ResponseField name="notification" type="string">
  Notification message.
</ResponseField>

<ResponseField name="created_at" type="string">
  Creation date time.
</ResponseField>

<ResponseField name="end_to_end_id" type="string">
  End-to-end ID (Pix transaction identifier).
</ResponseField>

<ResponseField name="reason" type="string">
  Reason for the refund.
</ResponseField>

<ResponseField name="wallet_error_code" type="string">
  Wallet error code (if applicable).
</ResponseField>

<ResponseField name="notification_url" type="string">
  Payin where notification will be sent.
</ResponseField>

<ResponseField name="created_at" type="string">
  Creation date time.
</ResponseField>

<ResponseField name="updated_at" type="string">
  Update date time.
</ResponseField>

<ResponseField name="refund_amount" type="integer">
  Refund value in cents.
</ResponseField>

<ResponseField name="status_history" type="array">
  Array of status history.

  <Expandable title="Status History Item">
    <ResponseField name="id" type="integer">
      Unique ID.
    </ResponseField>

    <ResponseField name="status_id" type="integer">
      Status ID.
    </ResponseField>

    <ResponseField name="name" type="string">
      Status name.
    </ResponseField>

    <ResponseField name="notification" type="string">
      Notification.
    </ResponseField>

    <ResponseField name="created_at" type="string">
      Creation date time.
    </ResponseField>

    <ResponseField name="end_to_end_id" type="string">
      End-to-end ID.
    </ResponseField>
  </Expandable>
</ResponseField>

## Request Example

<CodeGroup>
  ```bash cURL theme={null}
  curl --request GET \
    --url https://api.sandbox.wepayout.com.br/v1/payin/payments/payin-refund/1234 \
    --header 'Accept: application/json' \
    --header 'Authorization: Bearer 123'
  ```

  ```javascript JavaScript theme={null}
  async function getRefund(refundId) {
    const response = await fetch(
      `https://api.sandbox.wepayout.com.br/v1/payin/payments/payin-refund/${refundId}`,
      {
        method: 'GET',
        headers: {
          'Accept': 'application/json',
          'Authorization': 'Bearer 123'
        }
      }
    );
    
    return await response.json();
  }

  // Usage
  const refund = await getRefund(1234);
  console.log('Refund details:', refund);
  console.log('Status:', refund.name);
  console.log('Amount:', refund.refund_amount / 100);
  ```

  ```python Python theme={null}
  import requests

  def get_refund(refund_id):
      url = f'https://api.sandbox.wepayout.com.br/v1/payin/payments/payin-refund/{refund_id}'
      headers = {
          'Accept': 'application/json',
          'Authorization': 'Bearer 123'
      }
      
      response = requests.get(url, headers=headers)
      return response.json()

  # Usage
  refund = get_refund(1234)
  print(f"Refund details: {refund}")
  print(f"Status: {refund['name']}")
  print(f"Amount: R$ {refund['refund_amount'] / 100}")
  ```
</CodeGroup>

<ResponseExample>
  ```json 200 OK theme={null}
  {
    "id": 12345,
    "payin_id": 32457,
    "status_id": 4,
    "user": {
      "id": 1,
      "name": "Admin User"
    },
    "name": "PAID",
    "notification": "string",
    "created_at": "2024-06-12T23:10:00.000000Z",
    "end_to_end_id": "E1805820220621234567890AB1C2",
    "reason": "Customer requested refund",
    "wallet_error_code": null,
    "notification_url": "https://client.callback.com/notify-payin",
    "updated_at": "2024-06-12T23:15:00.000000Z",
    "refund_amount": 5000,
    "status_history": [
      {
        "id": 1,
        "status_id": 2,
        "name": "REQUESTED",
        "notification": "Refund requested",
        "created_at": "2024-06-12T23:10:00.000000Z",
        "end_to_end_id": null
      },
      {
        "id": 2,
        "status_id": 4,
        "name": "PAID",
        "notification": "Refund completed",
        "created_at": "2024-06-12T23:15:00.000000Z",
        "end_to_end_id": "E1805820220621234567890AB1C2"
      }
    ]
  }
  ```

  ```json 404 Not Found theme={null}
  {
    "message": "Refund not found"
  }
  ```
</ResponseExample>

## Use Cases

<AccordionGroup>
  <Accordion title="Check Refund Status">
    Monitor the status of a refund:

    ```javascript theme={null}
    async function checkRefundStatus(refundId) {
      const refund = await getRefund(refundId);
      
      const statusMap = {
        2: 'REQUESTED - Refund is being processed',
        4: 'PAID - Refund completed successfully',
        5: 'ERROR - Refund failed'
      };
      
      console.log(`Refund ${refundId}:`);
      console.log(`Status: ${statusMap[refund.status_id]}`);
      console.log(`Amount: R$ ${refund.refund_amount / 100}`);
      console.log(`Reason: ${refund.reason}`);
      
      return refund.status_id === 4;
    }
    ```
  </Accordion>

  <Accordion title="Track Refund History">
    View the complete history of a refund:

    ```javascript theme={null}
    async function trackRefundHistory(refundId) {
      const refund = await getRefund(refundId);
      
      console.log(`Refund history for ID ${refundId}:`);
      refund.status_history.forEach(history => {
        console.log(`${history.created_at}: ${history.name} - ${history.notification}`);
      });
      
      return refund.status_history;
    }
    ```
  </Accordion>

  <Accordion title="Verify Refund Completion">
    Check if a refund has been completed:

    ```javascript theme={null}
    async function verifyRefundCompletion(refundId) {
      const refund = await getRefund(refundId);
      
      const isCompleted = refund.status_id === 4;
      const hasFailed = refund.status_id === 5;
      
      if (isCompleted) {
        console.log(`Refund completed successfully`);
        console.log(`End-to-end ID: ${refund.end_to_end_id}`);
        return true;
      }
      
      if (hasFailed) {
        console.log(`Refund failed`);
        console.log(`Error: ${refund.wallet_error_code}`);
        return false;
      }
      
      console.log(`Refund still processing`);
      return null;
    }
    ```
  </Accordion>

  <Accordion title="Get Refund Details for Reconciliation">
    Retrieve refund details for accounting reconciliation:

    ```javascript theme={null}
    async function getRefundForReconciliation(refundId) {
      const refund = await getRefund(refundId);
      
      return {
        refundId: refund.id,
        payinId: refund.payin_id,
        amount: refund.refund_amount / 100,
        status: refund.name,
        endToEndId: refund.end_to_end_id,
        reason: refund.reason,
        createdAt: refund.created_at,
        completedAt: refund.updated_at,
        user: refund.user.name
      };
    }

    // Usage
    const reconciliation = await getRefundForReconciliation(1234);
    console.log('Reconciliation data:', reconciliation);
    ```
  </Accordion>

  <Accordion title="Monitor Multiple Refunds">
    Check status of multiple refunds:

    ```javascript theme={null}
    async function monitorRefunds(refundIds) {
      const results = [];
      
      for (const refundId of refundIds) {
        try {
          const refund = await getRefund(refundId);
          results.push({
            id: refundId,
            status: refund.name,
            amount: refund.refund_amount,
            completed: refund.status_id === 4
          });
        } catch (error) {
          results.push({
            id: refundId,
            error: error.message
          });
        }
      }
      
      return results;
    }

    // Usage
    const refundIds = [1234, 1235, 1236];
    const statuses = await monitorRefunds(refundIds);
    console.log('Refund statuses:', statuses);
    ```
  </Accordion>
</AccordionGroup>

## Status Codes

| Status ID | Status Name | Description                                      |
| --------- | ----------- | ------------------------------------------------ |
| 2         | REQUESTED   | Refund has been requested and is being processed |
| 4         | PAID        | Refund has been completed successfully           |
| 5         | ERROR       | Refund has failed                                |

## Best Practices

<Note>
  **Status History**: Use the `status_history` array to track the complete timeline of the refund process.
</Note>

<Tip>
  **End-to-End ID**: The `end_to_end_id` is only available after the refund is completed (status = PAID). Use it for Pix transaction tracking.
</Tip>

<Warning>
  **Error Handling**: Always check the `wallet_error_code` field when status is ERROR to understand why the refund failed.
</Warning>
