Please let me work for you!

I will surely give you a great offer now!

Dear Sir/Madam,

My name is Brian Mbiki and I created this platform with products to help you:

1. Start a Payment processing gateway.

2. Integrate Mpesa with any website or Mobile App.

3. Add any form of Payment gateway to your website or Mobile App.

I am willing to cut down all my costs now.

Just write to me via WhatsApp +254706745202 and I will surely surprise you with  a great offer.

 

x

× This category encapsulates all discussions, tutorials and answers about Mpesa Express APIs integration | Mpesa Express APIs integration | STK push | STK push integration in PHP

Lipa na Mpesa Online Sandbox Test

  • Alex M
  • Alex M's Avatar Topic Author
  • Visitor
  • Visitor
4 months 2 weeks ago #338 by Alex M
Replied by Alex M on topic Lipa na Mpesa Online Sandbox Test
Below is the code. Am getting the values from an application.yaml file

private void initMpesaConfifg() throws UnsupportedEncodingException {
app_key = applicationProperties.getMpesaConfig().getApp_key();
app_secret = applicationProperties.getMpesaConfig().getApp_secret();
appKeySecret = app_key + ":" + app_secret;
bytes = appKeySecret.getBytes("ISO-8859-1");
auth = Base64.encode(bytes);
}

Below is the code to get the acces token
public GenerateToken getSandBoxToken() throws IOException {

initMpesaConfifg();

OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
.url(" sandbox.safaricom.co.ke/oauth/v1/generat...e=client_credentials ")
.get()
.addHeader("authorization", "Basic " + auth)
.addHeader("cache-control", "no-cache")
.build();

log.debug("getSandBoxToken() request {} ",new Gson().toJson(request));

Response response = client.newCall(request).execute();
String res = response.body().string();

GenerateToken generateToken = new Gson().fromJson(res, GenerateToken.class);

log.debug("generateToken response {}",generateToken.toString());

return generateToken;
}

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago #339 by Sir Brian M. W
Replied by Sir Brian M. W on topic Lipa na Mpesa Online Sandbox Test
I edited my suggestion for your problem.

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago #340 by Sir Brian M. W
Replied by Sir Brian M. W on topic Lipa na Mpesa Online Sandbox Test
This problem narrows down to the use of passkey.

If you use the correct short code for the sandbox, an Mpesa Express enabled Daraja APP and correct sandbox passkey, the STK push will work.

Please Log in or Create an account to join the conversation.

  • Alex M
  • Alex M's Avatar Topic Author
  • Visitor
  • Visitor
4 months 2 weeks ago #341 by Alex M
Replied by Alex M on topic Lipa na Mpesa Online Sandbox Test
This is what am using

Lipa Na Mpesa Online Shortcode: 174379
Lipa Na Mpesa Online Passkey:
bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago #342 by Sir Brian M. W
Replied by Sir Brian M. W on topic Lipa na Mpesa Online Sandbox Test
Below is simply the variables objects you need to set:

OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"BusinessShortCode\": \" \",
\"Password\": \" \", // this is the base64 encoded string of your passkey
\"Timestamp\": \" \",
\"TransactionType\": \"CustomerPayBillOnline\",
\"Amount\": \" \",
\"PartyA\": \" \",
\"PartyB\": \" \",
\"PhoneNumber\": \" \",
\"CallBackURL\": \"https://ip_address:port/callback\",
\"AccountReference\": \" \",
\"TransactionDesc\": \" \"}");
Request request = new Request.Builder()
.url(" sandbox.safaricom.co.ke/mpesa/stkpush/v1/processrequest ")
.post(body)
.addHeader("authorization", "Bearer ACCESS_TOKEN")
.addHeader("content-type", "application/json")
.build();

Response response = client.newCall(request).execute();

Please Log in or Create an account to join the conversation.

  • Alex M
  • Alex M's Avatar Topic Author
  • Visitor
  • Visitor
4 months 2 weeks ago #343 by Alex M
Replied by Alex M on topic Lipa na Mpesa Online Sandbox Test
Does my app need some sort of "approval" from Safaricom's end. On the portal it indicates the app is APPROVED.

Please Log in or Create an account to join the conversation.

Time to create page: 0.274 seconds
Powered by Kunena Forum