Last active
June 8, 2020 01:14
-
-
Save AustineGwa/9f3ab9216ec9cd27351294f35ac5e533 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //calling the endpoint via java (okhttp Implementation) | |
| OkHttpClient client = new OkHttpClient(); | |
| MediaType mediaType = MediaType.parse("application/json"); | |
| RequestBody body = RequestBody.create(mediaType, "{\"InitiatorName\":\" \", | |
| \"SecurityCredential\":\" \", | |
| \"CommandID\":\" \", | |
| \"Amount\":\" \", | |
| \"PartyA\":\" \", | |
| \"PartyB\":\" \", | |
| \"Remarks\":\" \", | |
| \"QueueTimeOutURL\":\"http://your_timeout_url\", | |
| \"ResultURL\":\"http://your_result_url\", | |
| \"Occasion\":\" \"}"); | |
| Request request = new Request.Builder() | |
| .url("https://sandbox.safaricom.co.ke/mpesa/b2c/v1/paymentrequest") | |
| .post(body) | |
| .addHeader("authorization", "Bearer YOUR_OAUTH_TOKEN") | |
| .addHeader("content-type", "application/json") | |
| .build(); | |
| Response response = client.newCall(request).execute(); | |
| // Sample M-Pesa Core response received on the callback url. | |
| { | |
| "Result":{ | |
| "ResultType":0, | |
| "ResultCode":0, | |
| "ResultDesc":"The service request has been accepted successfully.", | |
| "OriginatorConversationID":"19455-424535-1", | |
| "ConversationID":"AG_20170717_00006be9c8b5cc46abb6", | |
| "TransactionID":"LGH3197RIB", | |
| "ResultParameters":{ | |
| "ResultParameter":[ | |
| { | |
| "Key":"TransactionReceipt", | |
| "Value":"LGH3197RIB" | |
| }, | |
| { | |
| "Key":"TransactionAmount", | |
| "Value":8000 | |
| }, | |
| { | |
| "Key":"B2CWorkingAccountAvailableFunds", | |
| "Value":150000 | |
| }, | |
| { | |
| "Key":"B2CUtilityAccountAvailableFunds", | |
| "Value":133568 | |
| }, | |
| { | |
| "Key":"TransactionCompletedDateTime", | |
| "Value":"17.07.2017 10:54:57" | |
| }, | |
| { | |
| "Key":"ReceiverPartyPublicName", | |
| "Value":"254708374149 - John Doe" | |
| }, | |
| { | |
| "Key":"B2CChargesPaidAccountAvailableFunds", | |
| "Value":0 | |
| }, | |
| { | |
| "Key":"B2CRecipientIsRegisteredCustomer", | |
| "Value":"Y" | |
| } | |
| ] | |
| }, | |
| "ReferenceData":{ | |
| "ReferenceItem":{ | |
| "Key":"QueueTimeoutURL", | |
| "Value":"https://internalsandbox.safaricom.co.ke/mpesa/b2cresults/v1/submit" | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment