"Some error occurred" 在 PayUMoney 支付网关中集成 android

"Some error occurred" in PayUMoney payment gateway while integrating in android

我已验证 PayUMoney 帐户。在沙盒模式下点击 paynow 按钮时显示 "some error occurred"。我用了pnp sdk

此代码用于点击立即付款按钮。

payNowButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            userAddress = address_line1.get(0) + "," + address_line2.get(0) + "," + address_pincode.get(0)
                    + "," + address_taluka + "," + address_district + "," + address_state;
            if (payment_type.equals("online")) {
                launchPayUMoneyFlow();
            } else if (payment_type.equals("cod")) {
                launchNormalFlow();
            }

        }
    });

这是哈希计算函数

public static String hashCal(String str) {
    byte[] hashseq = str.getBytes();
    StringBuilder hexString = new StringBuilder();
    try {
        MessageDigest algorithm = MessageDigest.getInstance("SHA-512");
        algorithm.reset();
        algorithm.update(hashseq);
        byte messageDigest[] = algorithm.digest();
        for (byte aMessageDigest : messageDigest) {
            String hex = Integer.toHexString(0xFF & aMessageDigest);
            if (hex.length() == 1) {
                hexString.append("0");
            }
            hexString.append(hex);
        }
    } catch (NoSuchAlgorithmException ignored) {
    }
    return hexString.toString();
}

当从 PayUMoney 收到响应时将调用以下函数

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result Code is -1 send from Payumoney activity
    Log.d("MainActivity", "request code " + requestCode + " resultcode " + resultCode);
    if (requestCode == PayUmoneyFlowManager.REQUEST_CODE_PAYMENT && resultCode == RESULT_OK && data !=
            null) {
        TransactionResponse transactionResponse = data.getParcelableExtra(PayUmoneyFlowManager
                .INTENT_EXTRA_TRANSACTION_RESPONSE);

        ResultModel resultModel = data.getParcelableExtra(PayUmoneyFlowManager.ARG_RESULT);

        // Check which object is non-null
        if (transactionResponse != null && transactionResponse.getPayuResponse() != null) {
            if (transactionResponse.getTransactionStatus().equals(TransactionResponse.TransactionStatus.SUCCESSFUL)) {
                //Success Transaction
            } else {
                //Failure Transaction
            }

            // Response from Payumoney
            String payuResponse = transactionResponse.getPayuResponse();

            // Response from SURl and FURL
            String merchantResponse = transactionResponse.getTransactionDetails();

            new AlertDialog.Builder(this)
                    .setCancelable(false)
                    .setMessage("Payu's Data : " + payuResponse + "\n\n\n Merchant's Data: " + merchantResponse)
                    .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.dismiss();
                        }
                    }).show();

        } else if (resultModel != null && resultModel.getError() != null) {
            Log.d(TAG, "Error response : " + resultModel.getError().getTransactionResponse());
        } else {
            Log.d(TAG, "Both objects are null!");
        }
    }
}

LaunchPayUMoneyFlow 是进行所有处理的函数。

String txnId="";

private void launchPayUMoneyFlow() {

    PayUmoneyConfig payUmoneyConfig = PayUmoneyConfig.getInstance();

    //Use this to set your custom text on result screen button
    payUmoneyConfig.setDoneButtonText("");

    //Use this to set your custom title for the activity
    payUmoneyConfig.setPayUmoneyActivityTitle("TEST GATEWAY");

    PayUmoneySdkInitializer.PaymentParam.Builder builder = new PayUmoneySdkInitializer.PaymentParam.Builder();

    try {
        amount = Double.parseDouble(final_total);

    } catch (Exception e) {
        e.printStackTrace();
    }
    txnId = System.currentTimeMillis() + "";
    String phone = userMobile;
    String productName = product_name;
    String firstName = userName;
    String email = "mayurdusane1@gmail.com";
    String udf1 = order_id;
    String udf2 = billingInfo;
    String udf3 = userAddress;
    String udf4 = userUID;
    String udf5 = request_time;
    String udf6 = "";
    String udf7 = "";
    String udf8 = "";
    String udf9 = "";
    String udf10 = "";

    AppEnvironment appEnvironment = AppEnvironment.SANDBOX;
    builder.setAmount(amount)
            .setTxnId(txnId)
            .setPhone(phone)
            .setProductName(productName)
            .setFirstName(firstName)
            .setEmail(email)
            .setsUrl(appEnvironment.surl())
            .setfUrl(appEnvironment.furl())
            .setUdf1(udf1)
            .setUdf2(udf2)
            .setUdf3(udf3)
            .setUdf4(udf4)
            .setUdf5(udf5)
            .setUdf6(udf6)
            .setUdf7(udf7)
            .setUdf8(udf8)
            .setUdf9(udf9)
            .setUdf10(udf10)
            .setIsDebug(false)
            .setKey("KEYHERE")
            .setMerchantId("MERCHANTIDHERE");

    try {
        mPaymentParams = builder.build();

generateHashFromServer(mPaymentParams);

    } catch (Exception e) {
        // some exception occurred
        Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
        payNowButton.setEnabled(true);
    }
}


/**
 * This method generates hash from server.
 *
 * @param paymentParam payments params used for hash generation
 */
