Paypal 付款:如何在 webview 中加载 paypal 时获得成功请求 [英] Paypal payment : How to get success request when loading the paypal in webview

查看:20
本文介绍了Paypal 付款:如何在 webview 中加载 paypal 时获得成功请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

paypal登录后,我可以成功完成交易.但我需要匹配paypal中的successUrl以验证两个url是否相同,然后显示成功的toast消息.

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);
                
            }
            
        });        
        
    }
    

    
}

清单:

<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内容:页面在'https://www.sandbox.paypal.com/us/cgi-bin/webscr?SESSION=LTy9Q59%5fia3wiAdHTQjgQxvUF1BTzLjgXgelCew4AS%2dGAutAfB5WjZXVuX8&dispatch=5885d806e68c53c53c53c53c82d8c53c53c5c82d8c53c53c53c52e8c5c53e8c5c5c8c53c52d80e618c8c5c3e8c5c8c53e8c5c8c5c8c52e通过安全连接加载,但包含一个针对不安全的端点'http://www.myapi-entertainment.com/page_managements/page_featured_subscription_payment_success/4.此内容也应通过 HTTPS 提交.的https://WWW.sandbox.paypal.com/us/cgi-bin/webscr?SESSION=LTy9Q59%5fia3wiAdHTQjgQxvUF1BTzLjgXgelCew4AS%2dGAutAfB5WjZXVuX8&dispatch=5885d80a13c06fae6168dc53c0636838dc53c0636838dce235c5372525c53e738dc53e73e28dce7323e73e73e23e78d25c03868dc536e28dc5368dc53e723e723e720888888d2.paypal.com/us/cgi-bin/webscr(0)

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)

这是我的成功回复http://www.myapi-entertainment.com/page_managements/page_featured_subscription_payment_success/4"->更改了服务器名称.

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.

推荐答案

我对您的查询的理解是,您有一个使用 Paypal 执行付款的网站 URL,而在移动应用程序中,您使用 Webview 执行相同的操作(不是 Paypal SDK).

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).

是的,您可以通过在您的 WEB 端进行一些编码来获得 回调.

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

含义:

每当任何用户导航到支付页面时,您的服务器必须知道用户是从网站访问还是通过移动 Webview 访问,服务器可以将 附加参数键发送到任何支付网关以进行自定义逻辑.稍后一旦支付交易完成,支付网关将返回相同的附加参数键以及结果(成功或失败).

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).

注意:每个支付网关都有一个设置成功/失败的重定向网址

一旦Paypal在交易完成后重定向到结果url(成功/失败),服务器就会在附加参数键的帮助下再次检查请求是来自网站还是来自移动Webview;检查下面的案例...

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...

如果来自移动网络视图

  • 成功:重定向到 URL www.myserver.com/success
  • 失败:重定向到 URL www.myserver.com/failure

如果来自Webiew,则正常流程

现在在您手机的 Web 视图中

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;
            }

});

就是这样.

这篇关于Paypal 付款:如何在 webview 中加载 paypal 时获得成功请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