错误PayPal api - 使用PHP Curl检查付款

时间:2014-08-16 03:59:16

标签: php api curl paypal

需要您的PayPal API帮助:

  

错误:HTTP / 1.1 404未找到服务器:Apache-Coyote / 1.1   PROXY_SERVER_INFO:host = slcsbjava3.slc.paypal.com; threadId = 279   Paypal-Debug-Id:939f47a2217c8 SERVER_INFO:   paymentsplatformserv:v1.payments.payment&安培; CalThreadId = 336&安培; TopLevelTxnStartTime = 147dcf033b3&安培;主机= slcsbjm1.slc.paypal.com&安培; PID = 25157   Content-Language:* Date:Sat,16 Aug 2014 03:50:35 GMT Content-Type:   application / json Content-Length:207   {“name”:“INVALID_RESOURCE_ID”,“message”:“请求的资源ID为   不   发现”, “information_link”: “https://developer.paypal.com/webapps/developer/docs/api/#INVALID_RESOURCE_ID”, “debug_id”: “939f47a2217c8”}

代码PHP:

define("URI_SANDBOX", "https://api.sandbox.paypal.com/v1/");

$url = URI_SANDBOX . "payments/payment/PAY-6PU626847B294842SKPEWXHY"; //PAY - correct!!!

$ch = curl_init($url);
$auth_token = "zzzzzzzz"; //correct
$headers = array("Content-Type:application/json", "Authorization:Bearer ".$auth_token);

$options = array(
CURLOPT_HEADER => true,
CURLINFO_HEADER_OUT => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_VERBOSE => true,
CURLOPT_TIMEOUT => 10
);
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
print_r($response);
curl_close($ch);

2 个答案:

答案 0 :(得分:0)

您可以尝试类似......

<?php

$ch = curl_init();
$clientId = "myId";
$secret = "mySecret";

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);

if(empty($result))die("Error: No response.");
else
{
    $json = json_decode($result);
    print_r($json->access_token);
}

curl_close($ch);

?>

您可以阅读更多内容:https://devtools-paypal.com/guide/pay_paypal/curl?env=sandbox

答案 1 :(得分:0)

<?php

$pay = "PAY-8YH60661WV8858705LJ4YKWY";

$ch = curl_init();
$auth_token = "your token id";
$headers = array("Content-Type:application/json", "Authorization:Bearer ".$auth_token);

$options = array(

CURLOPT_URL => "https://api.sandbox.paypal.com/v1/payments/payment/".$pay,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,

);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
$json = json_decode($result);
echo (json_encode($json));
curl_close($ch);

?>