how to generate hash from Fire base server to integrate PAYU gateway?
Asked Answered
H

0

6

I am trying to accept payments via PAYU in my android app, but I dont have a server and so I used firebase to store the data. From the video https://youtu.be/gnQ0IF3XniM I managed to integrate PAYU payment gateway from the server that is mentioned in the video. my code for generating the hash from server is as bellow :

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

Can anyone tell me how to generate hash from firebase server and integrate PAYU payment gateway.

Herbert answered 11/2, 2018 at 15:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.