Set Webview Properties

PayUCheckoutPro SDK allows to set WebViewClient and WebChromeClient in the embedded WebView

Setting WebChromeClient

To set your WebChromeClient in PayUCheckoutPro SDK, it must extend PayUWebChromeClient class as below

    class CheckoutProWebChromeClient extends PayUWebChromeClient{
        public CheckoutProWebChromeClient(Bank bank){
            super(bank);
        }

        @Override
        public boolean onJsConfirm(WebView view, String url, String message, JsResult result) {
            return super.onJsConfirm(view, url, message, result);
        }

        @Override
        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            return super.onJsAlert(view, url, message, result);
        }
    }

After creating your WebChromeClient, it can be set in PayUCheckoutPro SDK in setWebViewProperties() callback method of PayUCheckoutProListener as below

PayUCheckoutPro.open( 
            this, 
            payUPaymentParams, 
            new PayUCheckoutProListener() { 
        

                @Override 
                public void onPaymentSuccess(@NotNull Object response) { 
                                        //Cast response object to HashMap
                    HashMap<String,Object> result = (HashMap<String, Object>) response 
                    String payuResponse = result.get(PayUCheckoutProConstants.CP_PAYU_RESPONSE);
                    String merchantResponse = result.get(PayUCheckoutProConstants.CP_MERCHANT_RESPONSE)); 
                } 
 
                @Override 
                public void onPaymentFailure(@NotNull Object response) {
                    //Cast response object to HashMap
                    HashMap<String,Object> result = (HashMap<String, Object>) response 
                    String payuResponse = result.get(PayUCheckoutProConstants.CP_PAYU_RESPONSE);
                    String merchantResponse = result.get(PayUCheckoutProConstants.CP_MERCHANT_RESPONSE));
                } 
 
                @Override 
                public void onPaymentCancel(boolean isTxnInitiated) { 
                } 
 
                @Override 
                public void onError(@NotNull ErrorResponse errorResponse) { 
                    String errorMessage = errorResponse.getErrorMessage(); 
                } 
 
                @Override
                public void setWebViewProperties(@Nullable WebView webView, @Nullable Object o) {
                    webView.setWebChromeClient(new CheckoutProWebChromeClient((Bank)o));
                }
                
                @Override 
                public void generateHash(@NotNull HashMap<String, String> valueMap, @NotNull PayUHashGenerationListener hashGenerationListener) { 
                    String hashName = valueMap.get(CP_HASH_NAME); 
                    String hashData = valueMap.get(CP_HASH_STRING); 
                    if (!TextUtils.isEmpty(hashName) && !TextUtils.isEmpty(hashData)) { 
                        //Generate Hash from your backend here
                            String hash = HashGenerationUtils.INSTANCE.generateHashFromSDK(hashData, salt); 
                            HashMap<String, String> dataMap = new HashMap<>(); 
                            dataMap.put(hashName, hash); 
                            hashGenerationListener.onHashGenerated(dataMap); 
                        } 
                    } 
                } 
            } 
    ); 

Setting WebViewClient

To set your WebViewClient in PayUCheckoutPro SDK, it must extend PayUWebViewClient class as below

    class CheckoutProWebViewClient extends PayUWebViewClient{
        public CheckoutProWebViewClient(Bank bank, String merchantKey){
            super(bank, merchantKey);
        }
    }

After creating your WebViewClient, it can be set in PayUCheckoutPro SDK in setWebViewProperties() callback method of PayUCheckoutProListener as below

PayUCheckoutPro.open( 
            this, 
            payUPaymentParams, 
            new PayUCheckoutProListener() { 
        

                @Override 
                public void onPaymentSuccess(@NotNull Object response) { 
                                        //Cast response object to HashMap
                    HashMap<String,Object> result = (HashMap<String, Object>) response 
                    String payuResponse = result.get(PayUCheckoutProConstants.CP_PAYU_RESPONSE);
                    String merchantResponse = result.get(PayUCheckoutProConstants.CP_MERCHANT_RESPONSE)); 
                } 
 
                @Override 
                public void onPaymentFailure(@NotNull Object response) {
                    //Cast response object to HashMap
                    HashMap<String,Object> result = (HashMap<String, Object>) response 
                    String payuResponse = result.get(PayUCheckoutProConstants.CP_PAYU_RESPONSE);
                    String merchantResponse = result.get(PayUCheckoutProConstants.CP_MERCHANT_RESPONSE));
                } 
 
                @Override 
                public void onPaymentCancel(boolean isTxnInitiated) { 
                } 
 
                @Override 
                public void onError(@NotNull ErrorResponse errorResponse) { 
                    String errorMessage = errorResponse.getErrorMessage(); 
                } 
 
                @Override
                public void setWebViewProperties(@Nullable WebView webView, @Nullable Object o) {
                    webView.setWebViewClient(new CheckoutProWebViewClient((Bank)o, <merchant-key>));
                }
                
                @Override 
                public void generateHash(@NotNull HashMap<String, String> valueMap, @NotNull PayUHashGenerationListener hashGenerationListener) { 
                    String hashName = valueMap.get(CP_HASH_NAME); 
                    String hashData = valueMap.get(CP_HASH_STRING); 
                    if (!TextUtils.isEmpty(hashName) && !TextUtils.isEmpty(hashData)) { 
                        //Generate Hash from your backend here
                            String hash = HashGenerationUtils.INSTANCE.generateHashFromSDK(hashData, salt); 
                            HashMap<String, String> dataMap = new HashMap<>(); 
                            dataMap.put(hashName, hash); 
                            hashGenerationListener.onHashGenerated(dataMap); 
                        } 
                    } 
                } 
            } 
    ); 

Last updated