Finally found the way to get transaction details from pay-key
First get access token using you clientId and ClientSecret
$ch = curl_init();
$clientId = PAYPAL_CLIENT_ID; //client Id
$secret = PAYPAL_CLIENT_SECRET; client secrete key
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $clientId . ":" . $secret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
$result = curl_exec($ch);
$accessToken = null;
if (empty($result))
die('invalid access token');
else {
$json = json_decode($result);
$accessToken = $json->access_token;
}
curl_close($ch);
After Getting access token, I get transaction detail using following code
$curl = curl_init("https://api.sandbox.paypal.com/v1/payments/payment/<paykey>");
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $accessToken,
'Accept: application/json',
'Content-Type: application/json'
));
$response = curl_exec($curl);
$result = json_decode($response);
With this we can validate transaction.
remove sandbox work from url when you are using it for live.