(20241216) Payments requesting started, callback noting started.

This commit is contained in:
2024-12-16 18:29:30 +05:30
parent 0b9976fadb
commit b6ba54abd4
12 changed files with 636 additions and 117 deletions
+1 -1
View File
@@ -85,7 +85,7 @@ from langchain_openai import ChatOpenAI
# *****************************************************************************************************************
class LLMController(BaseModel):
class CoreLLMController(BaseModel):
AI_USAGE_COLLECTION = "_aiUsage"
+50 -3
View File
@@ -134,10 +134,14 @@ class CorePaymentController(BaseModel):
:return: The object id of the inserted document.
"""
# Receive te JSON:
payment_json = payment.model_dump()
payment_json.pop("_id")
# Simply insert the document:
return await mongo_conn.insert_one(
collection = self.PAYMENTS_COLLECTION,
document = payment,
document = payment_json,
raise_exception = True
)
@@ -253,6 +257,34 @@ class CorePaymentController(BaseModel):
# we return it as our data model:
return CorePaymentModel(**record)
async def get_payment_internal(
self,
mongo_conn: AsyncMongo,
payment_id: ObjectId | str,
) -> CorePaymentModel | None:
"""
NOTE: DO NOT USE THIS IN USER-FACING APIS. USE THIS INTERNALLY TO FETCH RECORDS.
Gets one payment detail if you know its payment id.
:param mongo_conn: The instance of the database connector to use for the operation.
:param payment_id: The id of the payment detail that needs to be read.
:return: The contents of that one payment detail in a structured format.
"""
# We fetch the whole payload of that one message:
record = await mongo_conn.find_one(
collection = self.PAYMENTS_COLLECTION,
filter = {"_id": ObjectId(payment_id)},
raise_exception = True
)
# If no such message was found:
if record is None: return None
# If a record was found,
# we return it as our data model:
return CorePaymentModel(**record)
# ┏┓┳┓┳┳┳┓ ┳┳ ┓
# ┃ ┣┫┃┃┃┃ ━━ ┃┃┏┓┏┫┏┓╋┏┓
# ┗┛┛┗┗┛┻┛ ┗┛┣┛┗┻┗┻┗┗
@@ -265,7 +297,8 @@ class CorePaymentController(BaseModel):
self,
mongo_conn: AsyncMongo,
payment_id: ObjectId | str,
event: PaymentEvent
event: PaymentEvent,
client_reference_id: str = None
) -> bool:
"""
@@ -273,14 +306,28 @@ class CorePaymentController(BaseModel):
:param mongo_conn: The instance of the database connector to use for the operation.
:param payment_id: The id of the payment detail that needs to be read.
:param event: The event that occurred. This will typically be generated by the third-party client.
:param client_reference_id: The way the client identifies this payment. You need to pass this only on the first
event. Typically, when you initiate the payment request.
:return: True if successfully noted, else False.
"""
# Prepare the update document:
update_json = {
"$push": {
"events": event.model_dump()
},
"$set": {
"lastEventTs": date_time.get_current_ist_date_time(as_string = False),
"lastPaymentStatus": event.paymentStatus
}
}
if client_reference_id: update_json["$set"]["clientPaymentReferenceId"] = client_reference_id
# Try to update the existing record:
return await mongo_conn.update_one(
collection = self.PAYMENTS_COLLECTION,
filter = {"_id": ObjectId(payment_id)},
update = {"$push": {"events": event}},
update = update_json,
upsert = False,
raise_exception = True
)