(20241217) Safaricom M-Pesa upgraded to capture messages better.

This commit is contained in:
2024-12-17 14:20:14 +05:30
parent 52c0b0baaf
commit d47060c4db
@@ -41,6 +41,7 @@ import io
# My utils:
from utils_v2.string import json
from utils_v2.string import regex
from utils_v2.date_time import date_time
# Data models:
@@ -346,16 +347,18 @@ class SafaricomMPesaExpress:
)
# If the call failed:
if api_response.httpCode == 400:
if api_response.httpCode not in [200]:
api_json = await api_response.get_json()
api_response.message = f"{api_json['errorCode']} -> {api_json['errorMessage']}"
# If the call failed:
if api_response.httpCode in [200]:
else:
api_json = await api_response.get_json()
success = True if str(api_json.get("ResponseCode")) == "0" else False
api_response.message = api_json.get("ResponseDescription", "N/A")
api_response.data = api_json
api_response.success = True if str(api_json.get("ResponseCode")) == "0" else False
api_response.success = success
api_response.referenceId = str(api_json["CheckoutRequestID"])
# Done here:
return api_response