1
+ """
2
+ Python Package to Easy the Integration with Vodacom Public API
3
+ """
4
+
1
5
import os
2
6
import json
7
+ import sys
3
8
import base64
4
9
import socket
5
10
import requests
@@ -136,18 +141,30 @@ def environment(self, enviro: str) -> Union[sandbox, production]:
136
141
137
142
@property
138
143
def api_key (self ) -> str :
139
- return self .auth_keys ["api_key" ]
144
+ '''
145
+ Return current api key
146
+ '''
147
+ return self .auth_keys .get ("api_key" )
140
148
141
149
@api_key .setter
142
150
def api_key (self , Api_key : str ) -> str :
151
+ '''
152
+ Use this propery to explicit set a api_key
153
+
154
+ >> import pypesa
155
+ >> wallet = pypesa()
156
+ >> wallet.api_key = " Your api key" #here
157
+
158
+ '''
143
159
if isinstance (Api_key , str ):
144
160
self .auth_keys ["api_key" ] = Api_key
145
161
return self .auth_keys ["api_key" ]
146
- raise TypeError (f"API key must be a of type String not { type (Api_key )} " )
162
+ raise TypeError (
163
+ f"API key must be a of type String not { type (Api_key )} " )
147
164
148
165
@property
149
166
def public_key (self ) -> str :
150
- return self .auth_keys [ "public_key" ]
167
+ return self .auth_keys . get ( "public_key" )
151
168
152
169
@public_key .setter
153
170
def public_key (self , pb_key : str ) -> str :
@@ -165,7 +182,8 @@ def origin_address(self, ip_address: str) -> str:
165
182
if isinstance (ip_address , str ):
166
183
self ._origin_ip = ip_address
167
184
return self ._origin_ip
168
- raise TypeError (f"Address must be of type string not { type (ip_address )} " )
185
+ raise TypeError (
186
+ f"Address must be of type string not { type (ip_address )} " )
169
187
170
188
@authenticated
171
189
def default_headers (self , auth_key : Optional [str ] = "" ) -> dict :
@@ -216,7 +234,8 @@ def verify_query(transaction_query: dict, required_fields: set) -> bool:
216
234
def customer_to_bussiness (self , transaction_query : dict ) -> dict :
217
235
""""""
218
236
219
- self .verify_query (transaction_query , self .urls .re_customer_to_bussiness )
237
+ self .verify_query (transaction_query ,
238
+ self .urls .re_customer_to_bussiness )
220
239
221
240
try :
222
241
return requests .post (
@@ -233,7 +252,8 @@ def customer_to_bussiness(self, transaction_query: dict) -> dict:
233
252
def bussiness_to_customer (self , transaction_query : dict ) -> dict :
234
253
""""""
235
254
236
- self .verify_query (transaction_query , self .urls .re_bussiness_to_customer )
255
+ self .verify_query (transaction_query ,
256
+ self .urls .re_bussiness_to_customer )
237
257
238
258
try :
239
259
@@ -251,7 +271,8 @@ def bussiness_to_customer(self, transaction_query: dict) -> dict:
251
271
def bussiness_to_bussiness (self , transaction_query : dict ) -> dict :
252
272
""""""
253
273
254
- self .verify_query (transaction_query , self .urls .re_bussiness_to_bussiness )
274
+ self .verify_query (transaction_query ,
275
+ self .urls .re_bussiness_to_bussiness )
255
276
256
277
try :
257
278
return requests .post (
@@ -328,4 +349,7 @@ def direct_debit_payment(self, transaction_query: dict) -> dict:
328
349
verify = True ,
329
350
)
330
351
except (requests .ConnectTimeout , requests .ConnectionError ):
331
- raise MpesaConnectionError
352
+ raise MpesaConnectionError
353
+
354
+
355
+ sys .modules [__name__ ] = Mpesa
0 commit comments