From 71e4b52aa161d101693b034f6e14355bca59b520 Mon Sep 17 00:00:00 2001 From: khushal Date: Tue, 25 Feb 2025 15:01:54 +0530 Subject: [PATCH] (20250225) fmlllll --- models/api/finstitutions/payments/request.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/models/api/finstitutions/payments/request.py b/models/api/finstitutions/payments/request.py index c35f4a0..8ac8f70 100644 --- a/models/api/finstitutions/payments/request.py +++ b/models/api/finstitutions/payments/request.py @@ -48,6 +48,10 @@ from bson.objectid import ObjectId # To work with currencies: import pycountry +# For random strings: +import random +import string + # ***************************************************************************************************************** # ***** **** @@ -199,7 +203,7 @@ class PGPaymentRequestData(BaseModel): examples = ["INR", "USD", "KES"] ) - description: str | None = Field( + description: str = Field( description = "a short, human-readable description of the payment", frozen = True ) @@ -240,6 +244,10 @@ class PGPaymentRequestData(BaseModel): if currency is None: raise ValueError("invalid currency code, please use iso 4217 standard") return value + @field_validator("description", mode = "before") + def ensure_description(cls, value): + if value is None: value = "rndm_" + "".join(random.choices(string.ascii_letters + string.digits, k = 20)) + @field_validator("tags", mode = "after") def null_to_empty_list(cls, value): return [] if value is None else value