SDK Integration
  • Getting Started
  • Onboarding Requirements
  • Hash Generation
  • Test Merchant list
  • Android
    • Android SDK Offering
    • PayUCheckoutPro
      • Integration
      • Build the Payment Params
        • Additional Params
      • Hash Generation
      • Set up the payment hashes
      • Initiate the Payment
      • Customized Integration
        • Set Webview Properties
        • SDK Configuration
        • Additional Offerings
      • Offers Integration
      • Convenience Fee Integration
      • Custom Note Integration
      • MCP Integration
    • Core
      • Supported Payment Types
      • TPV Integration
      • Merchant Web Services
        • Getting Enabled Payment Options
        • GetCheckoutDetails API
        • Lookup API
    • Custom Browser
      • Integration
        • CustomBrowser Config
        • CustomBrowserCallback
        • Supporting below Lollipop Versions
        • Third-Party Payments Support
      • Sample App
      • Change Logs
    • Native OTP Assist
      • Integration
      • Customization
      • Change Logs
    • UPI
      • Integration
      • TPV Integration in UPI
      • Sample App
      • Change Logs
    • Google Payâ„¢
      • Integration
      • Sample App
    • PhonePe
      • Integration
      • Sample App
      • Change Logs
    • OlaMoney
    • PayU OTP Parser
      • Integration
    • FAQ Android
  • iOS
    • PayUCheckoutPro
      • Integration
      • Advanced Integration
      • Set up the payment hashes
      • Convenience Fee Integration
      • MCP Integration
      • Custom Note Integration
    • Core
      • POD Integration
      • Seamless
      • Web Services
      • Objective C-Non-Seamless
      • Standing Instructions
      • TPV Integration
      • Sample App
    • Custom Browser
      • Sample App
    • OlaMoney
    • Native OTP Assist
      • Integration
      • Customization
    • UPI
      • Integration
      • Sample App
    • PayUParams
      • PayUSIParams
      • PayUBeneficiaryParams
  • Releasing to Apple
  • React-Native
    • PayUCheckoutPro
      • Integration
      • Set up the payment hashes
      • Advanced Integration
      • Change Logs
    • Core
    • Non-Seamless Wrapper
    • TPV (beta)
      • Integration
  • FAQ iOS
Powered by GitBook
On this page
  • Setting WebChromeClient
  • Setting WebViewClient

Was this helpful?

  1. Android
  2. PayUCheckoutPro
  3. Customized Integration

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);
        }
    }
    class CheckoutProWebChromeClient(
        val bank: Bank
    ) : PayUWebChromeClient(bank) {
        override fun onJsConfirm(
            view: WebView?,
            url: String?,
            message: String?,
            result: JsResult?
        ): Boolean {
            return super.onJsConfirm(view, url, message, result)
        }

        override fun onJsAlert(
            view: WebView?,
            url: String?,
            message: String?,
            result: JsResult?
        ): Boolean {
            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); 
                        } 
                    } 
                } 
            } 
    ); 
 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 = resources.getString(R.string.some_error_occurred) 
            } 
            
            override fun setWebViewProperties(webView: WebView?, bank: Any?) {
                webView?.webChromeClient = CheckoutProWebChromeClient(bank as Bank)
            }
                     
            override fun generateHash( 
                valueMap: HashMap<String, String?>, 
                hashGenerationListener: PayUHashGenerationListener 
            ) { 
                if ( valueMap.containsKey(CP_HASH_STRING) 
                    && valueMap.containsKey(CP_HASH_STRING) != null 
                    && valueMap.containsKey(CP_HASH_NAME) 
                    && valueMap.containsKey(CP_HASH_NAME) != null) { 
 
                    val hashData = valueMap[CP_HASH_STRING] 
                    val hashName = valueMap[CP_HASH_NAME] 
 
                    val hash: String? = 
                        HashGenerationUtils.generateHashFromSDK(hashData!!, salt) 
                    if (!TextUtils.isEmpty(hash)) { 
                        val dataMap: HashMap<String, String?> = HashMap() 
                        dataMap[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);
        }
    }
    class CheckoutProWebViewClient(bank: Bank, merchantKey: String): PayUWebViewClient(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); 
                        } 
                    } 
                } 
            } 
    ); 
 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 = resources.getString(R.string.some_error_occurred) 
            } 
            
            override fun setWebViewProperties(webView: WebView?, bank: Any?) {
                webView?.webViewClient = CheckoutProWebViewClient(bank as Bank, <merchant-key>)
            }
                     
            override fun generateHash( 
                valueMap: HashMap<String, String?>, 
                hashGenerationListener: PayUHashGenerationListener 
            ) { 
                if ( valueMap.containsKey(CP_HASH_STRING) 
                    && valueMap.containsKey(CP_HASH_STRING) != null 
                    && valueMap.containsKey(CP_HASH_NAME) 
                    && valueMap.containsKey(CP_HASH_NAME) != null) { 
 
                    val hashData = valueMap[CP_HASH_STRING] 
                    val hashName = valueMap[CP_HASH_NAME] 
 
                    val hash: String? = 
                        HashGenerationUtils.generateHashFromSDK(hashData!!, salt) 
                    if (!TextUtils.isEmpty(hash)) { 
                        val dataMap: HashMap<String, String?> = HashMap() 
                        dataMap[hashName!!] = hash!! 
                        hashGenerationListener.onHashGenerated(dataMap) 
                    } 
                } 
            } 
        })
PreviousCustomized IntegrationNextSDK Configuration

Last updated 4 years ago

Was this helpful?