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
127 stars 129 forks source link

Invalid BusinessShortCode #47

Closed HorraceMuendo closed 1 year ago

HorraceMuendo commented 1 year ago

{ "requestId":"24467-118861182-1", "errorCode": "400.002.02", "errorMessage": "Bad Request - Invalid BusinessShortCode"

            }
HorraceMuendo commented 1 year ago

hello how do I fix this

SnowJunior commented 1 year ago

Which language are you using ? If it is ruby I made an article that you can follow for it to run. I'll paste the link below https://snowsnippets.hashnode.dev/ruby-and-mpesa-api-how-to-integrate-daraja-api-using-ruby

HorraceMuendo commented 1 year ago

Golang

kisese commented 1 year ago

This means that SHortcode you are trying to pay to is not valid, a valid payload is like the following below. It also need to be the same on BusinessShortCode and PartyB

{    
   "BusinessShortCode":"174379",    
   "Password": "MTc0Mzc5YmZiMjc5ZjlhYTliZGJjZjE1OGU5N2RkNzFhNDY3Y2QyZTBjODkzMDU5YjEwZjc4ZTZiNzJhZGExZWQyYzkxOTIwMTYwMjE2MTY1NjI3",    
 "Timestamp":"20160216165627",    
 "TransactionType": "CustomerPayBillOnline",    
   "Amount":"1",    
  "PartyA":"254708374149",    
   "PartyB":"174379",    
 "PhoneNumber":"254708374149",    
 "CallBackURL":"https://mydomain.com/pat",    
 "AccountReference":"Test",    
 "TransactionDesc":"Test"
}

You can also check this example for golang https://github.com/kisese/golang-mpesa

SnowJunior commented 1 year ago

As @kisese has posted. Something to note ensure that your program is generating the same passKey as the one provided by safaricom. Here in the password section: "Password": "MTc0Mzc5YmZiMjc5ZjlhYTliZGJjZjE1OGU5N2RkNzFhNDY3Y2QyZTBjODkzMDU5YjEwZjc4ZTZiNzJhZGExZWQyYzkxOTIwMTYwMjE2MTY1NjI3",

That is normally the problem. Create an output to see if the passKey generated matches the one in daraja passKey

SnowJunior commented 1 year ago

@HorraceMuendo did you fix it ?

HorraceMuendo commented 1 year ago

Not really , here's the output from my terminal ,the password's format is similar to daraja's @kisese and @George-Onyango any comments on this?

Access token: V7IDKsgqMKT3pxEgZLnK56LMdoDh password:MTc0Mzc5YmZiMjc5ZjlhYTliZGJjZjE1OGU5N2RkNzFhNDY3Y2QyZTBjODkzMDU5YjEwZjc4ZTZiNzJhZGExZWQyYzkxOTIwMjMwMzI0MjEyODQw { "BusinessShortCode": "174379", "Password":"MTc0Mzc5YmZiMjc5ZjlhYTliZGJjZjE1OGU5N2RkNzFhNDY3Y2QyZTBjODkzMDU5YjEwZjc4ZTZiNzJhZGExZWQyYzkxOTIwMjMwMzI0MjEyODQw", "Timestamp" :"20230324212840", "TransactionType":"CustomerPayBillOnline", "Amount":"1", "PartyA":"0729664004", "PartyB":"174379", "PhoneNumber":"0729664004", "CallBackURL":"https://mydomain.com/path", "AccountReference":"SMOCHADELI", "TransactionDesc":"test",

            }

{ "requestId":"17899-11091744-1", "errorCode": "400.002.02", "errorMessage": "Bad Request - Invalid BusinessShortCode" }

SnowJunior commented 1 year ago

And how are you generating the access token

If it's via http you'll use the url and header putting the generated token in the authorization section

HorraceMuendo commented 1 year ago

I have done that @George-Onyango do you have links to anyone who has integrated it with golang before

HorraceMuendo commented 1 year ago

I used github.com/jwambugu/mpesa-golang-sdk and fixed the errors instead of coding it from scratch .....his sdk was really helpful