Skip to content

Android Custom Browser

himgupta229 edited this page Oct 15, 2019 · 4 revisions

Welcome to the Android-Custom-Browser wiki!


Gradle: compile 'com.payu.custombrowser:payu-custom-browser:7.5.0'

Note: From version 7.4.0 onwards it is mandatory to import UPI sdk dependency 'com.payu.upisdk:upisdk:1.0.1' in case you want to make payments via any UPI option viz. : Intent, Collect, GPay, PhonePe ,SamsungPay

Download latest Android CustomBrowser

Integration:



Custom browser 6.0 and above

1. Download the CustomBrowser-release.aar file from github. Rename it to CustomBrowser.aar
2. Import CustomBrowser as a module.
3. Make sure that app has a module dependency on CustomBrowser.
4. Grant following permission in AndroidManifest.xml file.(Mandatory)
<uses-permission android:name="android.permission.RECEIVE_SMS" />
5. Make sure that your Activity is able to support Fragments (v7 support library)
6. Basic Code snippet to add Custom browser (applicable till version 6.0 NOT above it)
PayUCustomBrowserCallback payUCustomBrowserCallback = new PayUCustomBrowserCallback() {
 @Override
    public void setCBProperties(WebView webview, Bank payUCustomBrowser) 
    {
      webview.postUrl(url, payuConfig.getData().getBytes());
    }
};
CustomBrowserConfig customBrowserConfig = new CustomBrowserConfig(merchantKey,txnId);
new CustomBrowser().addCustomBrowser(PaymentsActivity.this,customBrowserConfig , payUCustomBrowserCallback);
7. Method checkForPaymentAvailability() (Available on version 7.1.3+) [ To be called mandatory for making payment by Samsung Pay before calling addCustomBrowser ]

Function in CustomBrowser class. Checks for payment option type availability

To make payment by Samsung Pay import 'com.payu.samsungpay:samsungpay:1.0' in your project

To make payment by PhonePe import 'com.payu.phonepe:phonepe-intent:1.0.0' in your project

Input:
    	Activity : activity instance
        PaymentOption : Payment Option type e.g.PaymentOption.SAMSUNGPAY,PaymentOption.PHONEPE
        PayUCustomBrowserCallback : this class provide callbacks 
        paymentOptionHash : Payment Related Details Hash
        merchantKey       : PayU Merchant Key
        user_credentials  : User credentials or use "default"

Notes:

 To generate paymentoptionHash use below method
                   sha512(key|command|var1|salt) 
 where key     = Provide your merchant key here
       command = "payment_related_details_for_mobile_sdk"
       var1    = Provide user credentials or use "default"
       salt    = Provide your merchant salt here

Sample

