Coder Social home page Coder Social logo

bkash-pgwclient-demo-android's Introduction

Android Configurations

Add the INTERNET permission to your AndroidManifest.xml.

AndroidManifest.xml

<uses¬permission android:name="android.permission.INTERNET"/>

Webview Integration

In order to generate the iframe create a webview,

mWebView = (WebView) findViewById(YOUR.WEBVIEW.LAYOUT);

WebSettings webSettings = mWebView.getSettings();
 webSettings.setJavaScriptEnabled(true);
       mWebView.setClickable(true);
       mWebView.getSettings().setDomStorageEnabled(true);
       mWebView.getSettings().setAppCacheEnabled(false);
       mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
       mWebView.clearCache(true);
       mWebView.getSettings().setAllowFileAccessFromFileURLs(true);
       mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);

For interaction from html file add the code below,

        mWebView.addJavascriptInterface(new JavaScriptInterface(this), "AndroidNative");

        mWebView.loadUrl(YOUR.HTML.FILE);
        private class CheckoutWebViewClient extends WebViewClient {

        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            handler.proceed();
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.equals(ANY.EXTERNAL.URL)) {
                Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(myIntent);
                return true;
            }
            return super.shouldOverrideUrlLoading(view, url);
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            progressBar.setVisibility(view.VISIBLE);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
        //request = { amount: '1000', intent: 'sale' }
        //"intent" parameter has two options 'sale' or 'authorization'
        //'sale' is used for immediate payment and 'authorization' is for deffered payment(capture interface call needed from backend to confirm transaction)
        
            String paymentRequest = "{paymentRequest:" + request + "}";
            mWebView.loadUrl("javascript:callReconfigure(" + paymentRequest + " )");
            mWebView.loadUrl("javascript:clickPayButton()");
            progressBar.setVisibility(view.GONE);

        }

Integrate bKash Checkout In your webview

Add below lines inside HTML head Tag,

    <meta name="viewport" content="width=device-width" ,="" initial-scale="1.0/">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrom=1">

    <script src="PATH/jquery-1.8.3.min.js"></script>
    <script src="http://scripts.sandbox.bka.sh/bKash-checkout-v2.js"></script>

Add the bKash button/image(must have id=bKash_button) inside the body Tag,

<button id="bKash_button" style="display:none;">Pay With bKash</button>

Use bKash Checkout functions

Check the code for reference

Call the bKash.reconfigure(paymentRequest) function for passing the 'paymentRequest' parameter from your WebviewActivity as shown in above Webview Integration section.

i.e. mWebView.loadUrl("javascript:callReconfigure(" + paymentRequest + " )");

              function callReconfigure(val){
                    bKash.reconfigure(val);
                    }

Trigger the "bKash_button" click function,


$("#bKash_button").trigger('click');

bkash-pgwclient-demo-android's People

Contributors

fahadbk avatar tahniat-ashraf-bkash avatar washfi-ahmad avatar wordhulhasan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.