fbiego / MpesaSTK

An Arduino Library implementing MPESA Daraja on microcontrollers
MIT License
19 stars 6 forks source link

Test STK Push Failed HttpCode:"500" #1

Open abdazz25 opened 2 years ago

abdazz25 commented 2 years ago

Hi Felix, Hope you are keeping well. I am trying to test your Arduino Library on ESP32 module. It connect to the Wifi the access token seems to work cause if I change the consumer_key , pass_key or secret_key. I get the invalid access token error. How ever the STK Push fails with the error below.

Waiting for WiFi to connect... connected Sending STK request {"Result":"failed","HttpCode":"500"}

Could you kindly assist.

Thanks and regards, Abdalla

fbiego commented 2 years ago

Check you callback url, it should be secured (https)

abdazz25 commented 2 years ago

Hi Felix, I am testing it using your call back URL from the examples and it is https.

I have tried to remove the s from the http url still the error code is the same.

Though I am using credentials from my live Buy_Goods in Production. Will that cause this issue?

abdazz25 commented 2 years ago

I have uploaded the stkHandler to my site. It is https. The daraja.txt was created with below data even though the transaction failed with error 500.

{"success":true,"paid":true,"message":"Payment successful","amount":null,"txID":null,"balance":null,"date":null,"number":null,"merchantID":null,"checkoutID":null,"resultCode":null,"resultDesc":null}

fbiego commented 2 years ago

Hello, I have not tested the code in a production environment. Can you check if it works in the sandbox? Use the default settings from the example first i.e

mpesa.begin(TEST_CODE, PAYBILL, "https://mycallbackurl.com/checkout.php");
abdazz25 commented 2 years ago

Hi Felix, I modified the .cpp file to show the error message. This guided me to fix the issue. I was using the Till Number insted of the Store Number.

Waiting for WiFi to connect... connected {"requestId":"12566-20270757-1","errorCode":"500.001.1001","errorMessage":"Merchantdoesnotexist","Result":"success","HttpCode":"500"}

After changing the Buy_Code to Store Number the stk push came though then followed by an SMS from Safaricom as below.

Failed. M-PESA cannot complete this operation. The parameter value is incorrect. No till is found. for CustomerPayMerchant. For more information call or SMS customer services on 100.

Kindly see if you are passing this CustomerPayMerchant to the API

{"MerchantRequestID":"19978-16256822-1","CheckoutRequestID":"ws_CO_30082022171926235716594139","ResponseCode":"0","ResponseDescription":"Success.Requestacceptedforprocessing","CustomerMessage":"Success.Requestacceptedforprocessing","Result":"success","HttpCode":"200"}

fbiego commented 2 years ago

Okay, noted. I will implement that

abdazz25 commented 2 years ago

Thank you Felix.

On Tue, Aug 30, 2022, 18:27 Felix Biego @.***> wrote:

Okay, noted. I will implement that

— Reply to this email directly, view it on GitHub https://github.com/fbiego/MpesaSTK/issues/1#issuecomment-1231823945, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5JGZ5WSKGLMQJRT5HBLUDV3YR43ANCNFSM6AAAAAAQAJNKFI . You are receiving this because you authored the thread.Message ID: @.***>

abdazz25 commented 2 years ago

Hi Felix, Did you manage to fix this?

Thanks and regards, Abdalla

On Tue, Aug 30, 2022 at 6:36 PM Abdalla Nizar @.***> wrote:

Thank you Felix.

On Tue, Aug 30, 2022, 18:27 Felix Biego @.***> wrote:

Okay, noted. I will implement that

— Reply to this email directly, view it on GitHub https://github.com/fbiego/MpesaSTK/issues/1#issuecomment-1231823945, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5JGZ5WSKGLMQJRT5HBLUDV3YR43ANCNFSM6AAAAAAQAJNKFI . You are receiving this because you authored the thread.Message ID: @.***>

fbiego commented 2 years ago

Hello, I've been quite busy and haven't had time to work on this. Can you submit a PR with the changes?

jumla-online commented 1 year ago

hello abdazz25, which callback url are you using?

abdazz25 commented 1 year ago

@fbiego I am not very familiar with GitHub Pull Request.

However, from my previous tests above. There are two scenarios on using the MpesaSTK

  1. One is using a Till Number
  2. Using a Paybill Number The tests I have done above is using a Till Number. When using a Till Number, you have to use both your Till Number and something called a Store Number. The Store Number does not apply when using a Paybill Number for STK Push.

So, this error which generated is because in your code the concept of Store Number is not taken care of. Below error was from the API. After changing the Buy_Code to Store Number the stk push came though then followed by an SMS from Safaricom as below.

"Failed. M-PESA cannot complete this operation. The parameter value is incorrect. No till is found. for CustomerPayMerchant. For more information call or SMS customer services on 100."

What I am requesting is, if you can handle this Store Number issue. So that it can work with Till Numbers.

@jumla-online The call back url, I uploaded the files from this to my cpanel. // the callback & check URL is based on the PHP files @ // https://github.com/fbiego/stkHandler

abdazz25 commented 1 year ago

Hi guys, I just wanted to confirm here that, I have tested the library on PRODUCTION and with a Paybil number. It works perfectily with the callback and check urls. However, it does not work with Till Number.

{"success":true,"paid":true,"message":"Payment successful","amount":1,"txID":"RHP2ZDY10O","balance":null,"date":20230825115858,"number":254716594xxx,"merchantID":"7609-145740404-1","checkoutID":"ws_CO_25082023115851612716594139","resultCode":0,"resultDesc":"The service request is processed successfully."}

fbiego commented 1 year ago

Hi guys, I just wanted to confirm here that, I have tested the library on PRODUCTION and with a Paybil number. It works perfectily with the callback and check urls. However, it does not work with Till Number.

{"success":true,"paid":true,"message":"Payment successful","amount":1,"txID":"RHP2ZDY10O","balance":null,"date":20230825115858,"number":254716594xxx,"merchantID":"7609-145740404-1","checkoutID":"ws_CO_25082023115851612716594139","resultCode":0,"resultDesc":"The service request is processed successfully."}

Thanks for the information. Could you share if Till numbers are already supported in the API?

abdazz25 commented 1 year ago

@fbiego yes till numbers are supported. I have it working on a WordPress website checkout. However as mentioned earlier on one of my earlier comments, when using a Till Number, there is something called Store Number, this has to be sent as part of the parameters to the API for authentication. This is not taken care of on your Library. Every Till Number has a Store Number assigned to it. Kindly make some time to check on it.