title: PayPal "Authorization Failed"
body: <p>(This is the first time I've worked with the PayPal API so bear with me.)</p>
  
  <p>I'm trying to create encrypted buttons on the fly using the BMCreateButton API, using slightly modified code from <a href="https://www.x.com/developers/community/blogs/ppmacole/encrypting-your-buttons-through-paypal-api-php-using-soap" rel="nofollow">this page</a>. 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.)</p>
  
  <p>This code:</p>
  
  <pre><code>function createButton($name, $price) {
      // Check to make sure that our version of PHP supports SOAP.
      if((PHP_VERSION_ID &lt; 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 =&gt; $location
          ));
  
          // Set our API credentials.
          $credentials-&gt;Credentials-&gt;Username = $username;
          $credentials-&gt;Credentials-&gt;Password = $password;
          $credentials-&gt;Credentials-&gt;Signature = $signature;
          $soapClient-&gt;__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-&gt;BMCreateButtonRequest-&gt;Version = "71.0";
  
          $BMCreateButtonReq-&gt;BMCreateButtonRequest-&gt;ButtonCode = "ENCRYPTED";
  
          // What type of button are we creating?
          $BMCreateButtonReq-&gt;BMCreateButtonRequest-&gt;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-&gt;BMCreateButtonRequest-&gt;ButtonVar[] = "amount=$price";
          $BMCreateButtonReq-&gt;BMCreateButtonRequest-&gt;ButtonVar[] = "item_name=$name";
  
          // Run the API call.
          $response = $soapClient-&gt;BMCreateButton($BMCreateButtonReq);
  
          if($response-&gt;Ack == "Success" || $response-&gt;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 &lt;form&gt; tags -- just
              // display it as-is.
              echo $response-&gt;Website;
          } else {
              error_log("Could not create PayPal button. " . serialize($response-&gt;Errors));
              echo "&lt;p class=\"note\"&gt;Cannot create button&lt;/p&gt;";
  
          }
      }
  }
  </code></pre>
  
  <p>gives this in the error log:</p>
  
  <pre><code>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";}
  </code></pre>
  
  <p>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?</p>