如何从Fire基本服务器生成哈希以集成PAYU网关?

时间:2018-02-11 15:24:49

标签: android firebase payment-gateway payu

我想在我的Android应用程序中通过PAYU接受付款,但我没有服务器,因此我使用firebase存储数据。来自视频 https://youtu.be/gnQ0IF3XniM我设法从视频中提到的服务器集成了PAYU支付网关。 我从服务器生成哈希的代码如下:

    @Override
    protected PayuHashes doInBackground(String... postParams) {
        PayuHashes payuHashes = new PayuHashes();
        try {

            //TODO Below url is just for testing purpose, merchant needs to replace this with their server side hash generation url
            URL url = new URL("https://payu.herokuapp.com/get_hash");

            // get the payuConfig first
            String postParam = postParams[0];

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

            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            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());

            Iterator<String> payuHashIterator = response.keys();
            while (payuHashIterator.hasNext()) {
                String key = payuHashIterator.next();
                switch (key) {

                    case "payment_hash":
                        payuHashes.setPaymentHash(response.getString(key));
                        break;
                    case "vas_for_mobile_sdk_hash":
                        payuHashes.setVasForMobileSdkHash(response.getString(key));
                        break;

                    case "payment_related_details_for_mobile_sdk_hash":
                        payuHashes.setPaymentRelatedDetailsForMobileSdkHash(response.getString(key));
                        break;

                    case "delete_user_card_hash":
                        payuHashes.setDeleteCardHash(response.getString(key));
                        break;

                    case "get_user_cards_hash":
                        payuHashes.setStoredCardsHash(response.getString(key));
                        break;

                    case "edit_user_card_hash":
                        payuHashes.setEditCardHash(response.getString(key));
                        break;

                    case "save_user_card_hash":
                        payuHashes.setSaveCardHash(response.getString(key));
                        break;
                    case "check_offer_status_hash":
                        payuHashes.setCheckOfferStatusHash(response.getString(key));
                        break;
                    default:
                        break;
                }
            }

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

    @Override
    protected void onPostExecute(PayuHashes payuHashes) {
        super.onPostExecute(payuHashes);

        progressDialog.dismiss();
        launchSdkUI(payuHashes);
    }
}

任何人都可以告诉我如何从firebase服务器生成哈希并集成PAYU支付网关。

0 个答案:

没有答案