(20241213) Started accepting payment gateway auth details.

This commit is contained in:
2024-12-13 20:41:45 +05:30
parent 40cd59dd28
commit 3a03dd4a61
4 changed files with 39 additions and 34 deletions
+22 -19
View File
@@ -66,7 +66,7 @@ from shared import constants
from bson.objectid import ObjectId from bson.objectid import ObjectId
# Data Models: # Data Models:
from models.api.software.auth import SoftwareAuthRequestHeaders, SoftwareAuthRequestData from models.api.finstitutions.payments.auth import PGAuthRequestHeaders, PGAuthRequestData
from models.core.auth_token import CoreAuthTokenModel from models.core.auth_token import CoreAuthTokenModel
# For asynchronous activities: # For asynchronous activities:
@@ -81,7 +81,7 @@ import asyncio
# Related to Quart: # Related to Quart:
fi_auth_bp = Blueprint("fi_auth", __name__) pg_auth_bp = Blueprint("pg_auth", __name__)
# ***************************************************************************************************************** # *****************************************************************************************************************
@@ -101,7 +101,7 @@ fi_auth_bp = Blueprint("fi_auth", __name__)
# ***************************************************************************************************************** # *****************************************************************************************************************
@fi_auth_bp.record_once @pg_auth_bp.record_once
def init(blueprint_setup_state): def init(blueprint_setup_state):
# This gets called when the blueprint is registered. # This gets called when the blueprint is registered.
@@ -112,7 +112,7 @@ def init(blueprint_setup_state):
# --------------------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------------------
@fi_auth_bp.route("/auth", methods = ["POST"]) @pg_auth_bp.route("/auth", methods = ["POST"])
@set_api_version(api_version = "1.0.0") @set_api_version(api_version = "1.0.0")
@read_input(sanitize_headers = False, sanitize_data = False) @read_input(sanitize_headers = False, sanitize_data = False)
@get_session_info(key = "X-Session-Token", session_coro = "get_session") @get_session_info(key = "X-Session-Token", session_coro = "get_session")
@@ -120,7 +120,7 @@ def init(blueprint_setup_state):
attr_name = "logs_mongo", attr_name = "logs_mongo",
project = constants.PROJECT_NAME, project = constants.PROJECT_NAME,
log_type = constants.MODULE_NAME, log_type = constants.MODULE_NAME,
operation = "smsAuthApi", operation = "pgAuthApi",
log_input = True, log_input = True,
log_output = True, log_output = True,
sensitive_keys = ["sessionToken", "X-Session-Token"] sensitive_keys = ["sessionToken", "X-Session-Token"]
@@ -128,19 +128,19 @@ def init(blueprint_setup_state):
@log_chain_to_mongo(attr_name = "logs_mongo") @log_chain_to_mongo(attr_name = "logs_mongo")
@should_not_be_under_maintenance(attr_name = "is_under_maintenance") @should_not_be_under_maintenance(attr_name = "is_under_maintenance")
@validate_input( @validate_input(
header_validator = lambda x: SoftwareAuthRequestHeaders(**x).model_dump(), header_validator = lambda x: PGAuthRequestHeaders(**x).model_dump(),
data_validator = lambda x: SoftwareAuthRequestData(**x) data_validator = lambda x: PGAuthRequestData(**x)
) )
@handle_cancelled_request() @handle_cancelled_request()
async def authorize_software_client( async def authorize_payment_gateway(
inbound_headers: dict | SoftwareAuthRequestHeaders = None, inbound_headers: dict | PGAuthRequestHeaders = None,
inbound_data: dict | SoftwareAuthRequestData = None, inbound_data: dict | PGAuthRequestData = None,
inbound_files: dict = None, inbound_files: dict = None,
**kwargs **kwargs
): ):
""" """
God knows. Don't ask. To accept the authorization details of payment gateways.
:param inbound_headers: auto-extracted by the decorators. :param inbound_headers: auto-extracted by the decorators.
:param inbound_data: auto-extracted by the decorators. :param inbound_data: auto-extracted by the decorators.
:param inbound_files: auto-extracted by the decorators. :param inbound_files: auto-extracted by the decorators.
@@ -163,19 +163,22 @@ async def authorize_software_client(
# Start by assuming failure: # Start by assuming failure:
success = False success = False
# ┏┳┓┏┓┏┓ ┏┓┏┏• ┏┓ # ┏┓ • ┳┳┓ ┏┓ ┏┓
# ┃ ┣┓┏┓ ┃ ┣┫ ┃┃╋╋┓┏┏┓ ┣┫┃ # ┗┓┏┓╋┏┓┏┓┓┏┏┓┏┓ ┃┃┃━━┃┃┏┓┏┏┓ ┣ ┓┏┏┓┏┓┏┓┏┏
# ┛┗┗ ┗┛┗ ┗┛┛┛┗┗┗ ┛┗┻ # ┗┛┗┻┛┗┻┛ ┗┗┗┛┛┗┗ ┣┛┗ ┛┗ ┗┛┛┗┣┛┛ ┗ ┛┛
# ┛
if inbound_data.softwareClient == "theCaOfficeAi": if inbound_data.client == "safaricomMPesaExpress":
auth_token = CoreAuthTokenModel( auth_token = CoreAuthTokenModel(
serviceType = "software", serviceType = "paymentGateway",
client = inbound_data.softwareClient, client = inbound_data.client,
authType = "auth", authType = "auth",
auth = inbound_data.auth.model_dump(), auth = inbound_data.auth.model_dump(),
user = kwargs.get("session_info"), user = kwargs.get("session_info"),
clientUserId = {}, clientUserId = {
"businessShortCode": inbound_data.auth.businessShortCode
},
status = "active", status = "active",
syncFreq = 60 syncFreq = 60
) )
@@ -207,7 +210,7 @@ async def authorize_software_client(
status_code = StatusCodes.OK if success else StatusCodes.FAILED, status_code = StatusCodes.OK if success else StatusCodes.FAILED,
http_code = HttpCodes.SUCCESS if success else HttpCodes.INTERNAL_SERVER_ERROR, http_code = HttpCodes.SUCCESS if success else HttpCodes.INTERNAL_SERVER_ERROR,
data = { data = {
"client": inbound_data.softwareClient, "client": inbound_data.client,
"authorized": success "authorized": success
} }
) )
+2
View File
@@ -96,6 +96,7 @@ from api.blueprints.sms.send import sms_send_bp
# from api.blueprints.chat.auth import chat_auth_bp # from api.blueprints.chat.auth import chat_auth_bp
# from api.blueprints.chat.webhook import chat_webhook_bp # from api.blueprints.chat.webhook import chat_webhook_bp
from api.blueprints.software.auth import sw_auth_bp from api.blueprints.software.auth import sw_auth_bp
from api.blueprints.finstitutions.payments.auth import pg_auth_bp
from api.blueprints.tech.chat_alerts import tech_chat_alert_bp from api.blueprints.tech.chat_alerts import tech_chat_alert_bp
from api.blueprints.test.callback import test_callback_bp from api.blueprints.test.callback import test_callback_bp
from api.blueprints.ai.llm.invoke import llm_invoke_bp from api.blueprints.ai.llm.invoke import llm_invoke_bp
@@ -137,6 +138,7 @@ app.register_blueprint(sms_send_bp, url_prefix = f"/{MODULE_BASE}/sms")
# app.register_blueprint(chat_auth_bp, url_prefix = f"/{MODULE_BASE}/chat") # app.register_blueprint(chat_auth_bp, url_prefix = f"/{MODULE_BASE}/chat")
# app.register_blueprint(chat_webhook_bp, url_prefix = f"/{MODULE_BASE}/chat") # app.register_blueprint(chat_webhook_bp, url_prefix = f"/{MODULE_BASE}/chat")
app.register_blueprint(sw_auth_bp, url_prefix = f"/{MODULE_BASE}/software") app.register_blueprint(sw_auth_bp, url_prefix = f"/{MODULE_BASE}/software")
app.register_blueprint(pg_auth_bp, url_prefix = f"/{MODULE_BASE}/finstitutions/payments")
app.register_blueprint(tech_chat_alert_bp, url_prefix = f"/{MODULE_BASE}/tech/alert") app.register_blueprint(tech_chat_alert_bp, url_prefix = f"/{MODULE_BASE}/tech/alert")
app.register_blueprint(test_callback_bp, url_prefix = f"/{MODULE_BASE}/test") app.register_blueprint(test_callback_bp, url_prefix = f"/{MODULE_BASE}/test")
app.register_blueprint(llm_invoke_bp, url_prefix = f"/{MODULE_BASE}/ai") app.register_blueprint(llm_invoke_bp, url_prefix = f"/{MODULE_BASE}/ai")
+13 -13
View File
@@ -75,25 +75,25 @@ REGEX_SESSION_TOKEN = r"^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]
# ***************************************************************************************************************** # *****************************************************************************************************************
class TheCAOfficeAIAuth(BaseModel): class SafaricomMPesaExpressAuth(BaseModel):
authorizeSoftware: bool = Field( consumerKey: str = Field(
description = "god knows; don't ask", description = "the app's consumer key given by safaricom; found in 'my apps'",
frozen = True frozen = True
) )
authorizeMailMessaging: bool = Field( consumerSecret: str = Field(
description = "god knows; don't ask", description = "the app's consumer secret given by safaricom; found in 'my apps'",
frozen = True frozen = True
) )
authorizeCompliancePortal: bool = Field( businessShortCode: str = Field(
description = "god knows; don't ask", description = "your app's business short code; found in 'my apps'",
frozen = True frozen = True
) )
authorizeFinancialInstitution: bool = Field( appPasskey: str = Field(
description = "god knows; don't ask", description = "your app's passkey; taken from human representative",
frozen = True frozen = True
) )
@@ -109,7 +109,7 @@ class TheCAOfficeAIAuth(BaseModel):
# --------------------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------------------
class SoftwareAuthRequestHeaders(BaseModel): class PGAuthRequestHeaders(BaseModel):
sessionToken: str = Field( sessionToken: str = Field(
description = "the session token of the user who is requesting the service", description = "the session token of the user who is requesting the service",
@@ -133,10 +133,10 @@ class SoftwareAuthRequestHeaders(BaseModel):
# --------------------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------------------
class SoftwareAuthRequestData(BaseModel): class PGAuthRequestData(BaseModel):
softwareClient: Literal["theCaOfficeAi"] = Field(alias = "client") client: Literal["safaricomMPesaExpress"] = Field(alias = "client")
auth: Union[TheCAOfficeAIAuth] auth: Union[SafaricomMPesaExpressAuth]
# ┏┓ ┏• # ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓ # ┃ ┏┓┏┓╋┓┏┓
+2 -2
View File
@@ -89,7 +89,7 @@ class CoreAuthTokenModel(BaseModel):
alias = "_id" alias = "_id"
) )
serviceType: Literal["software", "email", "sms", "chat"] = Field( serviceType: Literal["software", "email", "sms", "chat", "paymentGateway"] = Field(
description = "the kind of service this message was sent/received from", description = "the kind of service this message was sent/received from",
frozen = True frozen = True
) )
@@ -99,7 +99,7 @@ class CoreAuthTokenModel(BaseModel):
"telegram", "whatsapp", # .................. Chat Clients "telegram", "whatsapp", # .................. Chat Clients
"nimbusSmsIndia", "savvyBulkSmsKenya", # ... SMS Clients "nimbusSmsIndia", "savvyBulkSmsKenya", # ... SMS Clients
"razorpay", "safaricomMPesaExpress", # ..... Payment Gateways "razorpay", "safaricomMPesaExpress", # ..... Payment Gateways
"theCaOfficeAi" # .......................... God knows, don't ask. "theCaOfficeAi" # .......................... Software
] = Field( ] = Field(
description = "the third-part client that was used", description = "the third-part client that was used",
frozen = True frozen = True