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
Java
Kotlin
1
class CheckoutProWebChromeClient extends PayUWebChromeClient{
2
public CheckoutProWebChromeClient(Bank bank){
3
super(bank);
4
}
5
6
@Override
7
public boolean onJsConfirm(WebView view, String url, String message, JsResult result) {
8
return super.onJsConfirm(view, url, message, result);
9
}
10
11
@Override
12
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
13
return super.onJsAlert(view, url, message, result);
14
}
15
}
Copied!
1
class CheckoutProWebChromeClient(
2
val bank: Bank
3
) : PayUWebChromeClient(bank) {
4
override fun onJsConfirm(
5
view: WebView?,
6
url: String?,
7
message: String?,
8
result: JsResult?
9
): Boolean {
10
return super.onJsConfirm(view, url, message, result)
11
}
12
13
override fun onJsAlert(
14
view: WebView?,
15
url: String?,
16
message: String?,
17
result: JsResult?
18
): Boolean {
19
return super.onJsAlert(view, url, message, result)
20
}
21
}
Copied!
After creating your WebChromeClient, it can be set in PayUCheckoutPro SDK in setWebViewProperties() callback method of PayUCheckoutProListener as below
Java
Kotlin
1
PayUCheckoutPro.open(
2
this,
3
payUPaymentParams,
4
new PayUCheckoutProListener() {
5
6
7
@Override
8
public void onPaymentSuccess(@NotNull Object response) {
9
//Cast response object to HashMap
10
HashMap<String,Object> result = (HashMap<String, Object>) response
11
String payuResponse = result.get(PayUCheckoutProConstants.CP_PAYU_RESPONSE);
12
String merchantResponse = result.get(PayUCheckoutProConstants.CP_MERCHANT_RESPONSE));
13
}
14
15
@Override
16
public void onPaymentFailure(@NotNull Object response) {
17
//Cast response object to HashMap
18
HashMap<String,Object> result = (HashMap<String, Object>) response
19
String payuResponse = result.get(PayUCheckoutProConstants.CP_PAYU_RESPONSE);
20
String merchantResponse = result.get(PayUCheckoutProConstants.CP_MERCHANT_RESPONSE));
21
}
22
23
@Override
24
public void onPaymentCancel(boolean isTxnInitiated) {
25
}
26
27
@Override
28
public void onError(@NotNull ErrorResponse errorResponse) {
29
String errorMessage = errorResponse.getErrorMessage();
30
}
31
32
@Override
33
public void setWebViewProperties(@Nullable WebView webView, @Nullable Object o) {
34
webView.setWebChromeClient(new CheckoutProWebChromeClient((Bank)o));
35
}
36
37
@Override
38
public void generateHash(@NotNull HashMap<String, String> valueMap, @NotNull PayUHashGenerationListener hashGenerationListener) {
39
String hashName = valueMap.get(CP_HASH_NAME);
40
String hashData = valueMap.get(CP_HASH_STRING);
41
if (!TextUtils.isEmpty(hashName) && !TextUtils.isEmpty(hashData)) {
42
//Generate Hash from your backend here
43
String hash = HashGenerationUtils.INSTANCE.generateHashFromSDK(hashData, salt);
44
HashMap<String, String> dataMap = new HashMap<>();
45
dataMap.put(hashName, hash);
46
hashGenerationListener.onHashGenerated(dataMap);
47
}
48
}
49
}
50
}
51
);
Copied!
1
PayUCheckoutPro.open(
2
this, payUPaymentParams,
3
object : PayUCheckoutProListener {
4
5
6
override fun onPaymentSuccess(response: Any) {
7
response as HashMap<*, *>
8
val payUResponse = response[PayUCheckoutProConstants.CP_PAYU_RESPONSE]
9
val merchantResponse = response[PayUCheckoutProConstants.CP_MERCHANT_RESPONSE]
10
}
11
12
13
override fun onPaymentFailure(response: Any) {
14
response as HashMap<*, *>
15
val payUResponse = response[PayUCheckoutProConstants.CP_PAYU_RESPONSE]
16
val merchantResponse = response[PayUCheckoutProConstants.CP_MERCHANT_RESPONSE]
17
}
18
19
20
override fun onPaymentCancel(isTxnInitiated:Boolean) {
21
}
22
23
24
override fun onError(errorResponse: ErrorResponse) {
25
val errorMessage: String
26
if (errorResponse != null && errorResponse.errorMessage != null && errorResponse.errorMessage!!.isNotEmpty())
27
errorMessage = errorResponse.errorMessage!!
28
else
29
errorMessage = resources.getString(R.string.some_error_occurred)
30
}
31
32
override fun setWebViewProperties(webView: WebView?, bank: Any?) {
33
webView?.webChromeClient = CheckoutProWebChromeClient(bank as Bank)
34
}
35
36
override fun generateHash(
37
valueMap: HashMap<String, String?>,
38
hashGenerationListener: PayUHashGenerationListener
39
) {
40
if ( valueMap.containsKey(CP_HASH_STRING)
41
&& valueMap.containsKey(CP_HASH_STRING) != null
42
&& valueMap.containsKey(CP_HASH_NAME)
43
&& valueMap.containsKey(CP_HASH_NAME) != null) {
44
45
val hashData = valueMap[CP_HASH_STRING]
46
val hashName = valueMap[CP_HASH_NAME]
47
48
val hash: String? =
49
HashGenerationUtils.generateHashFromSDK(hashData!!, salt)
50
if (!TextUtils.isEmpty(hash)) {
51
val dataMap: HashMap<String, String?> = HashMap()
52
dataMap[hashName!!] = hash!!
53
hashGenerationListener.onHashGenerated(dataMap)
54
}
55
}
56
}
57
})
Copied!

