简体   繁体   中英

How to allow Stripe Checkout to proceed in Android WebView?

When I attempt to open the Stripe Checkout inside my webview, I receive an error saying "there was a problem loading Checkout. If this persists, please try a different browser". When I run through the checkout process on Chrome Mobile outside of the Webview, the stripe checkout works flawlessly. It redirects to a webpage for the stripe checkout. Do I need to enable something in the application to allow for this to work in the WebView?

Code:

public class login extends Activity {

private WebView mWebView;
ProgressBar progressBar;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    mWebView = (WebView) findViewById(R.id.activity_login_webview);

    progressBar = (ProgressBar) findViewById(R.id.progressBar1);
    progressBar.setVisibility(View.VISIBLE);

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    mWebView.loadUrl("http://www.icadeliveries.com/login");
    mWebView.setWebViewClient(new HelloWebViewClient());


}

private class HelloWebViewClient extends WebViewClient {


    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        // TODO Auto-generated method stub
        super.onPageStarted(view, url, favicon);
    }

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

    @Override
    public void onPageFinished(WebView view, String url) {
        // TODO Auto-generated method stub
        super.onPageFinished(view, url);

        TextView load = (TextView) findViewById(R.id.LoadingText);
        load.setVisibility(view.GONE);

        progressBar.setVisibility(view.GONE);
    }

}


@Override
public boolean onKeyDown(int keyCode, KeyEvent event) { //if back key is pressed
    if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
        mWebView.goBack();
        return true;

    }

    return super.onKeyDown(keyCode, event);

}

Unfortunately, Stripe doesn't support displaying Checkout in Webviews at the moment which is why you're getting this error. The best solution is to build your own payment form using Stripe.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM