Closed HorraceMuendo closed 1 year ago
hello how do I fix this
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
Golang
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
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
@HorraceMuendo did you fix it ?
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" }
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
I have done that @George-Onyango do you have links to anyone who has integrated it with golang before
I used github.com/jwambugu/mpesa-golang-sdk and fixed the errors instead of coding it from scratch .....his sdk was really helpful
{ "requestId":"24467-118861182-1", "errorCode": "400.002.02", "errorMessage": "Bad Request - Invalid BusinessShortCode"