{
  "openapi": "3.1.0",
  "info": {
    "title": "Verifica Public API",
    "version": "1.0.0",
    "description": "Public API documentation for KYC and FirmaID processes."
  },
  "servers": [
    {
      "url": "https://api.verifica.id",
      "description": "Production Server"
    }
  ],
  "tags": [
    {
      "name": "Public KYC",
      "description": "Public endpoints for KYC processes (Frontend integration)."
    },
    {
      "name": "Public FirmaID",
      "description": "Public endpoints for Signature processes (Client integration)."
    },
    {
      "name": "FirmaID Actions",
      "description": "Specific actions for FirmaID management."
    },
    {
      "name": "Webhooks",
      "description": "Webhook endpoints for external integrations."
    },
    {
      "name": "Compliance",
      "description": "Endpoints de cumplimiento y verificación AML (Anti-Lavado de Dinero)."
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    },
    "schemas": {
      "PublicKycResult": {
        "type": "object",
        "properties": {
          "has_warnings": {
            "type": "boolean"
          },
          "has_attempts": {
            "type": "boolean"
          },
          "status": {
            "type": "string"
          },
          "status_name": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "callback_url": {
            "type": "string",
            "nullable": true
          },
          "warnings": {
            "type": "object",
            "nullable": true
          }
        }
      },
      "PublicKycRetry": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "status_name": {
            "type": "string"
          },
          "url": {
            "type": "string"
          },
          "vendor_data": {
            "type": "object",
            "nullable": true
          },
          "has_attempts": {
            "type": "boolean"
          }
        }
      },
      "SignatureClientWelcome": {
        "type": "object",
        "properties": {
          "signature_id": {
            "type": "string",
            "format": "uuid"
          },
          "signer_name": {
            "type": "string"
          },
          "signature_status": {
            "type": "string"
          },
          "signature_status_es": {
            "type": "string"
          },
          "has_attempts": {
            "type": "boolean"
          },
          "documents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SignatureDocumentResource"
            }
          }
        }
      },
      "SignatureDocumentResource": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "rejected_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "rejected_by": {
            "type": "string",
            "nullable": true
          },
          "rejection_reason": {
            "type": "string",
            "nullable": true
          },
          "size_mb": {
            "type": "number",
            "format": "float",
            "nullable": true
          },
          "file_url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "SignatureKycSession": {
        "type": "object",
        "properties": {
          "biometric_validation_session": {
            "type": "object",
            "properties": {
              "status": {
                "type": "string"
              },
              "status_name": {
                "type": "string"
              },
              "url": {
                "type": "string"
              }
            }
          },
          "has_attempts": {
            "type": "boolean"
          }
        }
      },
      "SignerResult": {
        "type": "object",
        "properties": {
          "has_warnings": {
            "type": "boolean"
          },
          "has_attempts": {
            "type": "boolean"
          },
          "status": {
            "type": "string"
          },
          "status_name": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "warnings": {
            "type": "object",
            "nullable": true
          }
        }
      },
      "GenericSuccess": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "example": "success"
          },
          "message": {
            "type": "string"
          },
          "data": {
            "type": "object",
            "nullable": true
          }
        }
      },
      "SignatureResource": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "organization_id": {
            "type": "integer",
            "nullable": true
          },
          "name": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "status_name": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "expiration_date": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "completed_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "rejected_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "rejected_reason": {
            "type": "string",
            "nullable": true
          },
          "rejected_by": {
            "type": "string",
            "nullable": true
          },
          "documents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SignatureDocumentResource"
            }
          },
          "signers": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SignerResource"
            }
          }
        }
      },
      "SignerResource": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "signing_status": {
            "type": "string"
          },
          "signing_status_name": {
            "type": "string"
          },
          "full_name": {
            "type": "string"
          },
          "document_type": {
            "type": "string"
          },
          "document_number": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "phone": {
            "type": "string",
            "nullable": true
          },
          "signer_url": {
            "type": "string",
            "format": "uri",
            "nullable": true
          },
          "biometric_validation_id": {
            "type": "string",
            "format": "uuid",
            "nullable": true
          },
          "biometric_validation_status": {
            "type": "string",
            "nullable": true
          },
          "biometric_validation_status_name": {
            "type": "string",
            "nullable": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "viewed_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "signed_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "rejected_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "SignatureStoreRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 255
          },
          "expires_at": {
            "type": "string",
            "format": "date-time",
            "description": "Required without expires_in. Must be at least 10 minutes in the future.",
            "nullable": true
          },
          "expires_in": {
            "type": "integer",
            "description": "Required without expires_at. Minutes until expiration.",
            "nullable": true,
            "minimum": 1,
            "maximum": 43200
          },
          "documents": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string",
                  "maxLength": 255
                },
                "file": {
                  "type": "string",
                  "description": "Base64 encoded PDF file."
                }
              },
              "required": ["name", "file"]
            }
          },
          "signers": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "properties": {
                "full_name": {
                  "type": "string",
                  "maxLength": 255
                },
                "document_type": {
                  "type": "string",
                  "enum": ["dni", "ce", "passport"]
                },
                "document_number": {
                  "type": "string",
                  "maxLength": 30
                },
                "email": {
                  "type": "string",
                  "format": "email",
                  "maxLength": 255
                },
                "phone": {
                  "type": "string",
                  "maxLength": 20,
                  "nullable": true
                }
              },
              "required": ["full_name", "document_type", "document_number", "email"]
            }
          }
        },
        "required": ["name", "documents", "signers"]
      },
      "AmlReportResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Report id, used with GET /api/v1/solutions/aml-report/{id}"
          },
          "document_type": {
            "type": "string",
            "enum": [
              "dni",
              "ruc"
            ],
            "description": "Document type"
          },
          "document_number": {
            "type": "string",
            "description": "Document number"
          },
          "dni": {
            "type": "string",
            "description": "Same as document_number (kept for compatibility)"
          },
          "aml_status": {
            "type": "string",
            "enum": [
              "GREEN",
              "YELLOW",
              "ORANGE",
              "RED",
              "BLACK"
            ],
            "description": "Risk level classification"
          },
          "compliance": {
            "type": "object",
            "properties": {
              "pep_sanctions": {
                "type": "object",
                "nullable": true,
                "description": "PEP and sanctions lists: risk_level, matched, matched_risk, unmatched, glossary"
              },
              "kyc_adverse_media": {
                "type": "object",
                "nullable": true,
                "description": "Adverse media lists: risk_level, matched, matched_risk, unmatched, glossary"
              },
              "ubo_companies": {
                "type": "object",
                "nullable": true,
                "description": "UBO and companies lists: risk_level, matched, matched_risk, unmatched, glossary"
              }
            }
          },
          "pep": {
            "type": "array",
            "nullable": true,
            "description": "PEP results details"
          },
          "sanctions": {
            "type": "array",
            "nullable": true,
            "description": "Sanctions list results"
          },
          "adverse_media": {
            "type": "array",
            "nullable": true,
            "description": "Adverse media results"
          },
          "pdf_link": {
            "type": "string",
            "format": "uri",
            "nullable": true,
            "description": "Signed URL of the report PDF, or of the no-match certificate when there is no match (valid for 45 minutes)"
          },
          "pep_historical": {
            "type": "array",
            "nullable": true,
            "description": "Historical PEP results"
          },
          "pep_relatives": {
            "type": "array",
            "nullable": true,
            "description": "PEP relatives results"
          },
          "judicial_records": {
            "type": "array",
            "nullable": true,
            "description": "Judicial records results"
          },
          "vip_list": {
            "type": "array",
            "nullable": true,
            "description": "VIP list results"
          }
        }
      }
    }
  },
  "paths": {
    "/api/v1/solutions/aml-report": {
      "post": {
        "tags": [
          "Compliance"
        ],
        "summary": "Crear un Reporte PEP/AML",
        "description": "Consulta en línea el Reporte PEP/AML de un DNI o RUC y responde 201 con el resultado y su id. Cobra 1 token de la bolsa aml (Reporte PEP/AML) solo cuando la consulta resuelve: el saldo se valida antes de consultar al proveedor y el cobro va después del resultado, así que una falla del proveedor no cuesta tokens. Cada POST es una consulta nueva y vuelve a cobrar; para releer un reporte usa GET /api/v1/solutions/aml-report/{id}. Sin coincidencias, pdf_link apunta al certificado de no coincidencia y los bloques de detalle vienen en null. pdf_link es una URL firmada válida por 45 minutos.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "document_type",
                  "document_number"
                ],
                "properties": {
                  "document_type": {
                    "type": "string",
                    "enum": [
                      "dni",
                      "ruc"
                    ],
                    "example": "dni",
                    "description": "Tipo de documento."
                  },
                  "document_number": {
                    "type": "string",
                    "example": "12345678",
                    "description": "DNI: 8 dígitos. RUC: 11 dígitos que empiezan en 10, 15, 16, 17 o 20."
                  }
                },
                "example": {
                  "document_type": "dni",
                  "document_number": "12345678"
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Reporte creado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "success"
                    },
                    "message": {
                      "type": "string",
                      "example": "AML Report created"
                    },
                    "data": {
                      "$ref": "#/components/schemas/AmlReportResponse"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Secret key ausente o inválida."
          },
          "402": {
            "description": "Sin tokens en la bolsa aml. No se consulta al proveedor ni se crea el reporte.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "example": "payment_required"
                    },
                    "status": {
                      "type": "integer",
                      "example": 402
                    },
                    "message": {
                      "type": "string",
                      "example": "Tokens insuficientes para realizar esta acción."
                    },
                    "errors": {
                      "nullable": true,
                      "example": null
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Documento inválido.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "success"
                    },
                    "errors": {
                      "type": "object",
                      "example": {
                        "document_number": [
                          "El DNI debe tener 8 dígitos."
                        ]
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Más de 60 llamadas por minuto."
          },
          "503": {
            "description": "El proveedor respondió con error o no respondió. No se crea el reporte, no se emite certificado y no se cobra; se puede reintentar.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "example": "api_error"
                    },
                    "status": {
                      "type": "integer",
                      "example": 503
                    },
                    "message": {
                      "type": "string",
                      "example": "El servicio de consulta AML no está disponible. Por favor intenta nuevamente en unos minutos."
                    },
                    "errors": {
                      "nullable": true,
                      "example": null
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/solutions/aml-report/{id}": {
      "get": {
        "tags": [
          "Compliance"
        ],
        "summary": "Consultar un Reporte PEP/AML",
        "description": "Devuelve un reporte de la organización, incluidos los que nacieron de un KYC, con un pdf_link firmado nuevo (válido 45 minutos). No consulta al proveedor ni cobra tokens.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Reporte guardado.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "success"
                    },
                    "message": {
                      "type": "string",
                      "example": "Retrieve AML Report"
                    },
                    "data": {
                      "$ref": "#/components/schemas/AmlReportResponse"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Secret key ausente o inválida."
          },
          "404": {
            "description": "El id no existe o pertenece a otra organización. Un id que no es UUID no llega a la ruta y responde el 404 estándar.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "success"
                    },
                    "message": {
                      "type": "string",
                      "example": "Reporte no encontrado."
                    },
                    "data": {
                      "nullable": true,
                      "example": null
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Más de 60 llamadas por minuto."
          }
        }
      }
    },
    "/api/v1/solutions/public-kyc/kyc-bravo/biometric-validation/{biometricValidation}": {
      "get": {
        "tags": ["Public KYC"],
        "summary": "Get Public KYC Results",
        "description": "Retrieves the results of a KYC session publicly.",
        "parameters": [
          {
            "name": "biometricValidation",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Results retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "success"
                    },
                    "message": {
                      "type": "string",
                      "example": "Resultados obtenidos correctamente"
                    },
                    "data": {
                      "$ref": "#/components/schemas/PublicKycResult"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/solutions/public-kyc/kyc-bravo/biometric-validation/{biometricValidation}/retry": {
      "post": {
        "tags": ["Public KYC"],
        "summary": "Retry Public KYC Session",
        "description": "Retries a failed KYC session.",
        "parameters": [
          {
            "name": "biometricValidation",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Session created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "success"
                    },
                    "message": {
                      "type": "string",
                      "example": "Session created successfully."
                    },
                    "data": {
                      "$ref": "#/components/schemas/PublicKycRetry"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/public-firmaid/signer-welcome/{signer}": {
      "get": {
        "tags": ["Public FirmaID"],
        "summary": "Signer Welcome",
        "description": "Retrieves initial data for the signer interface.",
        "parameters": [
          {
            "name": "signer",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Welcome data retrieved",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "success"
                    },
                    "message": {
                      "type": "string",
                      "example": "Signature client retrieved successfully."
                    },
                    "data": {
                      "$ref": "#/components/schemas/SignatureClientWelcome"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/public-firmaid/signer-documents/{signer}/viewed": {
      "post": {
        "tags": ["Public FirmaID"],
        "summary": "Mark Documents as Viewed",
        "description": "Marks that the signer has viewed the documents.",
        "parameters": [
          {
            "name": "signer",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Status updated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GenericSuccess"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/public-firmaid/signer-signature/{signer}/reject": {
      "post": {
        "tags": ["Public FirmaID"],
        "summary": "Reject Signature",
        "description": "Signer rejects the entire signature request.",
        "parameters": [
          {
            "name": "signer",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "reject_reason": {
                    "type": "string"
                  }
                },
                "required": ["reject_reason"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signature rejected",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GenericSuccess"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/public-firmaid/signer-document/{signer}/reject": {
      "post": {
        "tags": ["Public FirmaID"],
        "summary": "Reject Document",
        "description": "Signer rejects a specific document.",
        "parameters": [
          {
            "name": "signer",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "reject_reason": {
                    "type": "string"
                  },
                  "document_uuid": {
                    "type": "string",
                    "format": "uuid"
                  }
                },
                "required": ["reject_reason", "document_uuid"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Document rejected",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GenericSuccess"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/public-firmaid/kyc-signature/{signer}/create-session": {
      "post": {
        "tags": ["Public FirmaID"],
        "summary": "Create KYC Session for Signature",
        "description": "Creates a KYC session for the signer.",
        "parameters": [
          {
            "name": "signer",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Session created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "success"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "$ref": "#/components/schemas/SignatureKycSession"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/public-firmaid/signer-result/{signer}": {
      "get": {
        "tags": ["Public FirmaID"],
        "summary": "Get Signer Results",
        "description": "Retrieves the final results for a signer.",
        "parameters": [
          {
            "name": "signer",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "verificationSessionId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Results retrieved",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "success"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "$ref": "#/components/schemas/SignerResult"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/firmaid/send-request-new-signature": {
      "post": {
        "tags": ["FirmaID Actions"],
        "summary": "Create and Send Signature Request",
        "description": "Creates a new signature request and immediately sends it to signers.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SignatureStoreRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signature created and sent successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "success"
                    },
                    "message": {
                      "type": "string",
                      "example": "Signature created successfully."
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "signature": {
                          "$ref": "#/components/schemas/SignatureResource"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/webhooks/v1/solutions/kyc-bravo/didit": {
      "post": {
        "tags": ["Webhooks"],
        "summary": "Didit Webhook",
        "description": "Endpoint for receiving webhooks from Didit provider.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "description": "Arbitrary payload from provider."
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Webhook processed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "success"
                    },
                    "message": {
                      "type": "string",
                      "example": "Webhook processed successfully."
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
