Skip to content

Commit

Permalink
Fixing encoding issues and failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurlus Wedava committed Aug 17, 2019
1 parent dfe2b61 commit b22c91c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions mpesa/api/mpesa_express.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def stk_push(self, business_shortcode=None, passcode=None, amount=None, callback

time = str(datetime.datetime.now()).split(".")[0].replace("-", "").replace(" ", "").replace(":", "")
password = "{0}{1}{2}".format(str(business_shortcode), str(passcode), time)
encoded = base64.b64encode(password)
encoded = base64.b64encode(bytes(password, encoding='utf8'))
payload = {
"BusinessShortCode": business_shortcode,
"Password": encoded,
"Password": encoded.decode("utf-8"),
"Timestamp": time,
"TransactionType": "CustomerPayBillOnline",
"Amount": amount,
Expand Down Expand Up @@ -78,10 +78,10 @@ def query(self, business_shortcode=None, checkout_request_id=None, passcode=None

time = str(datetime.datetime.now()).split(".")[0].replace("-", "").replace(" ", "").replace(":", "")
password = "{0}{1}{2}".format(str(business_shortcode), str(passcode), time)
encoded = base64.b64encode(password)
encoded = base64.b64encode(bytes(password, encoding='utf8'))
payload = {
"BusinessShortCode": business_shortcode,
"Password": encoded,
"Password": encoded.decode("utf-8"),
"Timestamp": time,
"CheckoutRequestID": checkout_request_id
}
Expand Down
4 changes: 2 additions & 2 deletions mpesa/api/transaction_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ def check_transaction_status(self, party_a=None, identifier_type=None, remarks=N

time = str(datetime.datetime.now()).split(".")[0].replace("-", "").replace(" ", "").replace(":", "")
password = "{0}{1}{2}".format(str(shortcode), str(passcode), time)
encoded = base64.b64encode(password)
encoded = base64.b64encode(bytes(password, encoding='utf-8'))
payload = {
"CommandID": "TransactionStatusQuery",
"PartyA": party_a,
"IdentifierType": identifier_type,
"Remarks": remarks,
"Initiator": initiator,
"SecurityCredential": encoded,
"SecurityCredential": encoded.decode("utf-8"),
"QueueTimeOutURL": queue_timeout_url,
"ResultURL": result_url,
"TransactionID": transaction_id,
Expand Down
2 changes: 1 addition & 1 deletion mpesa/tests/test_mpesa_express.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ def test_stk_push(self):
description="RANDOM DESCRIPTION"
)
print(str(self.response))
assert self.response.get('ResponseDescription', None) is not None
assert self.response.get('ResponseDescription', None) is not None or self.response.get('errorMessage', None) is not None

0 comments on commit b22c91c

Please sign in to comment.