safaricom / LNMOnlineAndroidSample

Lipa Na MPESA Online (STK Push) Android Sample Application. This app demonstrates an e-commerce purchase and checkout process via Mpesa and Daraja :smile:
https://developer.safaricom.co.ke/
Apache License 2.0
129 stars 128 forks source link

Mpesa STK push Error #36

Closed ngangavic closed 5 years ago

ngangavic commented 5 years ago

I run my code several times succesfully, then this error started displaying. What could be the problem? { "requestId":"27746-3661277-1", "errorCode": "400.002.02", "errorMessage": "Bad Request - Invalid Timestamp" } { "requestId":"27746-3661277-1", "errorCode": "400.002.02", "errorMessage": "Bad Request - Invalid Timestamp" }

ngangavic commented 5 years ago

I figured it out by creating another application in the sandbox.

jumakiwaka commented 4 years ago

timestamp should be in the form of yyyymmddhhiiss

andridge commented 3 years ago

timestamp should be in the form of format('YmdHMS');

Larrykatuva commented 2 years ago

@staticmethod def generate_password() -> tuple: unformatted_time = datetime.now() formatted_time = unformatted_time.strftime("%Y%m%d%H%M%S") data_to_encode = MPESA_BUSINESS_SHORT_CODE + MPESA_PASSKEY + formatted_time encoded_string = base64.b64encode(data_to_encode.encode()) decoded_password = encoded_string.decode('utf-8') return decoded_password, formatted_time

//==> This method will sort you out

leehaney254 commented 5 months ago

I had the same error. For quite a while I tried to solve it, then I found 2 bugs:

  1. I had not declared addHeader("Content-Type", "application/json").
  2. There were some field that are required in the request body that I had missed.