如何在payumoney android intigration中创建商家端哈希

时间:2017-09-11 16:19:18

标签: php android payumoney

我在我的应用中使用payumoney支付门户。我已生成哈希 从GetHashesFromServerTask函数和这部分运行正常。 我在fetchMerchantHashes函数中遇到了这个问题。

     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();
}

我无法理解现在要做什么,以便我可以获得交易响应。

0 个答案:

没有答案