我发现最好的方法是使用迷你浏览器体验。但在移动设备上实施它时,我遇到了各种不同的问题(这也是它最初的目的)。您会看到许多类似的有关自适应支付以及使用灯箱和迷你浏览器体验的问题。
但是...终于...经过数小时、数天的努力,我已经找到了解决方法!这将解决所有人在使用PayPal自适应支付时遇到的各种问题,包括:
- 默认重定向到PayPal页面不支持移动响应并且在移动设备上看起来很糟糕。
- 灯箱在某些移动设备上“卡住”并且无法关闭。
- 迷你浏览器在完成付款或取消后不会关闭。
- 迷你浏览器不会从paypal apdg.js脚本重定向到callBackFunction。
- 在付款完成(或取消)后未重定向到returnUrl和cancelUrl。
- 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;
if (ua.match(/iPhone|iPod|Android|Blackberry.*WebKit/i)) {
win = window.open(paypalURL,'_blank');
pollingInterval = setInterval(function() {
if (win && win.closed) {
clearInterval(pollingInterval);
returnFromPayPal();
}
} , 1000);
}
else
{
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);
}
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");
}
</script>