我已经使用迷你浏览器选项实现了嵌入式自适应支付,这在 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>
最佳答案
当涉及到 PayPal 自适应支付问题和以下问题时,这应该可以解决每个人的各种不同问题:
- 默认重定向的 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>
关于iphone - Paypal 自适应支付移动浏览器(iPhone 上的 Safari 和 Chrome),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29981568/