PayUCheckout pro [PayuMoney] onError method called in android app

45 views Asked by At

I have get the MerchantID and SaltKey from the website after that I have been using

implementation 'in.payu:payu-checkout-pro:2.0.23' in build gradle.

But the Response is E/ErrorMessage: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject Please help me to resolve it


        btnPay.setOnClickListener {

            val additionalParamsMap: HashMap<String, Any?> = HashMap()
            additionalParamsMap[PayUCheckoutProConstants.CP_UDF1] = "udf1"
            additionalParamsMap[PayUCheckoutProConstants.CP_UDF2] = "udf2"
            additionalParamsMap[PayUCheckoutProConstants.CP_UDF3] = "udf3"
            additionalParamsMap[PayUCheckoutProConstants.CP_UDF4] = "udf4"
            additionalParamsMap[PayUCheckoutProConstants.CP_UDF5] = "udf5"
            additionalParamsMap[PayUCheckoutProConstants.SODEXO_SOURCE_ID] = "srcid123"

            val payUPaymentParams = PayUPaymentParams.Builder()
                .setAmount("10")
                .setIsProduction(true)
                .setKey("Key")
                .setProductInfo("Macbook Pro")
                .setPhone("9874563210")
                .setTransactionId(System.currentTimeMillis().toString())
                .setFirstName("firstname")
                .setEmail("email")
                .setSurl("https://payuresponse.firebaseapp.com/success")
                .setFurl("https://payuresponse.firebaseapp.com/failure")
                .setUserCredential("key:email")
                .setAdditionalParams(additionalParamsMap)
                .build()

            PayUCheckoutPro.open(
                this, payUPaymentParams,
                object : PayUCheckoutProListener {


                    override fun onPaymentSuccess(response: Any) {
                        response as HashMap<*, *>
                        val payUResponse = response[PayUCheckoutProConstants.CP_PAYU_RESPONSE]
                        val merchantResponse =
                            response[PayUCheckoutProConstants.CP_MERCHANT_RESPONSE]
                    }


                    override fun onPaymentFailure(response: Any) {
                        response as HashMap<*, *>
                        val payUResponse = response[PayUCheckoutProConstants.CP_PAYU_RESPONSE]
                        val merchantResponse =
                            response[PayUCheckoutProConstants.CP_MERCHANT_RESPONSE]
                    }


                    override fun onPaymentCancel(isTxnInitiated: Boolean) {
                    }


                    override fun onError(errorResponse: ErrorResponse) {
                        val errorMessage: String
                        if (errorResponse != null && errorResponse.errorMessage != null
                            && errorResponse.errorMessage!!.isNotEmpty()
                        )
                            errorMessage = errorResponse.errorMessage!!
                        else
                            errorMessage = "Error Message"


                        Log.e("ErrorMessage",""+errorResponse.errorMessage);
                    }

                    override fun setWebViewProperties(webView: WebView?, bank: Any?) {
                        //For setting webview properties, if any.
                    // Check Customized Integration section for more details on this
                    }

                    override fun generateHash(
                        valueMap: HashMap<String, String?>,
                        hashGenerationListener: PayUHashGenerationListener
                    ) {
                        if (valueMap.containsKey(CP_HASH_STRING) &&
                            valueMap.containsKey(CP_HASH_NAME)
                        ) {

                            val hashData = valueMap[CP_HASH_STRING]
                            val hashName = valueMap[CP_HASH_NAME]

                            val hashString: String? = HashGenerationUtils.generateHashFromSDK(
                                hashData.toString(),
                                "Saltkey"
                            )

                            //Do not generate hash from local,
                            // it needs to be calculated from server side only. Here,
                            // hashString contains hash created from your server side.
                            val hash: String? = hashString

                            if (!TextUtils.isEmpty(hash)) {
                                val dataMap: HashMap<String, String?> = HashMap()
                                dataMap[hashName!!] = hash!!
                                hashGenerationListener.onHashGenerated(dataMap)
                            }
                        }
                    }
                })
        }

Hash generation in local and i tried to generate in server also...

1

There are 1 answers

0
KarthiDreamr On

The test values given in the website no longer works use these values I've got by sending a complaint mail

key -> 'gtKFFx'
merchantSalt -> '4R38IvwiV57FwVpsgOvTXBdLE4tHUXFW'

If you want to learn more about the issues https://medium.com/@karthidreamr/payu-integration-in-react-native-with-checkoutpro-sdk-f70d2d1fd790