@@ -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 :
0 commit comments