(20250102) Alerts on payment events.

This commit is contained in:
2025-01-02 11:53:13 +00:00
parent fd2a1ef6d1
commit cb8e322c10
5 changed files with 57 additions and 14 deletions
+2 -2
View File
@@ -46,7 +46,7 @@ from utils_v2.api.codes import StatusCodes
from icecream import IceCreamDebugger
# To work with datatypes:
from typing import List
from typing import List, Literal
# *****************************************************************************************************************
@@ -141,7 +141,7 @@ class CoreBaseModel:
self,
message: str,
session_token = None,
alert_type = "error"
alert_type: Literal["info", "warn", "error"] = "error"
):
"""
@@ -351,8 +351,6 @@ class PaymentsController(CoreAuthTokenController, ABC):
session_token = session_token
)
print("RECEIPT ADD SQL JSON:", json.to_string(sql_json, default=str))
# Return the response:
if sql_json["status"] == 1: return True
else: return False
@@ -296,11 +296,11 @@ class SafaricomMPesaExpressPaymentsController(PaymentsController):
code_map = {
0: {
"status": "settled",
"message": "Payment successful :)"
"message": "Payment successful (0)."
}, # ... Success
1037: {
"status": "failed",
"message": "The payment gateway could not reach your customer."
"message": "The payment gateway could not reach your customer (1037)."
}, # ... DS Timeout. User could not be reached.
1025: {
"status": "failed",
@@ -312,23 +312,23 @@ class SafaricomMPesaExpressPaymentsController(PaymentsController):
}, # ... System error while trying to send the push request.
1032: {
"status": "rejected",
"message": "Your customer declined the payment request."
"message": "Your customer declined the payment request (1032)."
}, # ... Request Cancelled by the user.
1: {
"status": "failed",
"message": "Your customer has insufficient balance."
"message": "Your customer has insufficient balance (1)."
}, # ... The user has insufficient balance.
2001: {
"status": "failed",
"message": "The payment gateway says your credentials are invalid."
"message": "The payment gateway says your credentials are invalid (2001)."
}, # ... Invalid credentials of the initiator.
1019: {
"status": "failed",
"message": "The transaction expired before your customer processed it."
"message": "The transaction expired before your customer processed it (1019)."
}, # ... Transaction expired.
1001: {
"status": "failed",
"message": "Your customer is already in the middle of some transaction on the payment gateway."
"message": "Your customer is already in the middle of some transaction on the payment gateway (1001)."
}, # ... The payer is already making some transaction.
}
@@ -366,9 +366,15 @@ class SafaricomMPesaExpressPaymentsController(PaymentsController):
client_reference_id = pg_reference_id
)
# Send an alert for debugging:
await self.send_alert(
payment.to_markdown(include_events = True),
alert_type = "info"
)
# For when the payment is successful:
if pg_result_code in [0]:
await self.add_receipt(
receipt_added = await self.add_receipt(
sql_conn = sql_conn,
mongo_data_conn = mongo_data_conn,
payment = payment,