Skip to content

Commit 2d24008

Browse files
added bug monitoring tool to mobile money, transfer and VA services
1 parent 3b7f49d commit 2d24008

File tree

7 files changed

+97
-19
lines changed

7 files changed

+97
-19
lines changed

rave_python/rave_mpesa.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from rave_python.rave_exceptions import RaveError, IncompletePaymentDetailsError, AccountChargeError, TransactionVerificationError, TransactionValidationError, ServerError
2-
32
from rave_python.rave_payment import Payment
43
from rave_python.rave_misc import generateTransactionReference
5-
import json
4+
import json, requests
65

76
class Mpesa(Payment):
87

@@ -11,11 +10,19 @@ def __init__(self, publicKey, secretKey, production, usingEnv):
1110

1211
# Charge mobile money function
1312
def charge(self, accountDetails, hasFailed=False):
13+
1414
""" This is the mpesa charge call.\n
1515
Parameters include:\n
1616
accountDetails (dict) -- These are the parameters passed to the function for processing\n
1717
hasFailed (boolean) -- This is a flag to determine if the attempt had previously failed due to a timeout\n
1818
"""
19+
20+
#feature logging
21+
tracking_endpoint = self._trackingMap
22+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": "Incoming call","message": "Initiate-Mpesa-charge"}
23+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
24+
25+
## feature logic
1926
# Setting the endpoint
2027
endpoint = self._baseUrl + self._endpointMap["account"]["charge"]
2128
# Adding boilerplate mpesa requirements

rave_python/rave_rwmobile.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from rave_python.rave_payment import Payment
22
from rave_python.rave_misc import generateTransactionReference
3-
import json
3+
import json, requests
44

55
class RWMobile(Payment):
66

@@ -10,16 +10,22 @@ def __init__(self, publicKey, secretKey, production, usingEnv):
1010

1111
# Charge mobile money function
1212
def charge(self, accountDetails, hasFailed=False):
13+
1314
""" This is the RWMobile charge call.
1415
Parameters include:\n
1516
accountDetails (dict) -- These are the parameters passed to the function for processing\n
1617
hasFailed (boolean) -- This is a flag to determine if the attempt had previously failed due to a timeout\n
1718
"""
1819

20+
#feature logging
21+
tracking_endpoint = self._trackingMap
22+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": "Incoming call","message": "Initiate-Zambia-mobile-money-charge"}
23+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
24+
25+
#feature logic
1926
endpoint = self._baseUrl + self._endpointMap["account"]["charge"]
2027
# It is faster to add boilerplate than to check if each one is present
2128
accountDetails.update({"payment_type": "mobilemoneygh", "country":"NG", "is_mobile_money_gh":"1", "currency":"RWF", "network": "RWF"})
22-
2329
# If transaction reference is not set
2430
if not ("txRef" in accountDetails):
2531
accountDetails.update({"txRef": generateTransactionReference()})

rave_python/rave_transfer.py

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,32 @@ def _handleBulkResponse(self, response, bulkDetails):
4646

4747

4848
def initiate(self, transferDetails):
49+
50+
#feature logging
51+
tracking_endpoint = self._trackingMap
52+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": "Incoming call","message": "Initiate-Transfer"}
53+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
54+
55+
## feature logic
56+
4957
# Performing shallow copy of transferDetails to avoid public exposing payload with secret key
5058
transferDetails = copy.copy(transferDetails)
51-
59+
5260
# adding reference if not already included
5361
if not ("reference" in transferDetails):
5462
transferDetails.update({"reference": generateTransactionReference()})
5563
transferDetails.update({"seckey": self._getSecretKey()})
56-
64+
5765
# These are the parameters required to initiate a transfer
5866
requiredParameters = ["amount", "currency","beneficiary_name"]
59-
6067
checkIfParametersAreComplete(requiredParameters, transferDetails)
6168
checkTransferParameters(requiredParameters, transferDetails)
62-
69+
6370
# Collating request headers
6471
headers = {
6572
'content-type': 'application/json',
6673
}
67-
74+
6875
endpoint = self._baseUrl + self._endpointMap["transfer"]["initiate"]
6976
response = requests.post(endpoint, headers=headers, data=json.dumps(transferDetails))
7077
return self._handleInitiateResponse(response, transferDetails)
@@ -73,21 +80,25 @@ def initiate(self, transferDetails):
7380