new CustomBrowser().checkForPaymentAvailability(Activity activity, PaymentOption paymentOption,  PayUCustomBrowserCallback payUCustomBrowserCallback, String paymentOptionHash, String merchantKey, String user_credentials){
8. Method addCustomBrowser()

Function in CustomBrowser class. Add Custom Browser to the application

Input:
    	Activity : activity instance
        CustomBrowserConfig : configuration object of the custom browser
        PayUCustomBrowserCallback : this class provide callbacks 

Sample

new CustomBrowser().addCustomBrowser( Activity activity, CustomBrowserConfig cbCustomBrowserConfig, PayUCustomBrowserCallback cbPayUCustomBrowserCallback)
9. CustomBrowserConfig

Initialize CustomBrowserConfig CustomBrowserConfig customBrowserConfig = new CustomBrowserConfig(String merchantKey,String txnId);

ViewPortEnable - setViewPortWideEnable(viewPortWide)

  • set ViewPortWideEnable true for net banking else false

    • true - set viewport true
    • false - set viewport false
    • default - false
  • NOTE: set viewport true only for net banking.

  • AutoApprove - setAutoApprove(boolean isAutoApprove);

    • true - OTP will be fetched automatically and approved as well.
    • false - OTP will fetch automatically.
    • default - false
  • Surl/Furl Response Timeout - setMerchantResponseTimeout(int merchantResponseTimeout);

    • merchantResponseTimeout - Surl/Furl loading timeout in milliseconds
  • HTMLdata - setHtmlData(String htmlData) (Available on version 7.2.2+)

    • htmlData - HTML string received from PayU webservice using Server to Server call.
  • surepayS2Surl - setSurepayS2Surl(String surepayS2Surl) (Available on version 7.2.2+)

    • surepayS2Surl - Url on which HTML received from PayU webservice using Server to Server call is hosted.
  • AutoSelectOTP - setAutoSelectOTP(boolean isAutoSelect)

    • true - OTP option will be selected automatically
    • false - User will select from either passoword or OTP
    • default - false
  • EnableWebFlow - setEnableWebFlow(Payment paymentType,boolean enableWebFlow)

    • true - WebFlow payment will be enabled for selected Payment Type (UPI)
    • false - WebFlow payment will be disabled for selected Payment Type (UPI)
    • default - true

If using PayU SDK, you may use below mentioned code snippet:

PayUSdkDetails payUSdkDetails = new PayUSdkDetails();
customBrowserConfig.setSdkVersionName(payUSdkDetails.getSdkVersionName());
  • Magic Retry - setmagicRetry(boolean showMagicRetry)

    • true - to enable magic retry
    • false - disable magic retry
    • default - true
  • Merchant SMS permission - For android M only - customBrowserConfig.setMerchantSMSPermission(false);

    • true - shows dialog for permission
    • false - no dialog is shown to the user
    • default - false
  • Changes in PayU Post Data for TEZ(For PayU PG merchants only) -

  • Set below values for TEZ payment in your post data.
    • Bankcode - TEZ
    • PG - UPI
  • Changes in PayU Post Data for PhonePe Intent(For PayU PG merchants only) -
  • Set below values for PhonePe Intent payment in your post data.
    • Bankcode - PPINTENT
    • PG - CASH
10. PayUCustomBrowserCallback

List of the callback function provided by PayU Custom Browser:

  1. onPaymentFailure(String payuResult,String merchantResponse) - Calls when payment fails

  2. onPaymentSuccess(String payuResult,String merchantResponse) - Calls when payment succeeds

  3. onCBErrorReceived(int code,String errormsg) - Called for error on custom browser where,

    • code : Error Code
    • error msg : Error message

Following new error messages are introduced w.r.t. Tez Payment(version 7.0+)

In case enablewebflow is set to false for Tez payment and Tez app is not present on device following error would be thrown

- code        : 1001
- error msg   : DEVICE_NOT_SUPPORTED

In case below error is received while processing payment please check your postData and hash

- code        : 1002 
- errormsg    : MERCHANT_INFO_NOT_PRESENT 

Following are error messages w.r.t. Samsung Pay initialisation failure

- code             : errormsg 

- 1                : VENDOR_NOT_SUPPORTED   // Device Vendor is not supported
- 2                : DEVICE_NOT_SUPPORTED   // Device is not supported 
- 3                : APP_VERSION_MISMATCH   // Samsung Pay version doesn't meet requirements 
- 4                : COUNTRY_NOT_SUPPORTED  // Country of device origin is not supported by Samsung Pay 
- 5                : MERCHANT_KEY_NOT_REGISTER_FOR_SAMSUNG_PAY        // Merchant is not registered for 
                                                                         Samsung Pay with PayU 
- 6                : CONTEXT_NULL           // Context is null
- 7                : PAYMENT_ID_NOT_PRESENT // Check your postdata
  1. setCBProperties(WebView webview, Bank payUCustomBrowser){}; - Callback where webview setting is done
@Override
  public void setCBProperties(WebView webview, Bank payUCustomBrowser) {
    webview.setWebChromeClient(new PayUWebChromeClient(payUCustomBrowser));
    webview.setWebViewClient(new PayUWebViewClient(payUCustomBrowser,merchantKey));
    
    webview.postUrl(url, payuConfig.getData().getBytes());
   //comment above line if you are using CB is 6.1 or above
}	
  1. onBackButton(AlertDialog.Builder alertDialogBuilder){}; - This callback provides alert dialog access, so customization can be done to alert dialog.

  2. onBackApprove(){} - Calls when ‘ok’ is selected from alert dialog.

  3. onBackDismiss(){} - Calls when ‘cancel’ is selected from alert dialog

  4. public void initializeMagicRetry(Bank payUCustomBrowser,WebView webview,MagicRetryFragment magicRetryFragment) - Use this method when using magic retry.

  5. public void onPaymentTerminate() - Called when payment is terminated

  6. public void isPaymentOptionAvailable(CustomBrowserResultData resultData)(Available on version 7.1.3+) [ Merchant must check for Samsung Pay/PhonePe payment option availability on customer device before showing Samsung Pay/PhonePe as payment option]

    • Called when payment option is available
    • Merchant can use value of resultData object like below
             resultData.getPaymentOption() - Gives PaymentOption i.e. SamsungPay/PhonePe.
             resultData.isPaymentOptionAvailable() - Boolean whether Payment via selected PaymentOption is possible.
             resultData.getSamsungPayVpa() - Gives SamsungPay Vpa associated with device.
             resultData.getErrorMessage() - Gives error message in case PaymentOption is not available.
  1. public void onVpaEntered(String vpa, PackageListDialogFragment packageListDialogFragment)(Available on version 7.3.0+) [Merchant must override this function and provide verifyVpaHash in case they want payment via UPI Collect flow]
              packageListDialogFragment.verifyVpa(verifyVpaHash);

Notes:

 To generate verifyVpaHash use below method
                   sha512(key|command|var1|salt) 
 where key     = Provide your merchant key here
       command = "validateVPA"
       var1    = Provide vpa value recieved
       salt    = Provide your merchant salt here

10. Sample Code

// Callback for CB 
 PayUCustomBrowserCallback payUCustomBrowserCallback = new PayUCustomBrowserCallback() {
                @Override
                public void onPaymentFailure(String payuResponse,String merchantResponse) {
                    Intent intent = new Intent();
                    intent.putExtra(getString(R.string.cb_result), merchantResponse);
                    intent.putExtra(getString(R.string.cb_payu_response), payuResponse);
                    setResult(Activity.RESULT_CANCELED, intent);
                    finish();
                }

                @Override
                public void onPaymentTerminate() {
                }

                @Override
                public void onPaymentSuccess(String payuResponse,String merchantResponse) {
                    Intent intent = new Intent();
                    intent.putExtra(getString(R.string.cb_result), merchantResponse);
                    intent.putExtra(getString(R.string.cb_payu_response), payuResponse);
                    setResult(Activity.RESULT_OK, intent);
                    finish();
                }

                @Override
                public void onCBErrorReceived(int code, String errormsg) {
                }



                @Override
                public void setCBProperties(WebView webview, Bank payUCustomBrowser) {
                    webview.setWebChromeClient(new PayUWebChromeClient(payUCustomBrowser));
                    webview.setWebViewClient(new PayUWebViewClient(payUCustomBrowser,merchantKey));
                    webview.postUrl(url, payuConfig.getData().getBytes());
                   //comment above line if you are using CB is 6.1 or above
                }

                @Override
                public void onBackApprove() {
                    PaymentsActivity.this.finish();
                }

                @Override
                public void onBackDismiss() {
                    super.onBackDismiss();
                }

                @Override
                public void onBackButton(AlertDialog.Builder alertDialogBuilder) {
                    super.onBackButton(alertDialogBuilder);
                }

                @Override
                public void initializeMagicRetry(Bank payUCustomBrowser,WebView webview,MagicRetryFragment magicRetryFragment){
                    webview.setWebViewClient(new PayUWebViewClient(payUCustomBrowser, magicRetryFragment,merchantKey));
                    Map<String, String> urlList = new HashMap<String, String>();
                    urlList.put(url, payuConfig.getData());
                    payUCustomBrowser.setMagicRetry(urlList);
                }

                //Below method is available on version 7.1.3+
                @Override
                public void isPaymentOptionAvailable(CustomBrowserResultData resultData) {
                    Toast.makeText(PaymentsActivity.this, "isPaymentOptionAvailable"+resultData.getSamsungPayVpa() 
                     , Toast.LENGTH_SHORT).show();
                }

                //Below method is available on version 7.3.0+
                @Override
                public void onVpaEntered(String vpa, PackageListDialogFragment packageListDialogFragment) {
                    //Calculate validateVpahash using vpa and provide to verifyVpa method of 
                    PackageListDialogFragment like below.
                    packageListDialogFragment.verifyVpa(calculateHash(input));
                }

            };

            // Set configuration for CB
            CustomBrowserConfig customBrowserConfig = new CustomBrowserConfig(merchantKey,txnId);
            customBrowserConfig.setViewPortWideEnable(viewPortWide);
            customBrowserConfig.setAutoApprove(true);
            customBrowserConfig.setAutoSelectOTP(true);
            customBrowserConfig.setDisableBackButtonDialog(false);
             //Set below to true to enable run time permission dialog to appear for all Android 6.0 and above 
               devices
            customBrowserConfig.setMerchantSMSPermission(true); 
            customBrowserConfig.setmagicRetry(true);

            //for CB version is 6.1 or above, use below 2 lines as well
            customBrowserConfig.setPostURL(url);
            customBrowserConfig.setPayuPostData(payuConfig.getData());
            //for CB version is 7.0 or above, use below to enable/disable webflow payment.
            customBrowserConfig.setEnableWebFlow(Payment.TEZ,false);

            new CustomBrowser().addCustomBrowser(PaymentsActivity.this,customBrowserConfig , payUCustomBrowserCallback);

11. SurePay integration

This document contains technical integration information to configure Surepay in Android App

1. SurePay Count

Maximum number of times the SurePay dialog box will prompt the user to retry a transaction in case of network failures

setEnableSurePay​(int surePay)
Input params: surepay count 

To disable SurePay set surePay count value to 0. Example:

customBrowserConfig.setEnableSurePay(0); ​// set surepay count

2. WebViewClient (optional)

If merchant wants to use customized WebviewClient then their WVC should extend PayUSurePayWebViewClient

For custom webView client extend PayUSurePayWebViewClient. Example:

webview.setWebViewClient(new PayUSurePayWebViewClient(payUCustomBrowser, merchantKey)); 

3. PostData setPayuPostData(String) - Payment Post Data [Post data being sent to PayU PG] SurePay Example:

customBrowserConfig.setPayuPostData(payuConfig.getData()); ​// set post data

4. PostURL setPostURL(String) - Payment Post URL [PG url to be precise] Example:

customBrowserConfig.setPostURL(url); ​// set post URL

5. MerchantCheckoutActivity (optional) set Merchant activity(Absolute path of activity) By the time CB detects good network, if CBWebview is destroyed, we resume the transaction by passing payment post data to, this, merchant checkout activity.

customBrowserConfig.setMerchantCheckoutActivityPath("com.payu.payuui.Activity.MerchantCheckoutActivity"); 

6. Notifications can be customised All the notifications which will appear during a SurePay transaction can be customized as per the merchant’s needs. You can customize the icon, the header, sub-header and the message body of all the notifications which appear.

A. Better network Identified : This notification is fired when a better network is identified by SurePay. Use methods below to customize notification when a better network is identified.

customBrowserConfig.setSurePayNotificationGoodNetworkTitle();

   Default value is Internet Restored

customBrowserConfig.setSurePayNotificationGoodNetworkHeader(); 

  Default value is “You can now resume the transaction"

customBrowserConfig.setSurePayNotificationGoodNetworkBody();

B. Threshold value for finding good network is elapsed : This notification is fired when the threshold value until which SurePay looks for a good network is over and the user cannot resume the transaction from that point. Use below mentioned methods to customize notification when threshold value is elapsed.

customBrowserConfig.setSurePayNotificationPoorNetWorkHeader();  

Default value is “No Internet Found”

customBrowserConfig.setSurePayNotificationPoorNetWorkTitle();  

Default value is “We could not detect internet on your device”

customBrowserConfig.setSurePayNotificationPoorNetWorkBody(); 

C. Notification for Success transaction : This notification is fired when bank confirms the status of the transaction when it is dropped in the backward leg. Use below mentioned methods to customize notification for success transaction

customBrowserConfig.setSurePayNotificationTransactionVerifiedTitle();  

Default value is "Transaction Verified" 

customBrowserConfig.setSurePayNotificationTransactionVerifiedHeader();   

Default value is "The bank has verified this transaction and we are good to go.” 

customBrowserConfig.setSurePayNotificationTransactionVerifiedBody(); 

D. Notification for unknown Transaction : This notification is fired when the bank cannot confirm the status of the transaction dropped in the backward leg at that given point of time. Use below mentioned methods to customize notification for unknown transaction

customBrowserConfig.setSurePayNotificationTransactionNotVerifiedTitle();  

Default value is "Transaction Status Unknown"

customBrowserConfig.setSurePayNotificationTransactionNotVerifiedHeader();  

Default value is "The bank could not verify the transaction at this time."

customBrowserConfig.setSurePayNotificationTransactionNotVerifiedBody();

E. Set SurePay notification: Set the notification icon 

customBrowserConfig.setSurePayNotificationIcon(int intRes) 

  input param:​ Drawable Resource (Default value is R.drawable.surepay_logo)

IMPORTANT

1).Even​ after following the steps mentioned above, if sure pay is not working - make sure that webviewclient is not set or is set to PayUSurePayWebViewClient​ and nothing else. If merchant wants to use customized WebviewClient then their WVC should extend PayUSurePayWebViewClient

2). It is important for SurePay to work correctly that you set PG URL and POST data in respective methods. If you are not hitting the PG from app and the traffic is being route through your web server, please provide the corresponding url and post data in the methods mentioned above.

3). MerchantCheckoutActivity​ is an important configuration to set. This will help in recovering transactions even if the user has killed CB.

4). Add below mentioned permission in manifest file

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> 

5). Append ‘surepay count​’ to the post data, being sent to PayU server, if the first url on custom browser is a URL other than PayU PG payment URL (may be first url is merchant’s web server) Code snippet to add surepay count is mention below

&snooze=<surepay_count> 

Where, ‘surepay count​’ is the maximum number of times user can re-try a transaction later.

Settings on Admin Panel Values of flags that should be set on merchant panel for SurePay (Please contact your account manager to get this done.)

  1. disable_duplicate_txnid​ : 0
  2. include_txnid_in_duplicacy​: 0
  3. overseas_merchant​: 0

12. Proguard rules

-keepclassmembers class com.payu.custombrowser.** {
 *;
}
-keepclassmembers class * {
 @android.webkit.JavascriptInterface <methods>;
}
-keepattributes Signature
-keepattributes *Annotation*
-keepattributes JavascriptInterface
-keep public class com.payu.sdk.ProcessPaymentActivity$PayUJavaScriptInterface
-keep public class * implements com.payu.sdk.ProcessPaymentActivity$PayUJavaScriptInterface

13. Review Order Integration

Review Order

Review order is a feature of CB by which merchant can display an ongoing transaction’s information to the user on bank page. This will help the user to verify transaction related critical information while making a payment, and prevents users from pressing back button, cancelling the transaction, just to review or re-check their order details.

For review order integration ,please go here.

Clone this wiki locally