終於找到了從付費鍵獲取交易詳細信息的方式
首先使用您的clientId和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);
獲得訪問令牌後獲得訪問令牌,我使用下面的代碼
獲得交易明細
$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);
有了這個,我們可以驗證交易。
當您將它用於實時時,從網址中刪除沙盒工作。
您是否檢查了[PaymentDetails](https://developer.paypal.com/webapps/developer/docs/classic/api/adaptive-payments/PaymentDetails_API_Operation/)API? – 2014-10-02 11:39:25
謝謝@AndrewAngell我實現了這一點,它的工作很好。 – 2014-10-02 14:08:04