2017-05-03 12 views
1

나는 안드로이드 애플리케이션에 PayUBiz를 통합하고 있습니다. here.에서 샘플 앱을 다운로드했습니다.PayUBiz - 안드로이드 : 점점 필수 param 해시가 누락되었습니다

테스트 환경에서 정상적으로 작동합니다. live merchantId와 해시 생성을위한 내 서버 URL과 같은 다른 것들을 넣는 동안 작동하지 않습니다. "필수 param 해시가 누락되었습니다"을 제공합니다.

시도한 내용은 다음과 같습니다.

스텝 -1 : 전화 makePayment 메서드입니다.

private void makePayment() { 
    int environment = PayuConstants.PRODUCTION_ENV; 
    double totalProductPrice = 1.0; 
    double conveniencePrice = 0.0; 
    double totalPayableAmount = totalProductPrice + (totalProductPrice * (conveniencePrice/100)); 
    //int environment = PayuConstants.STAGING_ENV; 

    sharedPref = new UserSharedPref(this); 

    userCredentials = merchantKey + ":" + sharedPref.getUserEmail(); 

    mPaymentParams = new PaymentParams(); 

    mPaymentParams.setKey(merchantKey); 
    mPaymentParams.setAmount(String.valueOf(totalPayableAmount)); 
    mPaymentParams.setProductInfo("Our Store"); 
    mPaymentParams.setFirstName(sharedPref.getUserName()); 
    mPaymentParams.setEmail(sharedPref.getUserEmail()); 
    mPaymentParams.setTxnId("" + System.currentTimeMillis()); 
    mPaymentParams.setSurl("https://payu.herokuapp.com/success"); 
    mPaymentParams.setFurl("https://payu.herokuapp.com/failure"); 
    mPaymentParams.setUdf1(""); 
    mPaymentParams.setUdf2(""); 
    mPaymentParams.setUdf3(""); 
    mPaymentParams.setUdf4(""); 
    mPaymentParams.setUdf5(""); 
    mPaymentParams.setUserCredentials(userCredentials); 
    //TODO Sets the payment environment in PayuConfig object 
    payuConfig = new PayuConfig(); 
    payuConfig.setEnvironment(environment); 
    //TODO It is recommended to generate hash from server only. Keep your key and salt in server side hash generation code. 
    generatePayUHashFromServer(mPaymentParams); 
} 

스텝 2 : generatePayUHashFromServer 호출 방법.

private void generatePayUHashFromServer(PaymentParams mPaymentParams) { 
    StringBuffer postParamsBuffer = new StringBuffer(); 
    postParamsBuffer.append(concatParams(PayuConstants.KEY, mPaymentParams.getKey())); 
    postParamsBuffer.append(concatParams(PayuConstants.AMOUNT, mPaymentParams.getAmount())); 
    postParamsBuffer.append(concatParams(PayuConstants.TXNID, mPaymentParams.getTxnId())); 
    postParamsBuffer.append(concatParams(PayuConstants.EMAIL, null == mPaymentParams.getEmail() ? "" : mPaymentParams.getEmail())); 
    postParamsBuffer.append(concatParams(PayuConstants.PRODUCT_INFO, mPaymentParams.getProductInfo())); 
    postParamsBuffer.append(concatParams(PayuConstants.FIRST_NAME, null == mPaymentParams.getFirstName() ? "" : mPaymentParams.getFirstName())); 
    postParamsBuffer.append(concatParams(PayuConstants.UDF1, mPaymentParams.getUdf1() == null ? "" : mPaymentParams.getUdf1())); 
    postParamsBuffer.append(concatParams(PayuConstants.UDF2, mPaymentParams.getUdf2() == null ? "" : mPaymentParams.getUdf2())); 
    postParamsBuffer.append(concatParams(PayuConstants.UDF3, mPaymentParams.getUdf3() == null ? "" : mPaymentParams.getUdf3())); 
    postParamsBuffer.append(concatParams(PayuConstants.UDF4, mPaymentParams.getUdf4() == null ? "" : mPaymentParams.getUdf4())); 
    postParamsBuffer.append(concatParams(PayuConstants.UDF5, mPaymentParams.getUdf5() == null ? "" : mPaymentParams.getUdf5())); 
    postParamsBuffer.append(concatParams(PayuConstants.USER_CREDENTIALS, mPaymentParams.getUserCredentials() == null ? PayuConstants.DEFAULT : mPaymentParams.getUserCredentials())); 
    if (null != mPaymentParams.getOfferKey()) 
     postParamsBuffer.append(concatParams(PayuConstants.OFFER_KEY, mPaymentParams.getOfferKey())); 

    JSONObject jsonObject = new JSONObject(); 
    try { 
     jsonObject.put("orderId", orderId); 
     jsonObject.put("userId", sharedPref.getUserId()); 
    } catch (JSONException e) { 
     e.printStackTrace(); 
    } 
    String postParams = jsonObject.toString(); 
    // String postParams = postParamsBuffer.charAt(postParamsBuffer.length() - 1) == '&' ? postParamsBuffer.substring(0, postParamsBuffer.length() - 1).toString() : postParamsBuffer.toString(); 
    Log.e("Post PAram for Hash", postParams); 
    // lets make an api call 
    GetHashesFromServerTask getHashesFromServerTask = new GetHashesFromServerTask(); 
    getHashesFromServerTask.execute(postParams); 
} 

스텝 3 : GetHashesFromServerTask 메소드를 호출.

private class GetHashesFromServerTask extends AsyncTask<String, String, PayuHashes> { 
    private ProgressDialog progressDialog; 

    @Override 
    protected void onPreExecute() { 
     super.onPreExecute(); 
     progressDialog = new ProgressDialog(ActivityConfirmOrder.this); 
     progressDialog.setMessage("Please wait..."); 
     progressDialog.setCancelable(false); 
     progressDialog.show(); 
    } 

    @Override 
    protected PayuHashes doInBackground(String... postParams) { 
     PayuHashes payuHashes = new PayuHashes(); 
     try { 
      URL url = new URL(AppConstant.BASE_URL + "/payment/getPaymentData"); 
      String postParam = postParams[0]; 
      Log.e("Post Params", 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)); 
      } 
      Log.e("Hash Response:::", responseStringBuffer.toString()); 

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

스텝 4 : 안드로이드 응용 프로그램에서 다른 방법

public void launchSdkUI(PayuHashes payuHashes) { 
    Intent intent = new Intent(ActivityConfirmOrder.this, PayUBaseActivity.class); 
    intent.putExtra(PayuConstants.PAYU_CONFIG, payuConfig); 
    intent.putExtra(PayuConstants.PAYMENT_PARAMS, mPaymentParams); 
    intent.putExtra(PayuConstants.PAYU_HASHES, payuHashes); 
    intent.putExtra(PayuConstants.SALT, merchantSalt); 
    intent.putExtra("PaymentType", "PAYU"); 
    startActivityForResult(intent, PayuConstants.PAYU_REQUEST_CODE); 
} 

public void onActivityResult(int requestCode, int resultCode, Intent data) { 

    if (requestCode == PayuConstants.PAYU_REQUEST_CODE) { 
     if (data != null) { 
      Log.e("PayuResponse", data.getStringExtra("payu_response")); 

      try { 
       JSONObject responseObject = new JSONObject(data.getStringExtra("payu_response")); 
       if (responseObject != null) { 
        if (responseObject.optString("status").equalsIgnoreCase("failure")) { 

         Toast.makeText(mContext, "Failure..", Toast.LENGTH_SHORT).show(); 


        } else { 
         //Toast.makeText(getActivity(), getString(R.string.could_not_receive_data), Toast.LENGTH_LONG).show(); 
        } 
       } else { 
        //Toast.makeText(getActivity(), getString(R.string.could_not_receive_data), Toast.LENGTH_LONG).show(); 
       } 
      } catch (JSONException e) { 
       e.printStackTrace(); 
       //Toast.makeText(getActivity(), getString(R.string.could_not_receive_data), Toast.LENGTH_LONG).show(); 
      } 

     } else { 
      //Toast.makeText(getActivity(), getString(R.string.could_not_receive_data), Toast.LENGTH_LONG).show(); 
     } 
    } else { 
     Log.e("Log MSg", "No Payu SDK Request Code"); 
    } 
} 

protected String concatParams(String key, String value) { 
    return key + "=" + value + "&"; 
} 

답변

1

는 다른 설정은 오류 "없는 필수 해시 키"를 얻을 것이다이 3 필수 해시 키가 있습니다. payuHash 오브젝트에이 3 개의 키를 설정했는지 확인하십시오.

  1. payuHashes.setPaymentHash (response.getString (key)));

  2. payuHashes.setVasForMobileSdkHash (response.getString (key));

  3. payuHashes.setPaymentRelatedDetailsForMobileSdkHash (response.getString (key));

0

필수 파람 해시는 상인들이 서버에서 PaymentRelatedDetailsForMobileSDK 해시를 생성하지 않고하지 PayU의 Webservice를 전화로 전달 될 때이 오류가 온다

없습니다. 다음은

이 해시를 생성하는 공식이다 : sha512(key|command|var1|salt)

Key - 판매자 키/테스트 키

Command - payment_related_details_for_mobile_sdk

Var1 - 기본/user_credentials

Salt - 상인 소금/시험용 소금

payuHashes.setVasForMobileSdkHash(hash);과 동일한 생성 된 해시를 설정하십시오.

참조하십시오. 이 link에서 2와 5 개의 오류가 있습니다.