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

# Resolver cargo (Testing)

> Aprueba o rechaza manualmente un cargo de prueba en estado processing o created.

<Warning>
  Este endpoint solo funciona con cargos de prueba (`is_test: true`). Si intentas resolver un cargo de producción, recibirás un error `403`.
</Warning>

Permite simular la respuesta de un gateway de pago para cargos que quedaron en estado `processing` o `created` en ambiente de pruebas.

### ¿Cuándo usarlo?

Cuando creas un cargo en sandbox y el resultado es `processing` (por ejemplo, con cuentas bancarias que no tienen un patrón de auto-aprobación), puedes usar este endpoint para completar el flujo manualmente — simulando que el gateway responde aprobando o rechazando la transacción.

<ParamField path="charge_id" type="string" required placeholder="9e02966f-2ddf-4ee7-a391-5b5b7653e232">
  ID del cargo o `source_id` del cargo a resolver. Debe estar en estado `processing` o `created`.
</ParamField>

<ParamField body="action" type="string" required>
  Acción a ejecutar sobre el cargo. Valores válidos:

  * `approve` - Aprueba el cargo (transición a `paid`)
  * `reject` - Rechaza el cargo (transición a `failed`)
</ParamField>

<ParamField body="remarks" type="string">
  Motivo del rechazo. **Requerido cuando `action` es `reject`**.

  Acepta cualquier código de los [escenarios de prueba](/client/charges/scenarios), por ejemplo:

  * `INSUFFICIENT_FUNDS` - Fondos insuficientes
  * `RISK_CONTROL` - Bloqueado por control de riesgo
  * `CARD_EXPIRED` - Tarjeta expirada
  * `TRANSACTION_REJECTED` - Rechazado por el banco

  Consulta la lista completa en [escenarios de prueba](/client/charges/scenarios).
</ParamField>

### Aprobar un cargo

<RequestExample>
  ```bash cURL theme={null}
  curl https://api.onepay.la/v1/charges/9e02966f-2ddf-4ee7-a391-5b5b7653e232/resolve \
    -X POST \
    -H "Authorization: Bearer sk_test_xxx" \
    -H "Content-Type: application/json" \
    -d '{
      "action": "approve"
    }'
  ```

  ```javascript JavaScript theme={null}
  const chargeId = '9e02966f-2ddf-4ee7-a391-5b5b7653e232';

  const response = await fetch(`https://api.onepay.la/v1/charges/${chargeId}/resolve`, {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer sk_test_xxx',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      action: 'approve'
    })
  });

  const data = await response.json();
  console.log(data.status); // "paid"
  ```

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

  charge_id = "9e02966f-2ddf-4ee7-a391-5b5b7653e232"
  url = f"https://api.onepay.la/v1/charges/{charge_id}/resolve"

  response = requests.post(url, headers={
      "Authorization": "Bearer sk_test_xxx",
      "Content-Type": "application/json"
  }, json={
      "action": "approve"
  })

  data = response.json()
  print(data["status"])  # "paid"
  ```

  ```php PHP theme={null}
  <?php
  $chargeId = "9e02966f-2ddf-4ee7-a391-5b5b7653e232";
  $ch = curl_init();

  curl_setopt_array($ch, [
      CURLOPT_URL => "https://api.onepay.la/v1/charges/{$chargeId}/resolve",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_POST => true,
      CURLOPT_HTTPHEADER => [
          "Authorization: Bearer sk_test_xxx",
          "Content-Type: application/json"
      ],
      CURLOPT_POSTFIELDS => json_encode([
          "action" => "approve"
      ])
  ]);

  $response = curl_exec($ch);
  $data = json_decode($response, true);
  echo $data["status"]; // "paid"

  curl_close($ch);
  ?>
  ```
</RequestExample>

### Rechazar un cargo con motivo

```bash theme={null}
curl https://api.onepay.la/v1/charges/9e02966f-2ddf-4ee7-a391-5b5b7653e232/resolve \
  -X POST \
  -H "Authorization: Bearer sk_test_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "action": "reject",
    "remarks": "RISK_CONTROL"
  }'
```

<ResponseExample>
  ```json 200 Aprobado theme={null}
  {
    "id": "9e02966f-2ddf-4ee7-a391-5b5b7653e232",
    "status": "paid",
    "remarks": null,
    "paid_at": "2026-02-20T17:14:00.000000Z"
  }
  ```

  ```json 200 Rechazado theme={null}
  {
    "id": "9e02966f-2ddf-4ee7-a391-5b5b7653e232",
    "status": "failed",
    "remarks": {
      "code": "RISK_CONTROL",
      "description": "La transacción ha sido bloqueada por el control de riesgo del banco.",
      "customer_description": "La transacción ha sido bloqueada por el banco. Comunícate con tu banco para resolver el problema."
    },
    "paid_at": null
  }
  ```

  ```json 403 Cargo no es de prueba theme={null}
  {
    "message": "This endpoint is only available for test charges."
  }
  ```

  ```json 422 Estado no resoluble theme={null}
  {
    "message": "Only charges in processing or created status can be resolved."
  }
  ```

  ```json 422 Remarks requerido theme={null}
  {
    "message": "The remarks field is required when action is reject.",
    "errors": {
      "remarks": ["The remarks field is required when action is reject."]
    }
  }
  ```
</ResponseExample>
