私が見つけた最良のアプローチは、ミニ ブラウザー エクスペリエンスでした。しかし、それを実装するモバイル デバイスにはさまざまな問題がありました (これがそもそもの目的でした)。アダプティブ ペイメントや、ライトボックスやミニ ブラウザー エクスペリエンスの使用に関するあらゆる種類の問題について、同様の質問が多数寄せられます。
しかし、ついに...何時間も何日も何日も経って、私はそれを理解しました! これにより、PayPal アダプティブ ペイメントの問題や次の問題に関して、あらゆる種類の問題が解決されるはずです。
- リダイレクトされたデフォルトのペイパル ページはモバイル対応ではなく、モバイル デバイスでは見栄えが悪くなります。
- ライトボックスが「ハングアップ」し、一部のモバイル デバイスで閉じません。
- 決済完了後やキャンセル後、ミニブラウザが閉じない。
- ミニ ブラウザは、paypal apdg.js スクリプトから callBackFunction にリダイレクトしません。
- 決済完了後(またはキャンセル時)に returnUrl と cancelUrl にリダイレクトしない
- Chrome for ios (iphones) はコールバック関数を開始しないため、支払いの完了またはキャンセルの後、PayPal 支払いページを起動したページにとどまり、支払いの成功または失敗を検証できなくなります。
ドラムロールください....ここにあります!! これにより、PayPal JavaScript ファイルなどの必要性が置き換えられます。必要なのは、リダイレクト URL に追加する PayKey を取得する独自の方法とともに、以下に示すものだけです。以下のコードを使用してアダプティブペイメントが正しく機能している私のライブ Web サイトはhttps://www.trackaill.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>