3

"Your session has been expired. Please re-initiate your transaction. Don't worry... It happens to the best of us." Error message is getting displayed when I try to pay using paytm wallet from the CC Avenue payment gateway using android webview.

Below is my code I used for payment gateway:

@Override
protected void onCreate(Bundle savedInstanceState) {
    progressBarPB = (ProgressBar) findViewById(R.id.progressBarPB);
    progressBarPB.setVisibility(View.VISIBLE);
    WebView webView = (WebView) findViewById(R.id.paymentGatewayWV);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    webView.setWebViewClient(new HelloWebViewClient());
    webView.clearCache(true);
    webView.clearHistory();
    clearCookies(this);
    webView.loadUrl("payment gateway url");
}


@SuppressWarnings("deprecation")
public static void clearCookies(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        CookieManager.getInstance().removeAllCookies(null);
        CookieManager.getInstance().flush();
    } else {
        CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context);
        cookieSyncMngr.startSync();
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncMngr.stopSync();
        cookieSyncMngr.sync();
    }
}

public class HelloWebViewClient extends WebViewClient {
    public HelloWebViewClient() {
        // do nothing
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        progressBarPB.setVisibility(View.GONE);
    }
}

Some times the payment is successfully done, if I try to make the payment again the above error is displayed. I am clearing all the cookie data from the browser even why this error is displayed I didn't understand. Please help me with a good solution. Thanks :).

Krrish
  • 271
  • 3
  • 17

0 Answers0