Paypal移动Web的自适应支付

21

1
有关迷你浏览器体验(expType = mini)的更多信息,请访问此处:Adaptive Payments without modal box or popups? - James
4个回答

6
我发现最好的方法是使用迷你浏览器体验。但在移动设备上实施它时,我遇到了各种不同的问题(这也是它最初的目的)。您会看到许多类似的有关自适应支付以及使用灯箱和迷你浏览器体验的问题。
但是...终于...经过数小时、数天的努力,我已经找到了解决方法!这将解决所有人在使用PayPal自适应支付时遇到的各种问题,包括:
  1. 默认重定向到PayPal页面不支持移动响应并且在移动设备上看起来很糟糕。
  2. 灯箱在某些移动设备上“卡住”并且无法关闭。
  3. 迷你浏览器在完成付款或取消后不会关闭。
  4. 迷你浏览器不会从paypal apdg.js脚本重定向到callBackFunction。
  5. 在付款完成(或取消)后未重定向到returnUrl和cancelUrl。
  6. iOS的Chrome(iPhone)不会启动回调函数,因此在付款完成或取消后,它只会使您停留在您从中启动PayPal付款页面的页面上,这将防止您验证付款的成功或失败。
请为这个节奏鼓喝彩...这就是它!这将取代任何需要PayPal javascript文件等的东西。您只需要下面的代码以及自己获取PayKey并添加到重定向URL的方法即可。我的实时网站,使用以下代码正确工作的自适应支付是:https://www.trackabill.com
<div>
    <?php $payUrl = 'https://www.paypal.com/webapps/adaptivepayment/flow/pay?expType=mini&paykey=' . $payKey ?>

    <button onclick="loadPayPalPage('<?php echo $payUrl; ?>')" title="Pay online with PayPal">PayPal</button>
</div>
<script>
    function loadPayPalPage(paypalURL)
    {
        var ua = navigator.userAgent;
        var pollingInterval = 0;
        var win;
        // mobile device
        if (ua.match(/iPhone|iPod|Android|Blackberry.*WebKit/i)) {
            //VERY IMPORTANT - You must use '_blank' and NOT name the window if you want it to work with chrome ios on iphone
                //See this bug report from google explaining the issue: https://code.google.com/p/chromium/issues/detail?id=136610
            win = window.open(paypalURL,'_blank');

            pollingInterval = setInterval(function() {
                if (win && win.closed) {
                    clearInterval(pollingInterval);
                    returnFromPayPal();
                }
            } , 1000);
        }
        else
        {
            //Desktop device
            var width = 400,
                height = 550,
                left,
                top;

            if (window.outerWidth) {
                left = Math.round((window.outerWidth - width) / 2) + window.screenX;
                top = Math.round((window.outerHeight - height) / 2) + window.screenY;
            } else if (window.screen.width) {
                left = Math.round((window.screen.width - width) / 2);
                top = Math.round((window.screen.height - height) / 2);
            }

            //VERY IMPORTANT - You must use '_blank' and NOT name the window if you want it to work with chrome ios on iphone
                //See this bug report from google explaining the issue: https://code.google.com/p/chromium/issues/detail?id=136610
            win = window.open(paypalURL,'_blank','top=' + top + ', left=' + left + ', width=' + width + ', height=' + height + ', location=0, status=0, toolbar=0, menubar=0, resizable=0, scrollbars=1');

            pollingInterval = setInterval(function() {
                if (win && win.closed) {
                    clearInterval(pollingInterval);
                    returnFromPayPal();
                }
            } , 1000);
        }
    }

    var returnFromPayPal = function()
    {
       location.replace("www.yourdomain.com/paypalStatusCheck.php");
        // Here you would need to pass on the payKey to your server side handle (use session variable) to call the PaymentDetails API to make sure Payment has been successful
        // based on the payment status- redirect to your success or cancel/failed page
    }
</script>

6

支付部分可以正常工作,但不幸的是,在PayPal屏幕的末尾没有“返回”按钮,只有一个“关闭”按钮,它会关闭浏览器选项卡。这就无法将客户带回原始网站,可能存在销售跟踪代码。我还注意到,在移动支付中,支付通知可能需要几个小时。他们确实不支持移动Web上的自适应支付。 - Jordan
你不应该包含一些 JavaScript 代码来使流程正常工作吗?这是官方文档中建议的(尽管 PayPal 文档的可靠性相当低)。 - splinter123
请问有人可以提供生产环境的URI示例吗? - Epigene
有一个未记录的功能,可以让您在完成后将移动流量重定向回您的网站。只需在您的URL中使用expType=redirect而不是expType=mini即可。请参见我在页面下方的答案。 - Jon
我被这个问题搞得快疯了。它对我来说根本不起作用。PayPal的文档简直太糟糕了。 - gef

1

实际上有一个简单的解决方案,但没有任何文档记录。我们曾经与PayPal讨论过添加它,所以我想知道它是否最终得到了实施。

无论如何,只需将用户重定向到以下URL,他们将在完成后重定向回您的网站:

https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/preapproval?preapprovalKey=PA-XXXXX&expType=redirect

这里的区别在于使用expType=redirect而不是expType=mini。我不确定这是什么时候添加的,但经过一些逆向工程和实验,我们有了一个出乎意料简单的解决方案。

0

没错 - 自适应支付界面不是针对移动端优化的。但最接近的选择是我们所谓的MiniBrowser(小型浏览器)体验。您可以尝试并查看是否满足您的需求。您可以在X.com上找到如何指南:实现Mini-Browser选项


3
X.com的上面链接已经失效。 - Homnath Bagale

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接