php - 什么会导致 PayPal Adaptive Payments API 返回 "internal server error. please check the server logs for details"?

标签 php curl paypal paypal-adaptive-payments

我正在努力集成 PayPal 的 AdaptivePayment API,但每次调用时,我都会收到从 CURL 调用返回的错误“内部服务器错误。请检查服务器日志以获取详细信息”。我相信我拥有所有必需的 header 。其他人遇到过这个问题吗?我的代码如下:

            $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";

关于php - 什么会导致 PayPal Adaptive Payments API 返回 "internal server error. please check the server logs for details"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34399492/

相关文章:

javascript - 如何在 javascript 中使用 php

paypal - paypal定期付款试用期可以有0金额吗?

python - 如何使用 python curl 文件

php - 如何避免 curl_exec() 中的 echo ?

python - Paypal与谷歌应用引擎-python集成

c# - 使用 MVC3 的 Paypal API 请求

javascript - 如果月份与特定月份匹配,则在选择某个月份时尝试显示多行数据

php - Wordpress 自定义帖子类型使用首页

javascript - 你如何防止输入类型=提交关闭模式?

python - 无法使用 python requests 发布文件 - 来自curl的翻译