How to create merchant side hash in payumoney android intigration

188 views Asked by At

I am using payumoney payment portal in my app. I have generated hash from GetHashesFromServerTask function and this part is running fine. I am facing the issue in fetchMerchantHashes function.

     private void fetchMerchantHashes(final Intent intent) {
    // now make the api call.
    final String postParams = "merchant_key=" + merchantKey + "&user_credentials=" + userCredentials;
    final Intent baseActivityIntent = intent;
    new AsyncTask<Void, Void, HashMap<String, String>>() {

        @Override
        protected HashMap<String, String> doInBackground(Void... params) {
            try {
                //TODO Replace below url with your server side file url.
                URL url = new URL("https://payu.herokuapp.com/get_merchant_hashes");

                byte[] postParamsByte = postParams.getBytes("UTF-8");

                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("GET");
                conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                conn.setRequestProperty("Content-Length", String.valueOf(postParamsByte.length));
                conn.setDoOutput(true);
                conn.getOutputStream().write(postParamsByte);

                InputStream responseInputStream = conn.getInputStream();
                StringBuffer responseStringBuffer = new StringBuffer();
                byte[] byteContainer = new byte[1024];
                for (int i; (i = responseInputStream.read(byteContainer)) != -1; ) {
                    responseStringBuffer.append(new String(byteContainer, 0, i));
                }

                JSONObject response = new JSONObject(responseStringBuffer.toString());

                HashMap<String, String> cardTokens = new HashMap<String, String>();
                JSONArray oneClickCardsArray = response.getJSONArray("data");
                int arrayLength;
                if ((arrayLength = oneClickCardsArray.length()) >= 1) {
                    for (int i = 0; i < arrayLength; i++) {
                        cardTokens.put(oneClickCardsArray.getJSONArray(i).getString(0), oneClickCardsArray.getJSONArray(i).getString(1));
                    }
                    return cardTokens;
                }
                // pass these to next activity

            } catch (JSONException e) {
                e.printStackTrace();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (ProtocolException e) {
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(HashMap<String, String> oneClickTokens) {
            super.onPostExecute(oneClickTokens);

            baseActivityIntent.putExtra(PayuConstants.ONE_CLICK_CARD_TOKENS, oneClickTokens);
            startActivityForResult(baseActivityIntent, PayuConstants.PAYU_REQUEST_CODE);
        }
    }.execute();
}

I am not able to understand what to do now so that i can get transaction response.

0

There are 0 answers