0

我已经使用迷你浏览器选项实现了嵌入式自适应支付,该选项在 Android 手机上运行良好,但在 iPhone 浏览器(Safari 和 Chrome)上存在问题

在 Safari 上:-用户必须手动关闭 PayPal 弹出窗口,而它应该已经自动关闭。(手动关闭弹出窗口后,它会触发我用来更新订单的 JavaScript 回调函数)

在 Chrome 上:-当用户点击支付按钮打开 Paypal 授权迷你浏览器,但在支付成功或取消支付后,它不会自动关闭弹出窗口,甚至不会触发手动关闭回调。

我正在使用以下代码

<form action="https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay" target="PPDGFrame">
<input id="type" type="hidden" name="expType" value="mini">
<input id="paykey" type="hidden" name="paykey" value="AP-XXXXXXXXXXX"> 
<input type="submit" id="PPsubmitBtn" value="Pay">
</form>
<script src="https://www.paypalobjects.com/js/external/apdg.js"></script>
<script>
var dgFlowMini = new PAYPAL.apps.DGFlowMini({trigger: 'PPsubmitBtn', callbackFunction: 'updateOrder'});

function updateOrder() {
     //My order stuff update code goes here
}
</script>
4

1 回答 1

1

当涉及到 PayPal 自适应支付的问题和以下问题时,这应该可以解决每个人的所有不同类型的问题:

  1. 默认重定向的贝宝页面不是移动响应的,在移动设备上看起来很糟糕。
  2. 灯箱“挂起”并且在某些移动设备上无法关闭。
  3. 完成付款或取消后,迷你浏览器不会关闭。
  4. 迷你浏览器不会从 paypal apdg.js 脚本重定向到 callBackFunction。
  5. 付款完成后(或取消时)不重定向到 returnUrl 和 cancelUrl
  6. Chrome for ios (iphones) 不会启动回调函数,因此在付款完成或取消后,它只会让您停留在您启动 paypal 付款页面的页面,从而阻止您验证付款成功或失败(这是 Vinod 的问题上面的问题谈到)。

这取代了对 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>
于 2015-05-13T20:18:39.460 回答