documentverification/verifier/serializers.py
vickytechkey 9e60dc2f56
All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 30s
feat: add composite seller PAN verification, name matching, and GST pull endpoint
2026-10-15 21:42:00 +05:30

97 lines
2.9 KiB
Python

from rest_framework import serializers
from .models import VendorConfig, VerificationTransaction, VendorAttemptLog
class VerifyDocumentRequestSerializer(serializers.Serializer):
"""Input payload serializer for document verification API."""
document_type = serializers.CharField(
required=True,
help_text="Type of document, e.g. 'pan', 'aadhaar', 'driving_license', 'voter_id', 'bank_account', 'gstin'",
)
data = serializers.DictField(
required=True,
help_text="Document verification attributes (e.g. pan_number, name, dob, etc.)",
)
preferred_vendor = serializers.CharField(
required=False,
allow_null=True,
allow_blank=True,
help_text="Optional vendor to prioritize at head of fallback waterfall (e.g. 'codeplus')",
)
class VerifySellerPanGstRequestSerializer(serializers.Serializer):
"""Input payload for verifying a seller's identity via PAN and pulling linked GSTINs."""
seller_name = serializers.CharField(
required=True,
help_text="Full legal name of the seller / owner to match against the government PAN card.",
)
pan = serializers.CharField(
required=True,
max_length=10,
min_length=10,
help_text="10-character Permanent Account Number (PAN).",
)
gstin = serializers.CharField(
required=False,
allow_blank=True,
allow_null=True,
max_length=15,
help_text="Optional GSTIN entered by seller to cross-verify against linked GST records.",
)
preferred_vendor = serializers.CharField(
required=False,
allow_blank=True,
allow_null=True,
help_text="Optional vendor preference (defaults to waterfall order).",
)
class VendorAttemptLogSerializer(serializers.ModelSerializer):
class Meta:
model = VendorAttemptLog
fields = [
"attempt_number",
"vendor_name",
"status",
"is_success",
"data",
"raw_response",
"error_code",
"error_message",
"latency_ms",
"created_at",
]
class VerificationTransactionSerializer(serializers.ModelSerializer):
attempts = VendorAttemptLogSerializer(many=True, read_only=True)
class Meta:
model = VerificationTransaction
fields = [
"reference_id",
"document_type",
"status",
"successful_vendor",
"final_data",
"response_payload",
"attempts_count",
"total_latency_ms",
"created_at",
"attempts",
]
class VendorConfigSerializer(serializers.ModelSerializer):
class Meta:
model = VendorConfig
fields = [
"name",
"display_name",
"priority",
"is_active",
"supported_documents",
"base_url",
"updated_at",
]