title: Paypal Rest API on Symfony
body: <p>I'm trying to embed the paypal Rest API on my symfony project, but it returns me an error and even the technical service couldn't tell me where the problem could come from...</p>
  
  <p>The error returned is the following : "Attempted to load class "ApiContext" from namespace "PayPal\Rest". Did you forget a "use" statement for another namespace?"</p>
  
  <p>But I already have the right use statement and the api has already been loaded with composer.</p>
  
  <p>Here is the whole code, if it can help...</p>
  
  <pre><code>&lt;?php
  
  namespace PlatformBundle\Controller;
  
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use PayPal\Api\Payer;
  use PayPal\Api\Item;
  use PayPal\Api\ItemList;
  use PayPal\Api\Details;
  use PayPal\Api\Amount;
  use PayPal\Api\Transaction;
  use PayPal\Api\RedirectUrls;
  use PayPal\Api\Payment;
  use PayPal\Auth\OAuthTokenCredential;
  use PayPal\Rest\ApiContext;
  
  class PaypalController extends Controller
  {
      private function paypalKeys()
      {
          return new ApiContext(
              new OAuthTokenCredential(
                  'mykey',
                  'mykey'
              )
          );
      }
  
      public function chargeAction()
      {
          $this-&gt;paypalKeys();
          $price = 10;
          $total = $price;
  
          $payer = new Payer();
          $payer-&gt;setPaymentMethod('paypal');
  
          $item = new Item();
          $item-&gt;setName('transfer')
              -&gt;setCurrency('eur')
              -&gt;setQuantity(1)
              -&gt;setPrice($price);
  
          $itemList = new ItemList();
          $itemList-&gt;setItems([$item]);
  
          $details = new Details();
          $details-&gt;setShipping(0)
              -&gt;setSubtotal($price);
  
          $amount = new Amount();
          $amount-&gt;setCurrency('eur')
              -&gt;setTotal($total)
              -&gt;setDetails($details);
  
          $transaction = new Transaction();
          $transaction-&gt;setAmount($amount)
              -&gt;setItemList($itemList)
              -&gt;setDescription('Description')
              -&gt;setInvoiceNumber(uniqid());
  
          $redirectUrls = new RedirectUrls();
          $redirectUrls-&gt;setReturnUrl('http://localhost/dublin/web/app_dev.php/admin')
              -&gt;setCancelUrl('http://localhost/dublin/web/app_dev.php/cancel');
  
          $payment = new Payment();
          $payment-&gt;setIntent('sale')
              -&gt;setPayer($payer)
              -&gt;setRedirectUrls($redirectUrls)
              -&gt;setTransactions([$transaction]);
  
  //        try {
          $payment-&gt;create($this-&gt;paypalKeys());
  //        } catch (Exception $e) {
  //            die($e);
  //        }
  //
  //        return new Response('true');
  //        echo $approvalUrl = $payment-&gt;getApprovalLink();
      }
  }
  </code></pre>
  
  <p>thank you...</p>
  
  <p>Annex : </p>
  
  <p>Beginning of my ApiContext file
      
  
  <pre><code>namespace PayPal\Rest;
  
  use PayPal\Core\PayPalConfigManager;
  use PayPal\Core\PayPalCredentialManager;
  
  /**
   * Class ApiContext
   *
   * Call level parameters such as request id, credentials etc
   *
   * @package PayPal\Rest
   */
  class ApiContext
  {
  
      /**
       * Unique request id to be used for this call
       * The user can either generate one as per application
       * needs or let the SDK generate one
       *
  </code></pre>