同様の問題がありましたが、IPN に頼ることができなかったので、別の方法を共有すると思いました。
IPN を使用する必要はありません。payKey を使用してトランザクション ID を取得できます。これは、モバイル決済の検証に役立ちます。これは、payKey からすべてのトランザクション情報を取得する php ブロックです。モバイル アプリから呼び出す必要があります。iOS の場合、次のチュートリアルを使用できます: http://www.raywenderlich.com/13511/how-to-create-an-app-like-instagram-with-a-web-service-backend-part-12
<?
header("Content-Type: application/json");
//DEBUG TO CHECK PAYKEY
//turn php errors on
ini_set("track_errors", true);
//Example payKey (got from iOS app)
$payKey = "<snip>";
//set PayPal Endpoint to sandbox
$url = trim("https://svcs.sandbox.paypal.com/AdaptivePayments/PaymentDetails?payKey=".$payKey."&requestEnvelope.errorLanguage=en_US");
//PayPal API Credentials
//to do: change these for production credentials in the production app
$API_UserName = "<snip>";
$API_Password = "<snip>";
$API_Signature = "<snip>";
//Default App ID for Sandbox
$API_AppID = "APP-80W284485P519543T";
$API_RequestFormat = "NV";
$API_ResponseFormat = "NV";
try
{
//Create payload for this query
$bodyparams = array ("requestEnvelope.errorLanguage" => "en_US");
// convert payload array into url encoded query string
$body_data = http_build_query($bodyparams, "", chr(38)); // Generates body data
//create request and add headers
$params = array("http" => array(
"method" => "POST",
"content" => $body_data,
"header" => "X-PAYPAL-SECURITY-USERID: " . $API_UserName . "\r\n" .
"X-PAYPAL-SECURITY-PASSWORD: " . $API_Password . "\r\n" .
"X-PAYPAL-SECURITY-SIGNATURE: " . $API_Signature . "\r\n" .
"X-PAYPAL-APPLICATION-ID: " . $API_AppID . "\r\n" .
"X-PAYPAL-REQUEST-DATA-FORMAT: " . $API_RequestFormat . "\r\n" .
"X-PAYPAL-RESPONSE-DATA-FORMAT: " . $API_ResponseFormat
));
//create stream context
$ctx = stream_context_create($params);
//open the stream and send request
$fp = @fopen($url, "r", false, $ctx);
//get response
$response = stream_get_contents($fp);
//check to see if stream is open
if ($response === false) {
throw new Exception("php error message = " . "$php_errormsg");
}
//close the stream
fclose($fp);
//parse the ap key from the response
$keyArray = explode("&", $response);
foreach ($keyArray as $rVal){
list($qKey, $qVal) = explode ("=", $rVal);
$kArray[$qKey] = $qVal;
}
//print the response to screen for testing purposes
If ( $kArray["responseEnvelope.ack"] == "Success")
{
foreach ($kArray as $key =>$value){
echo $key . ": " .$value . "<br/>";
}
}
else {
echo 'ERROR Code: ' . $kArray["error(0).errorId"] . " <br/>";
echo 'ERROR Message: ' . urldecode($kArray["error(0).message"]) . " <br/>";
}
}
catch(Exception $e)
{
echo "Message: ||" .$e->getMessage()."||";
}
//End check paykey
?>
$kArray で取得できるすべてのフィールドを示す画像を添付したかったのですが、評判がありません。$kArray["paymentInfoList.paymentInfo(0).transactionId"]
注: サンドボックスに使用する API 資格情報は、developer.paypal.com の「サンドボックス アカウント」の下にあります。xxxfacilitator@xxx のプロファイルを展開して入手してください