CustomBrowserCallback
Describes how to create an object of PayUCustomBrowserCallback.
PayUCustomBrowserCallback provides following callback methods.
  • onPaymentFailure(String payuResult,String merchantResponse) - Calls when payment fails.
  • onPaymentSuccess(String payuResult,String merchantResponse) - Calls when payment succeeds.
  • onCBErrorReceived(int errorCode,String errormsg) - Called for any error in custom browser.
Following error messages are thrown in callback method.
1
Error code : Errormsg
2
3
1 : VENDOR_NOT_SUPPORTED // Device Vendor is not supported
4
2 : DEVICE_NOT_SUPPORTED // Device is not supported
5
3 : APP_VERSION_MISMATCH // Samsung Pay version doesn't meet requirements
6
4 : COUNTRY_NOT_SUPPORTED // Country of device origin is not supported by Samsung Pay
7
5 : MERCHANT_KEY_NOT_REGISTER_FOR_SAMSUNG_PAY // Merchant is not registered for
8
Samsung Pay with PayU
9
10
6 : CONTEXT_NULL // Context is null
11
7 : PAYMENT_ID_NOT_PRESENT // Check your postdata
12
1001 : DEVICE_NOT_SUPPORTED //In case enablewebflow is set to false for Tez payment and Tez app is not present on device following error would be thrown
13
1002 : MERCHANT_INFO_NOT_PRESENT // In case below error is received while processing payment please check your postData and hash
Copied!
  • setCBProperties(WebView webview, Bank payUCustomBrowser) - Callback where webview setting is done.
  • onBackButton(AlertDialog.Builder alertDialogBuilder) - This callback provides alert dialog access, so customisation can be done to alert dialog.
  • onBackApprove() - Calls when ‘ok’ is selected from alert dialog.
  • onBackDismiss()- Calls when ‘cancel’ is selected from alert dialog.
  • onPaymentTerminate() - Called when payment is terminated.
  • isPaymentOptionAvailable(CustomBrowserResultData resultData):Merchant must check for Samsung Pay/PhonePe payment option availability on customer device before showing Samsung Pay/PhonePe/Google Pay/UPI as payment option.This callback is called in response of checkForPaymentAvailability method present in CustomBrowser.Merchant can use value of resultData object like below.
1
resultData.getPaymentOption() - Gives PaymentOption i.e. SamsungPay/PhonePe/Google Pay/UPI.
2
resultData.isPaymentOptionAvailable() - Boolean whether Payment via selected PaymentOption is possible.
3
resultData.getSamsungPayVpa() - Gives SamsungPay Vpa associated with device.
4
resultData.getErrorMessage() - Gives error message in case PaymentOption is not available.
Copied!
  • onVpaEntered(String vpa, PackageListDialogFragment packageListDialogFragment)(Available since version 7.3.0) - Merchant must override this function and provide verifyVpaHash in case they want payment via UPI Collect flow.
1
packageListDialogFragment.verifyVpa(verifyVpaHash);
Copied!
To generate verifyVpaHash use command as validateVPA and var1 as Vpa address and calculate hash as described here.
Sample code for PayUCustomBrowserCallback:
1
PayUCustomBrowserCallback payUCustomBrowserCallback = new PayUCustomBrowserCallback() {
2
@Override
3
public void onPaymentFailure(String payuResponse,String merchantResponse) {
4
Intent intent = new Intent();
5
intent.putExtra(getString(R.string.cb_result), merchantResponse);
6
intent.putExtra(getString(R.string.cb_payu_response), payuResponse);
7
setResult(Activity.RESULT_CANCELED, intent);
8
finish();
9
}
10
11
@Override
12
public void onPaymentTerminate() {
13
}
14
15
@Override
16
public void onPaymentSuccess(String payuResponse,String merchantResponse) {
17
Intent intent = new Intent();
18
intent.putExtra(getString(R.string.cb_result), merchantResponse);
19
intent.putExtra(getString(R.string.cb_payu_response), payuResponse);
20
setResult(Activity.RESULT_OK, intent);
21
finish();
22
}
23
24
@Override
25
public void onCBErrorReceived(int code, String errormsg) {
26
}
27
28
29
30
@Override
31
public void setCBProperties(WebView webview, Bank payUCustomBrowser) {
32
webview.setWebChromeClient(new PayUWebChromeClient(payUCustomBrowser));
33
webview.setWebViewClient(new PayUWebViewClient(payUCustomBrowser,merchantKey));
34
webview.postUrl(url, payuConfig.getData().getBytes());
35
//comment above line if you are using CB is 6.1 or above
36
}
37
38
@Override
39
public void onBackApprove() {
40
PaymentsActivity.this.finish();
41
}
42
43
@Override
44
public void onBackDismiss() {
45
super.onBackDismiss();
46
}
47
48
@Override
49
public void onBackButton(AlertDialog.Builder alertDialogBuilder) {
50
super.onBackButton(alertDialogBuilder);
51
}
52
53
//Below method is available since version 7.1.3+
54
@Override
55
public void isPaymentOptionAvailable(CustomBrowserResultData resultData) {
56
Toast.makeText(PaymentsActivity.this, "isPaymentOptionAvailable"+resultData.getSamsungPayVpa()
57
, Toast.LENGTH_SHORT).show();
58
}
59
60
//Below method is available since version 7.3.0+
61
@Override
62
public void onVpaEntered(String vpa, PackageListDialogFragment packageListDialogFragment) {
63
//Calculate validateVpahash using vpa and provide to verifyVpa method of
64
PackageListDialogFragment like below.
65
packageListDialogFragment.verifyVpa(calculateHash(input));
66
}
67
68
};
Copied!
Copy link