Skip to content

Commit 09f1832

Browse files
added latency and status code to monitoring params
1 parent 2d24008 commit 09f1832

10 files changed

+139
-87
lines changed

rave_python/rave_bills.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,25 @@ def _handleCreateResponse(self, response, details):
4141
#function to create a Bill
4242
#Params: details - a dict containing service, service_method, service_version, service_channel and service_payload
4343
def create(self, details):
44+
4445
# Performing shallow copy of planDetails to avoid public exposing payload with secret key
4546
details = copy.copy(details)
4647
details.update({"seckey": self._getSecretKey()})
47-
4848
requiredParameters = ["service", "service_method", "service_version", "service_channel"]
4949
checkIfParametersAreComplete(requiredParameters, details)
50-
5150
endpoint = self._baseUrl + self._endpointMap["bills"]["create"]
5251
response = requests.post(endpoint, headers=self.headers, data=json.dumps(details))
52+
53+
# feature logging
54+
if response.ok == False:
55+
tracking_endpoint = self._trackingMap
56+
responseTime = response.elapsed.total_seconds()
57+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": "Create-Bills-error", "message": responseTime}
58+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
59+
else:
60+
tracking_endpoint = self._trackingMap
61+
responseTime = response.elapsed.total_seconds()
62+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": "Create-Bills", "message": responseTime}
63+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
64+
5365
return self._handleCreateResponse(response, details)

rave_python/rave_card.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def charge(self, cardDetails, hasFailed=False, chargeWithToken=False):
9393
hasFailed (bool) -- This indicates whether the request had previously failed for timeout handling
9494
"""
9595
# setting the endpoint
96+
feature_name = "Initiate-Card-charge"
9697
if not chargeWithToken:
9798
endpoint = self._baseUrl + self._endpointMap["card"]["charge"]
9899
requiredParameters = ["cardno", "cvv", "expirymonth", "expiryyear", "amount", "email", "IP", "phonenumber", "firstname", "lastname"]
@@ -111,17 +112,18 @@ def charge(self, cardDetails, hasFailed=False, chargeWithToken=False):
111112
if not ("txRef" in cardDetails):
112113
cardDetails.update({"txRef":generateTransactionReference()})
113114

114-
115-
return super(Card, self).charge(cardDetails, requiredParameters, endpoint)
115+
return super(Card, self).charge(feature_name, cardDetails, requiredParameters, endpoint)
116116

117117

118118
def validate(self, flwRef, otp):
119+
feature_name = "Validate-Card-charge"
119120
endpoint = self._baseUrl + self._endpointMap["card"]["validate"]
120-
return super(Card, self).validate(flwRef, otp, endpoint)
121+
return super(Card, self).validate(feature_name, flwRef, otp, endpoint)
121122

122123
def verify(self, txRef):
124+
feature_name = "Verify-Card-charge"
123125
endpoint = self._baseUrl + self._endpointMap["card"]["verify"]
124-
return super(Card, self).verify(txRef, endpoint)
126+
return super(Card, self).verify(feature_name, txRef, endpoint)
125127

126128

127129

rave_python/rave_francophone.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def charge(self, accountDetails, hasFailed=False):
4949
hasFailed (boolean) -- This is a flag to determine if the attempt had previously failed due to a timeout\n
5050
"""
5151

52+
feature_name = "Initiate-Francophone-mobile-money-charge"
5253
endpoint = self._baseUrl + self._endpointMap["account"]["charge"]
5354
# It is faster to add boilerplate than to check if each one is present
5455
accountDetails.update({"payment_type": "mobilemoneyfrancophone", "is_mobile_money_franco":"1"})
@@ -62,4 +63,4 @@ def charge(self, accountDetails, hasFailed=False):
6263
# Checking for required account components
6364
# requiredParameters = ["amount", "email", "phonenumber", "IP", "redirect_url"]
6465
requiredParameters = ["amount"]
65-
return super(Francophone, self).charge(accountDetails, requiredParameters, endpoint)
66+
return super(Francophone, self).charge(feature_name, accountDetails, requiredParameters, endpoint)

rave_python/rave_ghmobile.py

Lines changed: 5 additions & 4 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 GhMobile(Payment):
66

