11"""This module contains the functions that make networks requests to whmcs."""
22
33import requests
4+ from django .conf import settings
45from requests .exceptions import RequestException
56
67from olittwhmcs .exceptions import WhmcsConnectionError
@@ -16,7 +17,7 @@ def get_whmcs_response(parameters):
1617 try :
1718 response = make_whmcs_network_request (parameters )
1819 response_data = get_response_data (response )
19- result = response_data .get (' result' )
20+ result = response_data .get (" result" )
2021 if response .ok and result == "success" :
2122 return True , response_data
2223 error = get_error_message (response_data )
@@ -33,8 +34,11 @@ def make_whmcs_network_request(parameters):
3334 :rtype: requests.Response
3435 :raises WhmcsConnectionError: If the network request fails.
3536 """
36- # ToDo: Read this url from consumers or settings.py (or from env variables if not possible)
37- url = "https://www.olitt.com/billing/includes/api.php"
37+ url = (
38+ f"{ settings .WHMCS_BASE_URL } /includes/api.php"
39+ if settings .WHMCS_BASE_URL
40+ else "https://www.olitt.com/billing/includes/api.php"
41+ )
3842 try :
3943 return requests .post (url = url , data = parameters )
4044 except RequestException :
@@ -57,13 +61,14 @@ def get_response_data(response):
5761def get_error_message (response_data ):
5862 """
5963 Extract an error message from whmcs response data.
60- :param response_data: Dictionary, data received from whmcs from which to extract the message.
64+ :param response_data: Dictionary, data received from
65+ whmcs from which to extract the message.
6166 :return: Error message in the whmcs response data.
6267 :rtype: String or None
6368 """
6469 if type (response_data ) is dict :
65- result = response_data .get (' result' , None )
66- error = response_data .get (' message' , None )
70+ result = response_data .get (" result" , None )
71+ error = response_data .get (" message" , None )
6772 if result == "error" :
6873 return error
6974 return None
0 commit comments