我正在集成PayPal的AdaptivePayment API,但每次我打电话时都会收到CURL呼叫返回的错误"内部服务器错误。请查看服务器日志了解详细信息"。我相信我已经具备了所有必需的标题。其他人有这个问题吗?我的代码如下:
$appID = "APP-80W284485P519543T";
$username = "***********";
$password = "***********";
$signature = "**********";
$endpoint = "https://svcs.sandbox.paypal.com/AdaptivePayments/";
$headers = array(
"X-PAYPAL-SECURITY-USERID: " . $username,
"X-PAYPAL-SECURITY-PASSWORD: ". $password,
"X-PAYPAL-SECURITY-SIGNATURE: ". $signature,
"X-PAYPAL-REQUEST-DATA-FORMAT: JSON",
"X-PAYPAL-RESPONSE-DATA-FORMAT: JSON",
"X-PAYPAL-APPLICATION-ID: ". $appID
);
$packet = array(
"actionType" => "PAY",
"currencyCode" => "USD",
"cancelUrl" => "cancel.html",
"returnUrl" => "success.html",
"receiverList" => array(
"receiver" => array(
array(
"amount" => "1.00",
"email" => "example@gmail.com",
"primary" => true
),
array(
"amount" => "0.50",
"email" => "example2@gmail.com",
"primary" => false
)
)
),
"requestEnvelope" => array(
"errorLanguage" => "en_US"
)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint."PAY");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
//turning off the server and peer verification(TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($packet));
$response = curl_exec($ch);
if (curl_errno($ch))
{
// moving to display page to display curl errors
echo curl_errno($ch);
echo curl_error($ch);
//Execute the Error handling module to display errors.
}
else
{
echo "RESPONSE";
header('Content-Type: application/json');
echo $response;
curl_close($ch);
}
您的端点URL错误,应该是:
$endpoint = "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay";