Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .idea/aws.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 18 additions & 61 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions src/main/java/Mpesa.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,37 @@ public String registerURL(String shortCode, String responseType, String confirm
return response.body().string();
}

public String dynamicQR(String trxCode, String creditPartyIdentifier, String merchantName, double amount, String refNo) throws IOException{
JSONArray jsonArray=new JSONArray();
JSONObject jsonObject=new JSONObject();
jsonObject.put("MerchantName", merchantName);
jsonObject.put("RefNo", refNo);
jsonObject.put("Amount", amount);
jsonObject.put("TrxCode", trxCode);
jsonObject.put("CPI", creditPartyIdentifier);

jsonArray.put(jsonObject);

String requestJson=jsonArray.toString().replaceAll("[\\[\\]]","");
System.out.println(requestJson);

OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, requestJson);

Request request = new Request.Builder()
.url("https://sandbox.safaricom.co.ke/mpesa/stkpushquery/v1/query")
.post(body)
.addHeader("content-type", "application/json")
.addHeader("authorization", "Bearer "+authenticate())
.addHeader("cache-control", "no-cache")
.build();

Response response = client.newCall(request).execute();
System.out.println(response.body().string());
return response.body().string();
}


}