Setting WebViewClient

To set your WebViewClient in PayUCheckoutPro SDK, it must extend PayUWebViewClient class as below
Java
Kotlin
1
class CheckoutProWebViewClient extends PayUWebViewClient{
2
public CheckoutProWebViewClient(Bank bank, String merchantKey){
3
super(bank, merchantKey);
4
}
5
}
Copied!
1
class CheckoutProWebViewClient(bank: Bank, merchantKey: String): PayUWebViewClient(bank, merchantKey){
2
3
}
Copied!
After creating your WebViewClient, it can be set in PayUCheckoutPro SDK in setWebViewProperties() callback method of PayUCheckoutProListener as below
Java
Kotlin
1
PayUCheckoutPro.open(
2
this,
3
payUPaymentParams,
4
new PayUCheckoutProListener() {
5
6
7
@Override
8
public void onPaymentSuccess(@NotNull Object response) {
9
//Cast response object to HashMap
10
HashMap<String,Object> result = (HashMap<String, Object>) response
11
String payuResponse = result.get(PayUCheckoutProConstants.CP_PAYU_RESPONSE);
12
String merchantResponse = result.get(PayUCheckoutProConstants.CP_MERCHANT_RESPONSE));
13
}
14
15
@Override
16
public void onPaymentFailure(@NotNull Object response) {
17
//Cast response object to HashMap
18
HashMap<String,Object> result = (HashMap<String, Object>) response
19
String payuResponse = result.get(PayUCheckoutProConstants.CP_PAYU_RESPONSE);
20
String merchantResponse = result.get(PayUCheckoutProConstants.CP_MERCHANT_RESPONSE));
21
}
22
23
@Override
24
public void onPaymentCancel(boolean isTxnInitiated) {
25
}
26
27
@Override
28
public void onError(@NotNull ErrorResponse errorResponse) {
29
String errorMessage = errorResponse.getErrorMessage();
30
}
31
32
@Override
33
public void setWebViewProperties(@Nullable WebView webView, @Nullable Object o) {
34
webView.setWebViewClient(new CheckoutProWebViewClient((Bank)o, <merchant-key>));
35
}
36
37
@Override
38
public void generateHash(@NotNull HashMap<String, String> valueMap, @NotNull PayUHashGenerationListener hashGenerationListener) {
39
String hashName = valueMap.get(CP_HASH_NAME);
40
String hashData = valueMap.get(CP_HASH_STRING);
41
if (!TextUtils.isEmpty(hashName) && !TextUtils.isEmpty(hashData)) {
42
//Generate Hash from your backend here
43
String hash = HashGenerationUtils.INSTANCE.generateHashFromSDK(hashData, salt);
44
HashMap<String, String> dataMap = new HashMap<>();
45
dataMap.put(hashName, hash);
46
hashGenerationListener.onHashGenerated(dataMap);
47
}
48
}
49
}
50
}
51
);
Copied!
1
PayUCheckoutPro.open(
2
this, payUPaymentParams,
3
object : PayUCheckoutProListener {
4
5
6
override fun onPaymentSuccess(response: Any) {
7
response as HashMap<*, *>
8
val payUResponse = response[PayUCheckoutProConstants.CP_PAYU_RESPONSE]
9
val merchantResponse = response[PayUCheckoutProConstants.CP_MERCHANT_RESPONSE]
10
}
11
12
13
override fun onPaymentFailure(response: Any) {
14
response as HashMap<*, *>
15
val payUResponse = response[PayUCheckoutProConstants.CP_PAYU_RESPONSE]
16
val merchantResponse = response[PayUCheckoutProConstants.CP_MERCHANT_RESPONSE]
17
}
18
19
20
override fun onPaymentCancel(isTxnInitiated:Boolean) {
21
}
22
23
24
override fun onError(errorResponse: ErrorResponse) {
25
val errorMessage: String
26
if (errorResponse != null && errorResponse.errorMessage != null && errorResponse.errorMessage!!.isNotEmpty())
27
errorMessage = errorResponse.errorMessage!!
28
else
29
errorMessage = resources.getString(R.string.some_error_occurred)
30
}
31
32
override fun setWebViewProperties(webView: WebView?, bank: Any?) {
33
webView?.webViewClient = CheckoutProWebViewClient(bank as Bank, <merchant-key>)
34
}
35
36
override fun generateHash(
37
valueMap: HashMap<String, String?>,
38
hashGenerationListener: PayUHashGenerationListener
39
) {
40
if ( valueMap.containsKey(CP_HASH_STRING)
41
&& valueMap.containsKey(CP_HASH_STRING) != null
42
&& valueMap.containsKey(CP_HASH_NAME)
43
&& valueMap.containsKey(CP_HASH_NAME) != null) {
44
45
val hashData = valueMap[CP_HASH_STRING]
46
val hashName = valueMap[CP_HASH_NAME]
47
48
val hash: String? =
49
HashGenerationUtils.generateHashFromSDK(hashData!!, salt)
50
if (!TextUtils.isEmpty(hash)) {
51
val dataMap: HashMap<String, String?> = HashMap()
52
dataMap[hashName!!] = hash!!
53
hashGenerationListener.onHashGenerated(dataMap)
54
}
55
}
56
}
57
})
Copied!
Last modified 10mo ago