(20241217) Safaricom M-Pesa upgraded to capture messages better.
This commit is contained in:
@@ -41,6 +41,7 @@ import io
|
|||||||
|
|
||||||
# My utils:
|
# My utils:
|
||||||
from utils_v2.string import json
|
from utils_v2.string import json
|
||||||
|
from utils_v2.string import regex
|
||||||
from utils_v2.date_time import date_time
|
from utils_v2.date_time import date_time
|
||||||
|
|
||||||
# Data models:
|
# Data models:
|
||||||
@@ -346,16 +347,18 @@ class SafaricomMPesaExpress:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# If the call failed:
|
# If the call failed:
|
||||||
if api_response.httpCode == 400:
|
if api_response.httpCode not in [200]:
|
||||||
api_json = await api_response.get_json()
|
api_json = await api_response.get_json()
|
||||||
api_response.message = f"{api_json['errorCode']} -> {api_json['errorMessage']}"
|
api_response.message = f"{api_json['errorCode']} -> {api_json['errorMessage']}"
|
||||||
|
|
||||||
# If the call failed:
|
# If the call failed:
|
||||||
if api_response.httpCode in [200]:
|
else:
|
||||||
api_json = await api_response.get_json()
|
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.message = api_json.get("ResponseDescription", "N/A")
|
||||||
api_response.data = api_json
|
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:
|
# Done here:
|
||||||
return api_response
|
return api_response
|
||||||
|
|||||||
Reference in New Issue
Block a user