Skip to content

Commit

Permalink
version 1.0.1
Browse files Browse the repository at this point in the history
Signed-off-by: TralahM <musyoki.brian@tralahtek.com>
  • Loading branch information
TralahM committed Mar 12, 2021
1 parent 65a2e09 commit 3192af1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 25 deletions.
50 changes: 40 additions & 10 deletions mpesa/drc/__init__.py
Expand Up @@ -17,11 +17,24 @@
generate_c2b,
generate_b2c,
)
from mpesa.drc.parsers import (
parse_c2b_response,
parse_login_response,
parse_b2c_response,
)

# from mpesa.drc.parsers import (
# # parse_c2b_response,
# # parse_login_response,
# # parse_b2c_response,
# )
from mpesa.drc.request_parsers import prepare_content, data_items_to_map
from mpesa.drc.callback_parsers import prepare_callback

__all__ = [
"data_items_to_map",
"prepare_content",
"prepare_callback",
"generate_login",
"generate_c2b",
"generate_b2c",
"API",
]


class API:
Expand Down Expand Up @@ -102,7 +115,7 @@ def _post_request(self, url: str, content: str, content_handler: typing.Callable
result_content = response.content
return content_handler(result_content)

def authentication_token(self):
def authenticate(self):
"""Return Authentication Token."""
content = generate_login(
{
Expand All @@ -113,9 +126,16 @@ def authentication_token(self):
result = self._post_request(
self._login_url,
content,
parse_login_response,
prepare_content,
)
return result["token"]
return result
...

def authentication_token(self):
"""Return Authentication Token."""
result = self.authenticate()
print(result)
return result["SessionID"]
...

def b2c(
Expand Down Expand Up @@ -175,7 +195,7 @@ def b2c(
"Amount": Amount,
}
content = generate_b2c(params)
handler = parse_b2c_response
handler = prepare_content
return self._post_request(url, content, handler)
...

Expand Down Expand Up @@ -240,7 +260,7 @@ def c2b(
"ServiceProviderCode": ServiceProviderCode,
}
content = generate_c2b(params)
handler = parse_c2b_response
handler = prepare_content
return self._post_request(url, content, handler)

def w2b(
Expand Down Expand Up @@ -274,3 +294,13 @@ def w2b(
print(params)
pass
...

@classmethod
def parseB2C(cls, xml_response: bytes):
"""Parse B2C Callback XML Payload and return json."""
return prepare_callback(xml_response)

@classmethod
def parseC2B(cls, xml_response: bytes):
"""Parse C2B Callback XML Payload and return json."""
return prepare_callback(xml_response)
31 changes: 16 additions & 15 deletions setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = tekmpesa
version = 1.0.0
version = 1.0.1
description = All Mpesa APIs for All 8 Countries
long_description = file: README.md
long_description_content_type=text/markdown
Expand Down Expand Up @@ -31,35 +31,36 @@ project_urls =
include_package_data = true
packages = find:
install_requires =

requests

urllib3

pycryptodome

certifi

chardet

idna

six

pytest

future

jinja2

lxml

PyYaml

xmltodict

[options.extras_require]
docs=
sphinx
sphinx-automodapi
[options.entry_points]
console_scripts =

0 comments on commit 3192af1

Please sign in to comment.