7481
def bulk(self, bulkDetails):
7582

83+
#feature logging
84+
tracking_endpoint = self._trackingMap
85+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": "Incoming call","message": "Initiate-bulk-Transfer"}
86+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
87+
88+
# feature logic
7689
bulkDetails = copy.copy(bulkDetails)
90+
7791
# Collating request headers
7892
headers = {
7993
'content-type': 'application/json',
8094
}
8195

8296
bulkDetails.update({"seckey": self._getSecretKey()})
83-
8497
requiredParameters = ["title", "bulk_data"]
85-
8698
checkIfParametersAreComplete(requiredParameters, bulkDetails)
87-
8899
checkTransferParameters(requiredParameters, bulkDetails)
89-
90100
endpoint = self._baseUrl + self._endpointMap["transfer"]["bulk"]
101+
91102
# Collating request headers
92103
headers = {
93104
'content-type': 'application/json',
@@ -98,6 +109,7 @@ def bulk(self, bulkDetails):
98109

99110
# This makes and handles all requests pertaining to the status of your transfer or account
100111
def _handleTransferStatusRequests(self, endpoint, isPostRequest=False, data=None):
112+
101113
# Request headers
102114
headers = {
103115
'content-type': 'application/json',
@@ -123,25 +135,54 @@ def _handleTransferStatusRequests(self, endpoint, isPostRequest=False, data=None
123135

124136
# Not elegant but supports python 2 and 3
125137
def fetch(self, reference=None):
138+
139+
#feature logging
140+
tracking_endpoint = self._trackingMap
141+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": "Incoming call","message": "Fetch-Transfer"}
142+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
143+
144+
#feature logic
126145
endpoint = self._baseUrl + self._endpointMap["transfer"]["fetch"] + "?seckey="+self._getSecretKey()+'&reference='+str(reference)
127146
return self._handleTransferStatusRequests(endpoint)
128147

129148
def all(self):
149+
150+
#feature logging
151+
tracking_endpoint = self._trackingMap
152+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": "Incoming call","message": "List-all-Transfers"}
153+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
154+
155+
#feature logic
130156
endpoint = self._baseUrl + self._endpointMap["transfer"]["fetch"] + "?seckey="+self._getSecretKey()
131157
return self._handleTransferStatusRequests(endpoint)
132158

133159
def getFee(self, currency=None):
160+
161+
# feature logging
162+
tracking_endpoint = self._trackingMap
163+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": "Incoming call","message": "Get-Transfer-fee-by-Currency"}
164+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
165+
166+
# feature logic
134167
endpoint = self._baseUrl + self._endpointMap["transfer"]["fee"] + "?seckey="+self._getSecretKey() + "&currency="+str(currency)
135168
return self._handleTransferStatusRequests(endpoint)
136169

137170
def getBalance(self, currency):
171+
172+
# feature logging
173+
tracking_endpoint = self._trackingMap
174+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": "Incoming call","message": "Get-Balance-fee-by-Currency"}
175+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
176+
177+
# feature logic
138178
if not currency: # i made currency compulsory because if it is not assed in, an error message is returned from the server
139179
raise IncompletePaymentDetailsError("currency", ["currency"])
140180
endpoint = self._baseUrl + self._endpointMap["transfer"]["balance"]
141181
data = {
142182
"seckey": self._getSecretKey(),
143183
"currency": currency
144184
}
185+
145186
return self._handleTransferStatusRequests(endpoint, data=data, isPostRequest=True)
146187

147188

rave_python/rave_ugmobile.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from rave_python.rave_payment import Payment
22
from rave_python.rave_misc import generateTransactionReference
3-
import json
3+
import json, requests
44

55
class UGMobile(Payment):
66

@@ -10,16 +10,22 @@ def __init__(self, publicKey, secretKey, production, usingEnv):
1010

1111
# Charge mobile money function
1212
def charge(self, accountDetails, hasFailed=False):
13+
1314
""" This is the ghMobile charge call.
1415
Parameters include:\n
1516
accountDetails (dict) -- These are the parameters passed to the function for processing\n
1617
hasFailed (boolean) -- This is a flag to determine if the attempt had previously failed due to a timeout\n
1718
"""
1819

20+
#feature logging
21+
tracking_endpoint = self._trackingMap
22+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": "Incoming call","message": "Initiate-Uganda-mobile-money-charge"}
23+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
24+
25+
## feature logic
1926
endpoint = self._baseUrl + self._endpointMap["account"]["charge"]
2027
# It is faster to add boilerplate than to check if each one is present
2128
accountDetails.update({"payment_type": "mobilemoneyuganda", "country":"NG", "is_mobile_money_ug":"1", "currency":"UGX", "network": "UGX"})
22-
2329
# If transaction reference is not set
2430
if not ("txRef" in accountDetails):
2531
accountDetails.update({"txRef": generateTransactionReference()})

rave_python/rave_verify.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ def _handleVerifyStatusRequests(self, endpoint, isPostRequest=False, data=None):
5656
raise BVNFetchError({"error": True, "returnedData": responseJson })
5757

5858
def bvnVerify(self, bvn):
59+
60+
#feature logging
61+
tracking_endpoint = self._trackingMap
62+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": "Incoming call","message": "BVN-verification"}
63+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
64+
65+
# feature logic
5966
if not bvn:
6067
return "BVN was not supplied. Kindly supply one"
6168
endpoint = self._baseUrl + self._endpointMap["bvn"]["verify"] +str(bvn)+"?seckey=" + self._getSecretKey()

rave_python/rave_virtualaccount.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,17 @@ def _handleCreateResponse(self, response, accountDetails):
5959
#function to create a virtual card
6060
#Params: cardDetails - a dict containing email, is_permanent, frequency, duration, narration
6161
def create(self, accountDetails):
62+
63+
#feature logging
64+
tracking_endpoint = self._trackingMap
65+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": "Incoming call","message": "Create-virtual-account"}
66+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
67+
68+
# feature logic
6269
accountDetails = copy.copy(accountDetails)
6370
accountDetails.update({"seckey": self._getSecretKey()})
64-
6571
requiredParameters = ["email", "narration"]
6672
checkIfParametersAreComplete(requiredParameters, accountDetails)
67-
6873
endpoint = self._baseUrl + self._endpointMap["virtual_account"]["create"]
6974
response = requests.post(endpoint, headers=self.headers, data=json.dumps(accountDetails))
7075
return self._handleCreateResponse(response, accountDetails)

rave_python/rave_zbmobile.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from rave_python.rave_payment import Payment
22
from rave_python.rave_misc import generateTransactionReference
3-
import json
3+
import json, requests
44

55
class ZBMobile(Payment):
66

@@ -10,16 +10,22 @@ def __init__(self, publicKey, secretKey, production, usingEnv):
1010

1111
# Charge mobile money function
1212
def charge(self, accountDetails, hasFailed=False):
13+
1314
""" This is the ghMobile charge call.
1415
Parameters include:\n
1516
accountDetails (dict) -- These are the parameters passed to the function for processing\n
1617
hasFailed (boolean) -- This is a flag to determine if the attempt had previously failed due to a timeout\n
1718
"""
1819

20+
#feature logging
21+
tracking_endpoint = self._trackingMap
22+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": "Incoming call","message": "Initiate-Zambia-mobile-money-charge"}
23+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
24+
25+
## Feature logic
1926
endpoint = self._baseUrl + self._endpointMap["account"]["charge"]
2027
# It is faster to add boilerplate than to check if each one is present
2128
accountDetails.update({"payment_type": "mobilemoneyzambia", "country":"NG", "is_mobile_money_ug":"1", "currency":"ZMW", "network": "MTN"})
22-
2329
# If transaction reference is not set
2430
if not ("txRef" in accountDetails):
2531
accountDetails.update({"txRef": generateTransactionReference()})

0 commit comments

Comments
 (0)