public void generateHashFromServer(PayUmoneySdkInitializer.PaymentParam paymentParam) {
    RequestQueue queue1 = Volley.newRequestQueue(this);
    String url = "URL GOES HERE"; // Request a string response from the provided URL.
    StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {

                    JSONArray dataArray;
                    JSONObject jsonObject;
                    String merchantHash="";

                    try {
                        jsonObject = new JSONObject(response);
                        //dataArray = jsonObject.getJSONArray(JSON_ARRAY);
                        //Toast.makeText(getApplicationContext(), "m" + jsonObject.getString("result"), Toast.LENGTH_SHORT).show();
                        merchantHash = jsonObject.getString("result");

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    //setting up response values to the fragment
                    if (merchantHash.isEmpty() || merchantHash.equals("")) {
                        Toast.makeText(FinalCheckoutActivity.this, "Could not generate hash", Toast.LENGTH_SHORT).show();
                    } else {
                        mPaymentParams.setMerchantHash(merchantHash);
                        //Toast.makeText(FinalCheckoutActivity.this, "m:"+mPaymentParams.getParams(), Toast.LENGTH_SHORT).show();
                        //Log.e(TAG, "onPostExecute: "+mPaymentParams.getParams() );
                        PayUmoneyFlowManager.startPayUMoneyFlow(mPaymentParams, FinalCheckoutActivity.this, -1, false);
                    }

                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getApplication(), "Error:" + error, Toast.LENGTH_LONG).show();
        }

    }) {
        @Override
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<String, String>();
            params.put(PayUmoneyConstants.KEY,"KEYHERE" );
            params.put(PayUmoneyConstants.AMOUNT,amount+"" );
            params.put(PayUmoneyConstants.TXNID,txnId);
            params.put(PayUmoneyConstants.EMAIL,userEmail);
            params.put(PayUmoneyConstants.PRODUCT_INFO,product_name);
            params.put(PayUmoneyConstants.FIRSTNAME,userName);
            params.put(PayUmoneyConstants.UDF1,order_id );
            params.put(PayUmoneyConstants.UDF2,billingInfo );
            params.put(PayUmoneyConstants.UDF3,userAddress);
            params.put(PayUmoneyConstants.UDF4,userUID);
            params.put(PayUmoneyConstants.UDF5,request_time);

            return params;
        }
    };
    queue1.add(stringRequest);
}

执行流程:

执行 PayUmoneyFlowManager.startPayUMoneyFlow() 后显示 "Some error occurred"

哈希生成脚本

    <?php
$key=$_POST["key"];
$salt="SALTHERE";
$txnId=$_POST["txnid"];
$amount=$_POST["amount"];
$productName=$_POST["productInfo"];
$firstName=$_POST["firstName"];
$email=$_POST["email"];
$udf1=$_POST["udf1"];
$udf2=$_POST["udf2"];
$udf3=$_POST["udf3"];
$udf4=$_POST["udf4"];
$udf5=$_POST["udf5"];

$payhash_str = $key . '|' . checkNull($txnId) . '|' .checkNull($amount)  . '|' .checkNull($productName)  . '|' . checkNull($firstName) . '|' . checkNull($email) . '|' . checkNull($udf1) . '|' . checkNull($udf2) . '|' . checkNull($udf3) . '|' . checkNull($udf4) . '|' . checkNull($udf5) . '|||||||'. $salt;


function checkNull($value) {
            if ($value == null) {
                  return '';
            } else {
                  return $value;
            }
      }
$hash = strtolower(hash('sha512', $payhash_str));
$arr['result'] = $hash;
$arr['status']=0;
$arr['errorCode']=null;
$arr['responseCode']=null;
$output=$arr;

echo json_encode($output);
?>

注意:哈希生成脚本是从PayUMoney技术团队获得的。 我提到了几乎所有关于 Whosebug 和 github 的问题。仍然收到此错误。我提到的资料很少。

  1. 'sorry some error occurred' while integrating PayUMoney payment gateway in Test mode
  2. https://github.com/payu-intrepos/PayUMoney-Android-SDK/issues/3
  3. Android PayUMoney integration error "some error occured"
  4. PayuMoney Integration in Android : Some error occured! Try again
  5. 'sorry some error occurred' while integrating PayUMoney payment gateway in Test mode

PayU SDK 应将此 "Some error occured" 替换为正确的错误消息。

此问题是因为您的哈希与 PayUServer 不匹配

因为|的数量不匹配.

尝试在 Php 文件中替换它:

. checkNull($udf5) . '||||||'. $salt

迟到的答案,但希望这对仍在寻找解决方案的其他人有所帮助。

请勿更改 PayU 团队提供给您的代码。

用于生产,

  1. 只需在 AppPreference.java 文件中输入一些有效的详细信息。

  2. 现在在服务器 php script 中用您的 production salt = "xxxxxxx" 值替换 salt 值。

  3. 并且,将Hash生成格式替换为以下格式:

这会起作用。

$payhash_str = $key . '|' . checkNull($txnId) . '|' .checkNull($amount) . '|' .checkNull($productName) . '|' . checkNull($firstName) . '|' . checkNull($email) . '|' . checkNull($udf1) . '|' . checkNull($udf2) . '|' . checkNull($udf3) . '|' . checkNull($udf4) . '|' . checkNull($udf5) . '||||||'. $salt;
$retHashSeq = $KEY.'|'.$posted["txnid"].'|'.$posted["amount"].'|'."Product".'|'.$posted["firstname"].'|'.$posted["email"].'|'.$posted["udf1"].'|'.$posted["udf2"].'|'.$posted["udf3"].'|'.$posted["udf4"].'|'.$posted["udf5"].'||||||'.$SALT;