'How to create a Hash on the server and how to use it?

I try too much but every time return Toast in "invalid Hash". I also try the change the server but the return toast is the same, every time some couple of seconds Payumonny screen is open and after then go back to the payment screen in java and an invalid toast appear

Here is my server file Hash.php to create a hash

<?php 
 $key = $_POST['key'];
 $texID = $_POST['texID'];
 $amount = $_POST['amount'];
 $proInfo = $_POST['productname'];
 $firstName = $_POST['name'];
 $email = $_POST['email'];
 $salt = "solt_key";
 
 

 $hashSeq = $key . '|' . $texID . '|' .$amount . '|' .$proInfo . '|' .$firstName. '|' .$email. '||||||||||'. $salt;

 
 
 $hash = hash("sha512",$hashSeq);

 
*here echo hash in the Json Object*
echo json_encode(array('payment_hash' => $hash));

?>

This is Android studio code

 public void startpay(){
        builder.setAmount(mAmount)                           ***Payment amount***
                .setTxnId(mTXNId)                            **Transaction ID**
                .setPhone(mPhoneNumber)                      *User Phone number*
                .setProductName(mProductInfo)                ***Product Name or description***
                .setFirstName(mFirstName)                    *User First name*
                .setEmail(mEmailId)                          *User Email ID*
                .setsUrl("https://www.payumoney.com/mobileapp/payumoney/success.php")      
                .setfUrl("https://www.payumoney.com/mobileapp/payumoney/failure.php")     
                .setUdf1("")
                .setUdf2("")
                .setUdf3("")
                .setUdf4("")
                .setUdf5("")
                .setUdf6("")
                .setUdf7("")
                .setUdf8("")
                .setUdf9("")
                .setUdf10("")
                .setIsDebug(true)                               *Integration environment - true* (Debug)/ false(Production)*
                .setKey(mMerchantKey)                         *Merchant key*
                .setMerchantId(mMerchandID);
        try {
            paymentParam = builder.build();
            // generateHashFromServer(paymentParam );
            getHashkey();
        } catch (Exception e) {
            Toast.makeText(FinalPlaceOrderActivity.this, "Error:"+e.toString(), Toast.LENGTH_SHORT).show();
        }
    }

*there calling API using with Volly*
 public void getHashkey(){

        StringRequest getHashKey = new StringRequest(Request.Method.POST, "Api_url", new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {

                System.out.println("Responce:"+response);

                try {
                    JSONObject object = new JSONObject(response);
                    String merchantHash = object.getString("payment_hash");

                    paymentParam.setMerchantHash(merchantHash);
                     *Invoke the following function to open the checkout page.
                     PayUmoneyFlowManager.startPayUMoneyFlow(paymentParam,* StartPaymentActivity.this,-1, true);
                    PayUmoneyFlowManager.startPayUMoneyFlow(paymentParam, FinalPlaceOrderActivity.this, R.style.AppTheme_default, true);

                } catch (JSONException e) {
                    Toast.makeText(FinalPlaceOrderActivity.this, "Error:"+e.toString(), Toast.LENGTH_SHORT).show();
                }


            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

                Toast.makeText(getApplicationContext(), "We can't process this time...", Toast.LENGTH_SHORT).show();
            }
        }
        ) {
            @Nullable
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<String, String>();

                map.put("key", mMerchantKey);
                map.put("texID", mTXNId);
                map.put("amount", mAmount);
                map.put("productname", mProductInfo);
                map.put("name", mFirstName);
                map.put("email", mEmailId);

                return map;
            }
        };

        Volley.newRequestQueue(FinalPlaceOrderActivity.this).add(getHashKey);
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source