20
votes

Edit:

After paypal login, I could successfully complete transaction.But I need to match the successUrl in paypal to verify both url is same and then display successful toast message.

But I am not getting success url from payment.So I can't match it.Below I have posted the relevant code:

WebActivity.java:

public class PaypalWebActivity extends Activity {
    
    private WebView webView;
    
    String payUrlStr;
    
    ProgressDialog dialog;

    String successUrl;
    
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.paypal_web_layout);

        successUrl = LOAD_WEBVIEW_PAYMENT_PAYPAL_SUCCESS;

        dialog = ProgressDialog.show(PaypalWebActivity.this, "", "Please wait..", false);

        loadWebViewPaypal();
        
    }

    private void loadWebViewPaypal() {
        
        payUrlStr = LOAD_WEBVIEW_PAYMENT_PAYPAL(PAGE_ID);       
        
        Log.e("payUrlStr", ""+payUrlStr);
        
        webView = (WebView) findViewById(R.id.webView);
        webView.loadUrl(payUrlStr);
        webView.getSettings().setJavaScriptEnabled(true);
        
        @SuppressWarnings("unused")
        WebSettings settings= webView.getSettings();
        if (Build.VERSION.SDK_INT >= 21) {
            webView.getSettings().setMixedContentMode( WebSettings.MIXED_CONTENT_ALWAYS_ALLOW );
           }
        
        webView.setWebViewClient(new WebViewClient() {
            
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                Log.e("Loading url...", url);
                view.loadUrl(url);
                
               String loadWebUrl = view.getUrl();
                
                Log.e("loadWebUrl", ""+loadWebUrl);
                
                return true;
            }
            
            @Override
            public void onPageFinished(WebView view, String url) {
                Log.e("Finished url...", url);
                
                String webUrl = view.getUrl();
                
                Log.e("webUrl", ""+webUrl);
                
                
                if(webUrl.substring(0,95).equals(successUrl)){
                    
                    Log.e("Getting Success Request", "Test");
                    
                }else{
                    
                    Log.e("Failed to get Request", "Test");
                    
                }
                
                if(dialog.isShowing()){
                    dialog.dismiss();
                }
                
            }
            
            @Override
            public void onReceivedError(WebView view, int errorCode,
                    String description, String failingUrl) {
                
                Log.e("Error in url...", description);
                Log.e("Error in failingUrl...", failingUrl);
                
            }
            
        });        
        
    }
    

    
}

Manifest:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

check this discussion.step by step I put screenshots and added content for clear understanding.

I am getting this error message.So cant able to match success request:

06-15 18:12:59.894: I/chromium(3273): [INFO:CONSOLE(0)] "Mixed Content: The page at 'https://www.sandbox.paypal.com/us/cgi-bin/webscr?SESSION=LTy9Q59%5fia3wiAdHTQjgQxvUF1BTzLjgXgelCew4AS%2dGAutAfB5WjZXVuX8&dispatch=5885d80a13c0db1f8e263663d3faee8dcce3e160f5b9538489e17951d2c62172' was loaded over a secure connection, but contains a form which targets an insecure endpoint 'http://www.myapi-entertainment.com/page_managements/page_featured_subscription_payment_success/4. this content should also be submitted over HTTPS. https://www.sandbox.paypal.com/us/cgi-bin/webscr?SESSION=LTy9Q59%5fia3wiAdHTQjgQxvUF1BTzLjgXgelCew4AS%2dGAutAfB5WjZXVuX8&dispatch=5885d80a13c0db1f8e263663d3faee8dcce3e160f5b9538489e17951d2c62172 (0)

This is my success response "http://www.myapi-entertainment.com/page_managements/page_featured_subscription_payment_success/4" -> Changed server name.

is it possible to match success request with paypal? If I get any suggestion, it will be helpful to me.

5
I think u need to ask permission at runtimePreethi Rao
Put up your web page code of payUrlStr please, did you integrate with simple payment button or PayPal Express API in there?pp_pduan
@pp_pduan I need to discuss. can you please come there.Steve
Can you enable https on your server and use an https success response urlrdx

5 Answers

7
votes

Paypal returns json response after successful payment like below

{
  "client": {
    "environment": "sandbox",
    "paypal_sdk_version": "2.14.1",
    "platform": "Android",
    "product_name": "PayPal-Android-SDK"
  },
  "response": {
    "create_time": "2016-06-15T11:38:04Z",
    "id": "PAY-6CN54299U76194116K5QT4BY",
    "intent": "sale",
    "state": "approved"
  },
  "response_type": "payment"
}