@@ -10,17 +10,18 @@ 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
"""
18-
19+
1920
endpoint = self._baseUrl + self._endpointMap["account"]["charge"]
21+
feature_name = "Initiate-Ghana-mobile-money-charge"
2022

2123
# It is faster to add boilerplate than to check if each one is present
2224
accountDetails.update({"payment_type": "mobilemoneygh", "country":"GH", "is_mobile_money_gh":"1", "currency":"GHS"})
23-
2425
# If transaction reference is not set
2526
if not ("txRef" in accountDetails):
2627
accountDetails.update({"txRef": generateTransactionReference()})
@@ -30,5 +31,5 @@ def charge(self, accountDetails, hasFailed=False):
3031

3132
# Checking for required account components
3233
requiredParameters = ["amount", "email", "phonenumber", "network", "IP", "redirect_url"]
33-
return super(GhMobile, self).charge(accountDetails, requiredParameters, endpoint)
34+
return super(GhMobile, self).charge(feature_name, accountDetails, requiredParameters, endpoint)
3435

rave_python/rave_mpesa.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@ def charge(self, accountDetails, hasFailed=False):
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-
2519
## feature logic
2620
# Setting the endpoint
21+
feature_name = "Initiate-Mpesa-charge"
2722
endpoint = self._baseUrl + self._endpointMap["account"]["charge"]
2823
# Adding boilerplate mpesa requirements
2924
accountDetails.update({"payment_type": "mpesa", "country":"KE", "is_mpesa":"1", "is_mpesa_lipa":"1", "currency":"KES"})
@@ -36,9 +31,10 @@ def charge(self, accountDetails, hasFailed=False):
3631

3732
# Checking for required account components
3833
requiredParameters = ["amount", "email", "phonenumber", "IP"]
39-
res = super(Mpesa, self).charge(accountDetails, requiredParameters, endpoint, isMpesa=True)
34+
res = super(Mpesa, self).charge(feature_name, accountDetails, requiredParameters, endpoint, isMpesa=True)
4035
return res
4136

4237
def verify(self, txRef):
38+
feature_name = "Verify-Mpesa_charge"
4339
endpoint = self._baseUrl + self._endpointMap["account"]["verify"]
44-
return super(Mpesa, self).verify(txRef, endpoint)
40+
return super(Mpesa, self).verify(feature_name, txRef, endpoint)

rave_python/rave_payment.py

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def _handleValidateResponse(self, response, flwRef, request=None):
174174

175175

176176
# Charge function (hasFailed is a flag that indicates there is a timeout), shouldReturnRequest indicates whether to send the request back to the _handleResponses function
177-
def charge(self, paymentDetails, requiredParameters, endpoint, shouldReturnRequest=False, isMpesa=False):
177+
def charge(self, feature_name, paymentDetails, requiredParameters, endpoint, shouldReturnRequest=False, isMpesa=False):
178178
""" This is the base charge call. It is usually overridden by implementing classes.\n
179179
Parameters include:\n
180180
paymentDetails (dict) -- These are the parameters passed to the function for processing\n
@@ -213,6 +213,18 @@ def charge(self, paymentDetails, requiredParameters, endpoint, shouldReturnReque
213213
"alg": "3DES-24"
214214
}
215215
response = requests.post(endpoint, headers=headers, data=json.dumps(payload))
216+
217+
#feature logging
218+
if response.ok:
219+
tracking_endpoint = self._trackingMap
220+
responseTime = response.elapsed.total_seconds()
221+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": feature_name, "message": responseTime}
222+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
223+
else:
224+
tracking_endpoint = self._trackingMap
225+
responseTime = response.elapsed.total_seconds()
226+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": feature_name + "-error", "message": responseTime}
227+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
216228

217229
if shouldReturnRequest:
218230
if isMpesa:
@@ -222,9 +234,10 @@ def charge(self, paymentDetails, requiredParameters, endpoint, shouldReturnReque
222234
if isMpesa:
223235
return self._handleChargeResponse(response, paymentDetails["txRef"], paymentDetails, True)
224236
return self._handleChargeResponse(response, paymentDetails["txRef"])
237+
225238

226239

227-
def validate(self, flwRef, otp, endpoint=None):
240+
def validate(self, feature_name, flwRef, otp, endpoint=None):
228241
""" This is the base validate call.\n
229242
Parameters include:\n
230243
flwRef (string) -- This is the flutterwave reference returned from a successful charge call. You can access this from action["flwRef"] returned from the charge call\n
@@ -247,10 +260,23 @@ def validate(self, flwRef, otp, endpoint=None):
247260
}
248261

249262
response = requests.post(endpoint, headers = headers, data=json.dumps(payload))
263+
264+
#feature logging
265+
if response.ok:
266+
tracking_endpoint = self._trackingMap
267+
responseTime = response.elapsed.total_seconds()
268+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": feature_name, "message": responseTime}
269+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
270+
else:
271+
tracking_endpoint = self._trackingMap
272+
responseTime = response.elapsed.total_seconds()
273+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": feature_name + "-error", "message": responseTime}
274+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
275+
250276
return self._handleValidateResponse(response, flwRef)
251277

252278
# Verify charge
253-
def verify(self, txRef, endpoint=None):
279+
def verify(self, feature_name, txRef, endpoint=None):
254280
""" This is used to check the status of a transaction.\n
255281
Parameters include:\n
256282
txRef (string) -- This is the transaction reference that you passed to your charge call. If you didn't define a reference, you can access the auto-generated one from payload["txRef"] or action["txRef"] from the charge call\n
@@ -269,10 +295,23 @@ def verify(self, txRef, endpoint=None):
269295
"SECKEY": self._getSecretKey()
270296
}
271297
response = requests.post(endpoint, headers=headers, data=json.dumps(payload))
298+
299+
#feature logging
300+
if response.ok:
301+
tracking_endpoint = self._trackingMap
302+
responseTime = response.elapsed.total_seconds()
303+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": feature_name, "message": responseTime}
304+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
305+
else:
306+
tracking_endpoint = self._trackingMap
307+
responseTime = response.elapsed.total_seconds()
308+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": feature_name + "-error", "message": responseTime}
309+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
310+
272311
return self._handleVerifyResponse(response, txRef)
273312

274313
#Refund call
275-
def refund(self, flwRef):
314+
def refund(self, feature_name, flwRef):
276315
""" This is used to refund a transaction from any of Rave's component objects.\n
277316
Parameters include:\n
278317
flwRef (string) -- This is the flutterwave reference returned from a successful call from any component. You can access this from action["flwRef"] returned from the charge call
@@ -288,6 +327,18 @@ def refund(self, flwRef):
288327

289328
response = requests.post(endpoint, headers = headers, data=json.dumps(payload))
290329

330+
#feature logging
331+
if response.ok:
332+
tracking_endpoint = self._trackingMap
333+
responseTime = response.elapsed.total_seconds()
334+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": feature_name, "message": responseTime}
335+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
336+
else:
337+
tracking_endpoint = self._trackingMap
338+
responseTime = response.elapsed.total_seconds()
339+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": feature_name + "-error", "message": responseTime}
340+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
341+
291342
try:
292343
responseJson = response.json()
293344
except ValueError:

rave_python/rave_rwmobile.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@ def charge(self, accountDetails, hasFailed=False):
1717
hasFailed (boolean) -- This is a flag to determine if the attempt had previously failed due to a timeout\n
1818
"""
1919

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-
2520
#feature logic
21+
feature_name = "Initiate-Zambia-mobile-money-charge"
2622
endpoint = self._baseUrl + self._endpointMap["account"]["charge"]
2723
# It is faster to add boilerplate than to check if each one is present
2824
accountDetails.update({"payment_type": "mobilemoneygh", "country":"NG", "is_mobile_money_gh":"1", "currency":"RWF", "network": "RWF"})
@@ -34,5 +30,5 @@ def charge(self, accountDetails, hasFailed=False):
3430
accountDetails.update({"orderRef": generateTransactionReference()})
3531
# Checking for required account components
3632
requiredParameters = ["amount", "email", "phonenumber", "network", "IP", "redirect_url"]
37-
return super(RWMobile, self).charge(accountDetails, requiredParameters, endpoint)
33+
return super(RWMobile, self).charge(feature_name, accountDetails, requiredParameters, endpoint)
3834

rave_python/rave_ugmobile.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class UGMobile(Payment):
77
def __init__(self, publicKey, secretKey, production, usingEnv):
88
super(UGMobile, self).__init__(publicKey, secretKey, production, usingEnv)
99

10-
1110
# Charge mobile money function
1211
def charge(self, accountDetails, hasFailed=False):
1312

@@ -16,13 +15,9 @@ def charge(self, accountDetails, hasFailed=False):
1615
accountDetails (dict) -- These are the parameters passed to the function for processing\n
1716
hasFailed (boolean) -- This is a flag to determine if the attempt had previously failed due to a timeout\n
1817
"""
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-Uganda-mobile-money-charge"}
23-
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
2418

2519
## feature logic
20+
feature_name = "Initiate-Uganda-mobile-money-charge"
2621
endpoint = self._baseUrl + self._endpointMap["account"]["charge"]
2722
# It is faster to add boilerplate than to check if each one is present
2823
accountDetails.update({"payment_type": "mobilemoneyuganda", "country":"NG", "is_mobile_money_ug":"1", "currency":"UGX", "network": "UGX"})
@@ -34,5 +29,5 @@ def charge(self, accountDetails, hasFailed=False):
3429
accountDetails.update({"orderRef": generateTransactionReference()})
3530
# Checking for required account components
3631
requiredParameters = ["amount", "email", "phonenumber", "network", "IP"]
37-
return super(UGMobile, self).charge(accountDetails, requiredParameters, endpoint)
32+
return super(UGMobile, self).charge(feature_name, accountDetails, requiredParameters, endpoint)
3833

rave_python/rave_virtualaccount.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ 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))
6762

6863
# feature logic
6964
accountDetails = copy.copy(accountDetails)
@@ -72,4 +67,17 @@ def create(self, accountDetails):
7267
checkIfParametersAreComplete(requiredParameters, accountDetails)
7368
endpoint = self._baseUrl + self._endpointMap["virtual_account"]["create"]
7469
response = requests.post(endpoint, headers=self.headers, data=json.dumps(accountDetails))
70+
71+
#feature logging
72+
if response.ok == False:
73+
tracking_endpoint = self._trackingMap
74+
responseTime = response.elapsed.total_seconds()
75+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": "Create-virtual-account-error","message": responseTime}
76+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
77+
else:
78+
tracking_endpoint = self._trackingMap
79+
responseTime = response.elapsed.total_seconds()
80+
tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.5", "title": "Create-virtual-account","message": responseTime}
81+
tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
82+
7583
return self._handleCreateResponse(response, accountDetails)

0 commit comments

Comments
 (0)