In three steps Add Mobile Payments to your application using MTN Mobile Money, Airtel Money, Africell Mobile Money and UTL m-sente, Payments to your Android Application, or any other JAVA application

Note 1: Mobile money is the quickest way to transfer money in Uganda and other African countries.
Note 2: Android Operating system is the most used operating system in the world.

Step 1:
Go to google play store and download "Easy Pay Mobile Wallet" application

Step 2:
Use the App to create your account at easy Pay, and create an Mobile Money API that will allow you to transfer money across almost all networks in Africa.



Step 3:
Copy the code below and add it inside tour main activity class

       

        public static class CallAPI extends AsyncTask {

        private String post_url="https://www.easypay.co.ug/api/";
        private String client_id="your id from the app";
        private String secret="your secret from the app";
        private String transaction_action="mmdeposit";
        private String transaction_amount="";
        private String transaction_phone="";
        private String currency="UGX";
        private String reference="1";
        private String reason="Lodge payment";
        Context context;

        public CallAPI(String transaction_amount, String transaction_phone, Context context){
            this.transaction_amount=transaction_amount;
            this.transaction_phone=transaction_phone;
            this.context=context;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected String doInBackground(String... params) {
            try {
                final String POST_PARAMS = "{" +
                        "\"username\": \""+client_id+"\"," +
                        "\"password\": \""+secret+"\"," +
                        "\"action\": \""+transaction_action+"\"," +
                        "\"amount\": \"" + transaction_amount + "\"," +
                        "\"currency\": \""+currency+"\"," +
                        "\"phone\": \"" + transaction_phone + "\"," +
                        "\"reference\": \"" + reference + "\"," +
                        "\"reason\": \"" + reason + "\"}";
                System.out.println(POST_PARAMS);
                URL obj = new URL(post_url);
                HttpURLConnection postConnection = (HttpURLConnection) obj.openConnection();
                postConnection.setRequestMethod("POST");
                postConnection.setRequestProperty("Content-Type", "application/json");
                postConnection.setDoOutput(true);
                OutputStream os = postConnection.getOutputStream();
                os.write(POST_PARAMS.getBytes());
                os.flush();
                os.close();
                int responseCode = postConnection.getResponseCode();
                System.out.println("POST Response Code : " + responseCode);
                System.out.println("POST Response Message : " + postConnection.getResponseMessage());
                BufferedReader in = new BufferedReader(new InputStreamReader(postConnection.getInputStream()));
                String inputLine;
                StringBuffer response = new StringBuffer();
                while ((inputLine = in.readLine()) != null) {
                    response.append(inputLine);
                }
                in.close();
                JSONObject js = new JSONObject(String.valueOf(response));
                dialog.dismiss();
                if(js.get("success").toString().equals("0")) {
                    Log.e("FAILED: ", js.get("errormsg").toString());
                    //Toast.makeText(context, js.get("errormsg").toString(), Toast.LENGTH_SHORT).show();
                }else if(js.get("success").toString().equals("1")) {
                    Log.e("WORKED: ", response.toString());
                }
            }catch (Exception e){
                Log.e("WORKED: ",  "Error: "+e);
                dialog.dismiss();
            }
            return "";
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
        }
    }

       
 

Use the code below to request money from the mobile money user.
CallAPI callAPI=new CallAPI(transaction_amount, transaction_phone, MainActivity.this);
callAPI.execute();

For Those who want a full working Application Sample, Check out my other blog post Here
Note: For more information about the API refer to Easy Pay API Guide

Comments

  1. i cannot see the android part for in coming payments from my customers, the outgoing payments fine but how to handle in coming payments not shown.
    thanks

    ReplyDelete
    Replies
    1. You can also read my other blog here
      https://waglex.blogspot.com/2019/03/android-payment-using-mtn-mobile-money.html

      Delete
  2. i cannot see the android part for in coming payments from my customers, the outgoing payments fine but how to handle in coming payments not shown.
    thanks

    ReplyDelete
    Replies
    1. That was just a demonstration on how to use the API, but you can read more about how to use the API from https://www.easypay.co.ug/kb/knowledge-base/open-mobile-money-api-uganda-mtn-airtel-africell-utl-m-sente/

      Delete

Post a Comment

Popular posts from this blog

Android Payment Using MTN Mobile Money, Airtel Money, Africell Mobile Money and UTL m-sente, Free Code Project