dqz13288 2013-02-04 21:52
浏览 483
已采纳

PayPal“授权失败”

(This is the first time I've worked with the PayPal API so bear with me.)

I'm trying to create encrypted buttons on the fly using the BMCreateButton API, using slightly modified code from this page. Unfortunately I can't seem to get this working, as I get an "authentication/authorization failed" message in the PHP error log. (I've also asked this on the PayPal developer forum but haven't got an answer.)

This code:

function createButton($name, $price) {
    // Check to make sure that our version of PHP supports SOAP.
    if((PHP_VERSION_ID < 50101) || !in_array("soap", get_loaded_extensions())) {
        error_log("PHP not running with SOAP");
    } else {
        include_once("config.php"); //this file holds the credentials and whether it's running in sandbox mode or not
        //basic variable validation
        $price = floatval($price);

        // Import the PayPal WSDL.
        $location = $sandbox ? "https://api-3t.sandbox.paypal.com/2.0/" : "https://api-3t.paypal.com/2.0/";
        $soapClient = new SoapClient("https://www.paypalobjects.com/wsdl/PayPalSvc.wsdl", array(
            location => $location
        ));

        // Set our API credentials.
        $credentials->Credentials->Username = $username;
        $credentials->Credentials->Password = $password;
        $credentials->Credentials->Signature = $signature;
        $soapClient->__setSoapHeaders(new SoapHeader("urn:ebay:api:PayPalAPI", "RequesterCredentials", $credentials));

        // Start creating our BMCreateButtonReq object.  For full details about this object, see
        // http://tinyurl.com/3mxau6j .
        $BMCreateButtonReq->BMCreateButtonRequest->Version = "71.0";

        $BMCreateButtonReq->BMCreateButtonRequest->ButtonCode = "ENCRYPTED";

        // What type of button are we creating?
        $BMCreateButtonReq->BMCreateButtonRequest->ButtonType = "CART";

        // Specific variables for this button.  For the full list of options, see
        // http://tinyurl.com/6qyanl .  For a basic payment, these two should be enough.

        $BMCreateButtonReq->BMCreateButtonRequest->ButtonVar[] = "amount=$price";
        $BMCreateButtonReq->BMCreateButtonRequest->ButtonVar[] = "item_name=$name";

        // Run the API call.
        $response = $soapClient->BMCreateButton($BMCreateButtonReq);

        if($response->Ack == "Success" || $response->Ack == "SuccessWithWarning") {
            // If successful, the button code will be in the Website element of $response.
            // It'll be a full HTML form, so don't wrap it in any <form> tags -- just
            // display it as-is.
            echo $response->Website;
        } else {
            error_log("Could not create PayPal button. " . serialize($response->Errors));
            echo "<p class=\"note\">Cannot create button</p>";

        }
    }
}

gives this in the error log:

Could not create PayPal button. O:8:"stdClass":4:{s:12:"ShortMessage";s:35:"Authentication/Authorization Failed";s:11:"LongMessage";s:49:"You do not have permissions to make this API call";s:9:"ErrorCode";s:5:"10002";s:12:"SeverityCode";s:5:"Error";}

I've checked the credentials and they're correct, and fail with the sandbox as well as the live API. Am I missing something fundamental, or is there an error in the code I may have overlooked?

  • 写回答

1条回答 默认 最新

  • dsedug8644 2013-02-04 22:28
    关注

    I remember this one!

    Are $username, $password, and $signature defined inside the function? If not, you need to add global $username, $password, $signature at the top of the function.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)