Repository navigation
feat(pagos): EstadoConfirmacionPago — pago reportado vs confirmado (schema + clasificación) - #156
Merged
Merged
Conversation
…chema + clasificación)
ADR-PAGO-REPORTADO-CONFIRMADO-001, paso 1 (aditivo, sin feature flag): el
schema y la clasificación inicial. Endpoints de confirmación + UI van en PRs
siguientes.
Un pago digital ("ya te mandé el Nequi") hoy se trata igual que uno verificado.
`EstadoConfirmacionPago` (REPORTADO / CONFIRMADO / DISCREPANTE) es una señal
ORTOGONAL al saldo: "¿este dinero entró?". El detalle de una discrepancia NO
vive en `Pago` — vive en el `ResponsibilityCase` (dominio antifraude).
Schema (`prisma/schema.prisma`):
- enum `EstadoConfirmacionPago`
- `Pago.confirmacion` (default REPORTADO), `confirmadoPorId` (FK User, SET NULL),
`confirmadoAt`, `@@index([confirmacion])`
- `User.pagosConfirmados` (relación inversa)
- doc del `ResponsibilityCase.tipo`: nuevo valor `PAGO_NO_CONFIRMADO`
Migración `20260901_add_pago_confirmacion`: tipo + columnas + FK + índice +
backfill idempotente (todo Pago pre-migración → CONFIRMADO con confirmadoPorId
NULL; son hechos ya conciliados por cierres pasados, marcarlos REPORTADO
inundaría la cola de confirmación — ADR-MIGRACION-001) + GRANT app_write.
Clasificación inicial (`src/lib/pago-confirmacion.ts`, helper puro):
- `confirmacionInicial(metodo)` — NEQUI/TRANSFERENCIA/DAVIPLATA → REPORTADO;
EFECTIVO/BONO (custodia física → cierre de embarque) → CONFIRMADO
- `parseMetodosRequierenConfirmacion(csv)` — para el futuro override
`Config.METODOS_REQUIEREN_CONFIRMACION` (aún no cableado; .1 usa el default
del ADR §2 en todos los sitios para no divergir entre route y cierre)
Sitios de creación de Pago cableados: venta-libre (route + CrearVentasLibresService),
pagar-fiado, ProcesarPedidoService (cierre), PrismaPagoRepository.createMany
(CrearPedido). `import/commit.ts` → CONFIRMADO (hechos históricos, mismo criterio
que el backfill).
Nada lee `confirmacion` todavía: EstadoPago/saldo/badges/cierre sin cambios.
Tests: `pago-confirmacion.test.ts` (helper), `PrismaPagoRepository.test.ts`
(createMany clasifica), venta-libre `route.test.ts` (EFECTIVO→CONFIRMADO,
NEQUI→REPORTADO). tsc + 2740 unit tests + eslint verdes.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
…erente, claim de config 3 hallazgos del code-review: 1. Migración: el backfill `UPDATE ... SET confirmacion='CONFIRMADO'` no era re-run safe (CLAUDE.md #12: en dev las migraciones se corren a mano y pueden repetirse) — un segundo `psql -f` marcaría CONFIRMADO pagos digitales legítimamente pendientes. Ahora ADD COLUMN + backfill van en un bloque gateado por "la columna no existía". Verificado: 2ª aplicación = no-op. 2. `confirmadoAt` incoherente: el backfill lo setea (`= createdAt`) pero los pagos vivos que nacían CONFIRMADO (efectivo/bono) lo dejaban NULL → una query "confirmados en el período X" por `confirmadoAt` excluiría toda venta de contado posterior a la migración. Nuevo `datosConfirmacionInicial(metodo)` que setea `confirmadoAt` cuando nace CONFIRMADO (auto por regla de método), nunca `confirmadoPorId` (eso solo el endpoint). Los 6 sitios lo usan. 3. `Config.METODOS_REQUIEREN_CONFIRMACION`: el docstring prometía un override que no está cableado. Reformulado — el cableado va con el endpoint de confirmación (.2), donde leer Config es natural; `parseMetodosRequierenConfirmacion` queda listo para eso. tsc + 74 tests del área + eslint verdes. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…firmacion-schema # Conflicts: # src/app/api/pedidos/venta-libre/__tests__/route.test.ts
This was referenced Sep 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Qué
ADR-PAGO-REPORTADO-CONFIRMADO-001, paso 1: schema + clasificación inicial. Aditivo, sin feature flag. Endpoints de confirmación (/api/pagos/por-confirmar,/api/pagos/[id]/confirmar) y UI (badges "Reportado", sección dashboard) van en PRs siguientes.Por qué
Un pago digital ("ya te mandé el Nequi") hoy se trata igual que uno verificado: la UI dice "Pagado", el saldo baja. No hay forma de distinguir reportado de confirmado → falsos positivos y disputas (AC-05).
EstadoConfirmacionPagoes una señal ortogonal al saldo.EstadoPagono cambia.Cambios
prisma/schema.prismaEstadoConfirmacionPago;Pago.confirmacion/confirmadoPorId/confirmadoAt+@@index([confirmacion]);User.pagosConfirmados; docResponsibilityCase.tipo+=PAGO_NO_CONFIRMADOprisma/migrations/20260901_add_pago_confirmacion/migration.sqlON DELETE SET NULL) + índice + backfill idempotente +GRANT app_writesrc/lib/pago-confirmacion.ts(nuevo)confirmacionInicial(metodo)+parseMetodosRequierenConfirmacion(csv)— helpers purosventa-libre/route.ts,CrearVentasLibresService,pagar-fiado/route.ts,ProcesarPedidoService,PrismaPagoRepository.createManyPagoal crearlosrc/lib/import/commit.tsCONFIRMADO(hecho histórico)Clasificación (ADR §2)
REPORTADO(hay que ver la cuenta)CONFIRMADO(custodia física → cierre de embarque +FALTANTE_CAJA)El override
Config.METODOS_REQUIEREN_CONFIRMACIONaún no está cableado:.1usa el default del ADR en todos los sitios para no divergir entre el route de venta libre y el cierre de embarque. Se cablea en el PR del endpoint de confirmación (donde leer Config es natural).Backfill
Todo
Pagoanterior a la migración →CONFIRMADO,confirmadoPorId = NULL,confirmadoAt = createdAt. Son pagos ya conciliados por cierres pasados; marcarlosREPORTADOinundaría la cola con miles de filas sin valor (ADR-MIGRACION-001; la ausencia deconfirmadoPorIddeja claro que fue backfill).Alcance / lo que NO cambia
Nada lee
confirmaciontodavía:EstadoPago, saldo, badges,/api/cierre— idénticos. Solo se empieza a escribir la columna.Verificación
npx prisma validate✅ · migración aplicada a dev DB ✅npx tsc --noEmit✅npx vitest run→ 2740 ✅npx eslint(archivos tocados) ✅pago-confirmacion.test.ts(helper),PrismaPagoRepository.test.ts(createMany clasifica),venta-libre/route.test.ts(EFECTIVO→CONFIRMADO, NEQUI→REPORTADO)Rollback
git revert+DROP COLUMN×3 +DROP TYPE. Sin lectores, sin UI, sin flag que revertir.🤖 Generated with Claude Code