当涉及到 PayPal 自适应支付的问题和以下问题时,这应该可以解决每个人的所有不同类型的问题:
- 默认重定向的贝宝页面不是移动响应的,在移动设备上看起来很糟糕。
- 灯箱“挂起”并且在某些移动设备上无法关闭。
- 完成付款或取消后,迷你浏览器不会关闭。
- 迷你浏览器不会从 paypal apdg.js 脚本重定向到 callBackFunction。
- 付款完成后(或取消时)不重定向到 returnUrl 和 cancelUrl
- 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>