-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathmpesa_credentials.py
executable file
·31 lines (22 loc) · 1.06 KB
/
mpesa_credentials.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import requests
import json
from requests.auth import HTTPBasicAuth
from datetime import datetime
import base64
class MpesaC2bCredential:
consumer_key = 'cHnkwYIgBbrxlgBoneczmIJFXVm0oHky'
consumer_secret = '2nHEyWSD4VjpNh2g'
api_URL = 'https://sandbox.safaricom.co.ke/oauth/v1/generate?grant_type=client_credentials'
class MpesaAccessToken:
r = requests.get(MpesaC2bCredential.api_URL,
auth=HTTPBasicAuth(MpesaC2bCredential.consumer_key, MpesaC2bCredential.consumer_secret))
mpesa_access_token = json.loads(r.text)
validated_mpesa_access_token = mpesa_access_token['access_token']
class LipanaMpesaPpassword:
lipa_time = datetime.now().strftime('%Y%m%d%H%M%S')
Business_short_code = "174379"
Test_c2b_shortcode = "600344"
passkey = 'bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919'
data_to_encode = Business_short_code + passkey + lipa_time
online_password = base64.b64encode(data_to_encode.encode())
decode_password = online_password.decode('utf-8')