3

(PayPal APIを使用するのはこれが初めてなので、我慢してください。)

このページのわずかに変更されたコードを使用して、BMCreateButtonAPIを使用して暗号化されたボタンをその場で作成しようとしています。残念ながら、PHPエラーログに「認証/承認に失敗しました」というメッセージが表示されるため、これを機能させることができないようです。(PayPal開発者フォーラムでもこれを尋ねましたが、答えはありません。)

このコード:

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

        }
    }
}

これをエラーログに記録します。

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

クレデンシャルを確認しましたが、それらは正しいので、サンドボックスとライブAPIで失敗します。私は基本的な何かを見逃していますか、それとも私が見落としているかもしれないコードにエラーがありますか?

4

1 に答える 1

1

これ覚えてる!

、、およびは関数内で定義されていますか$username?そうでない場合は、関数の先頭に追加する必要があります。$password$signatureglobal $username, $password, $signature

于 2013-02-04T22:28:36.400 に答える