You need to check response json object. if state is approved that means paypal payment is successful. Then you can check on Paypal website for current transactions.

Make Sure you have followed below steps: 1) private static final int REQUEST_CODE_PAYMENT = 1; private static String CONFIG_ENVIRONMENT=PayPalConfiguration.ENVIRONMENT_SANDBOX; //It will be PayPalConfiguration.ENVIRONMENT_PRODUCTION for live mode. 2)

// note that these credentials will differ between live & sandbox environments.
private static final String CONFIG_CLIENT_ID = "ATBvU5urlaPOhpCrAhFsoG4u63RvNoKUocFPs9yR5q_sbM0yecZawUjoJhIilW8DNg5RrJcRHgRuEP_1";

private static PayPalConfiguration config = new PayPalConfiguration()
                                    .environment(CONFIG_ENVIRONMENT)
                                    .clientId(CONFIG_CLIENT_ID)
                                            // The following are only used in PayPalFuturePaymentActivity.
                                    .merchantName("Example Merchant")
                                    .merchantPrivacyPolicyUri(Uri.parse("https://www.example.com/privacy"))
                                    .merchantUserAgreementUri(Uri.parse("https://www.example.com/legal"));
                            Intent intent = new Intent(getActivity(), PayPalService.class);
                            intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
                            getActivity().startService(intent);
6
votes

What I understand with your query is, you have an URL of your Website which perform payment using Paypal, and in Mobile app you are performing the same using the Webview(not Paypal SDK).

Yes, you can get the callback by doing some coding at your WEB end.

Meaning:

Whenever any user navigate to Payment page then your Server must know whether User visited from Website or through Mobile Webview, Server can send additional parameter key to any Payment gateway for their custom logic. Later once Payment transaction completed, Payment gateway will return the same additional parameter key alongwith the result(Success or Failure).

Note: Every Payment gateway has a setting of Redirection url for Success/Failure

Once Paypal redirect to result url(Success/Failure) after Transaction gets completed, Server then again check whether the request has been made from Website or from Mobile Webview with the help of additional parameter key; check case below...

If from Mobile Webview

  • Success: Redirected to URL www.myserver.com/success
  • Failure: Redirected to URL www.myserver.com/failure

If from Webiew then Normal flow

Now in your Mobile's Webview

webView.setWebViewClient(new WebViewClient() {

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
                if(url.equalsIgnoreCase("www.myserver.com/success"))
                  //Success Toast
                else if(url.equalsIgnoreCase("www.myserver.com/failure"))
                   //Failure Toast
                return true;
            }

});

That's it.

4
votes

Edit

It seems from the screen shots you're embedding a subscription page into your webview, and trying to match successUrl with the return URL.

  1. Check the answer in this post to set up the retrun URL first in your profile

  2. Obtain the URL String webUrl = webView.getUrl(); if you want to make match/ verification with the defined successUrl

1
votes

As mentioned above,

u need to check response json object. if state is approved that means paypal payment is successful.then you can check on Paypal website for current transactions

1
votes

I am getting a Payment success or failure request using this below Codes:

private void loadWebViewPaypal() {

        payUrlStr = LOAD_WEBVIEW_PAYMENT_PAYPAL(PAGE_ID);       

        Log.e("payUrlStr", "" + payUrlStr);

        webView = (WebView) findViewById(R.id.webView);

        webView.setWebViewClient(new WebClient());
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl(payUrlStr);


        @SuppressWarnings("unused")
        WebSettings settings= webView.getSettings();

        if (Build.VERSION.SDK_INT >= 21) {
            webView.getSettings().setMixedContentMode( WebSettings.MIXED_CONTENT_ALWAYS_ALLOW );
           }


    }

    public class WebClient extends WebViewClient
    {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {

            Log.e("Page Started", ""+url);

            super.onPageStarted(view, url, favicon);



            if(url.contains(successUrl)) {

                Log.e("Getting Success Request", "Test");

                Intent i = new Intent(PaypalWebActivity.this, TabhostActivity.class);

                PAYPAL_WEB_BACK = "fulfilled";
                startActivity(i);
                finish();

            } else if(url.equalsIgnoreCase(failureUrl)) {

                Intent i = new Intent(PaypalWebActivity.this, TabhostActivity.class);

                PAYPAL_WEB_BACK = "fulfilled";
                startActivity(i);
                finish();

            }
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            Log.e("Override Url", ""+url);

            view.loadUrl(url);
            return true;

        }

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

            Log.e("Finished Url :", "" + url);

            if(dialog.isShowing()){
                dialog.dismiss();
            }
        }
    }