Skip to content

Commit bed799a

Browse files
authored
removed the calculation error in mpesa_access_token() (#5)
the mpesa_access_token() had a bug in my system where the OAuth token would not refresh unless the request was sent 51 minutes after it expired. Now if no one used the system for an hour ,the token minutes would count to 59 then go back to zero since the minutes code would calculate the minutes above the hour making the old token "valid" since the minutes would be less than 50. I removed the modulus calculation so the minutes always go above 60.
1 parent 5515059 commit bed799a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

django_daraja/mpesa/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def mpesa_access_token():
156156
access_token = generate_access_token()
157157
else:
158158
delta = timezone.now() - access_token.created_at
159-
minutes = (delta.total_seconds()//60)%60
159+
minutes = (delta.total_seconds()//60)
160160
print('minutes: ', minutes)
161161
if minutes > 50:
162162
# Access token expired
@@ -202,4 +202,4 @@ def encrypt_rsa(certificate_path, input):
202202
encrypted = cert.public_key().encrypt(message, PKCS1v15())
203203
output = base64.b64encode(encrypted).decode('ascii')
204204

205-
return output
205+
return output

0 commit comments

Comments
 (0)