title: Error in laravel 5.5 Class PaypalPayment does not exist
body: <p>I am trying to make use of the following dependency in laravel 5.5</p>
  
  <p><a href="https://github.com/anouarabdsslm/laravel-paypalpayment" rel="nofollow noreferrer">https://github.com/anouarabdsslm/laravel-paypalpayment</a></p>
  
  <p>Error in laravel 5.5 Class App\Http\Controllers\PaypalPayment does not exist. I have not managed to call the PaypalPayment class. "use Paypalpayment" does not work.</p>
  
  <p><a href="https://i.stack.imgur.com/2i235.png" rel="nofollow noreferrer">Capture del error</a></p>
  
  <p><strong>Error:</strong></p>
  
  <pre><code>C:\xampp\htdocs\laravel-paypal - copia\vendor\laravel\framework\src\Illuminate\Container\Container.php
  }
  
  /**
   * Instantiate a concrete instance of the given type.
   *
   * @param  string  $concrete
   * @return mixed
   *
   * @throws \Illuminate\Contracts\Container\BindingResolutionException
   */
  public function build($concrete)
  {
      // If the concrete type is actually a Closure, we will just execute it and
      // hand back the results of the functions, which allows functions to be
      // used as resolvers for more fine-tuned resolution of these objects.
      if ($concrete instanceof Closure) {
          return $concrete($this, $this-&gt;getLastParameterOverride());
      }
  
      $reflector = new ReflectionClass($concrete);
  
      // If the type is not instantiable, the developer is attempting to resolve
      // an abstract type such as an Interface of Abstract Class and there is
      // no binding registered for the abstractions so we need to bail out.
      if (! $reflector-&gt;isInstantiable()) {
          return $this-&gt;notInstantiable($concrete);
      }
  
      $this-&gt;buildStack[] = $concrete;
  
      $constructor = $reflector-&gt;getConstructor();
  
      // If there are no constructors, that means there are no dependencies then
      // we can just resolve the instances of the objects right away, without
      // resolving any other types or dependencies out of these containers.
      if (is_null($constructor)) {
          array_pop($this-&gt;buildStack);
  
          return new $concrete;
      }
  </code></pre>
  
  <p>Arguments
  "Class App\Http\Controllers\PaypalPayment does not exist"</p>
  
  <p>File Config/App</p>
  
  <pre><code>&lt;?php
  </code></pre>
  
  <p>return [</p>
  
  <pre><code>/*
  |--------------------------------------------------------------------------
  | Application Name
  |--------------------------------------------------------------------------
  |
  | This value is the name of your application. This value is used when the
  | framework needs to place the application's name in a notification or
  | any other location as required by the application or its packages.
  |
  */
  
  'name' =&gt; env('APP_NAME', 'Laravel'),
  
  /*
  |--------------------------------------------------------------------------
  | Application Environment
  |--------------------------------------------------------------------------
  |
  | This value determines the "environment" your application is currently
  | running in. This may determine how you prefer to configure various
  | services your application utilizes. Set this in your ".env" file.
  |
  */
  
  'env' =&gt; env('APP_ENV', 'production'),
  
  /*
  |--------------------------------------------------------------------------
  | Application Debug Mode
  |--------------------------------------------------------------------------
  |
  | When your application is in debug mode, detailed error messages with
  | stack traces will be shown on every error that occurs within your
  | application. If disabled, a simple generic error page is shown.
  |
  */
  
  'debug' =&gt; env('APP_DEBUG', false),
  
  /*
  |--------------------------------------------------------------------------
  | Application URL
  |--------------------------------------------------------------------------
  |
  | This URL is used by the console to properly generate URLs when using
  | the Artisan command line tool. You should set this to the root of
  | your application so that it is used when running Artisan tasks.
  |
  */
  
  'url' =&gt; env('APP_URL', 'http://localhost'),
  
  /*
  |--------------------------------------------------------------------------
  | Application Timezone
  |--------------------------------------------------------------------------
  |
  | Here you may specify the default timezone for your application, which
  | will be used by the PHP date and date-time functions. We have gone
  | ahead and set this to a sensible default for you out of the box.
  |
  */
  
  'timezone' =&gt; 'UTC',
  
  /*
  |--------------------------------------------------------------------------
  | Application Locale Configuration
  |--------------------------------------------------------------------------
  |
  | The application locale determines the default locale that will be used
  | by the translation service provider. You are free to set this value
  | to any of the locales which will be supported by the application.
  |
  */
  
  'locale' =&gt; 'en',
  
  /*
  |--------------------------------------------------------------------------
  | Application Fallback Locale
  |--------------------------------------------------------------------------
  |
  | The fallback locale determines the locale to use when the current one
  | is not available. You may change the value to correspond to any of
  | the language folders that are provided through your application.
  |
  */
  
  'fallback_locale' =&gt; 'en',
  
  /*
  |--------------------------------------------------------------------------
  | Encryption Key
  |--------------------------------------------------------------------------
  |
  | This key is used by the Illuminate encrypter service and should be set
  | to a random, 32 character string, otherwise these encrypted strings
  | will not be safe. Please do this before deploying an application!
  |
  */
  
  'key' =&gt; env('APP_KEY'),
  
  'cipher' =&gt; 'AES-256-CBC',
  
  /*
  |--------------------------------------------------------------------------
  | Logging Configuration
  |--------------------------------------------------------------------------
  |
  | Here you may configure the log settings for your application. Out of
  | the box, Laravel uses the Monolog PHP logging library. This gives
  | you a variety of powerful log handlers / formatters to utilize.
  |
  | Available Settings: "single", "daily", "syslog", "errorlog"
  |
  */
  
  'log' =&gt; env('APP_LOG', 'single'),
  
  'log_level' =&gt; env('APP_LOG_LEVEL', 'debug'),
  
  /*
  |--------------------------------------------------------------------------
  | Autoloaded Service Providers
  |--------------------------------------------------------------------------
  |
  | The service providers listed here will be automatically loaded on the
  | request to your application. Feel free to add your own services to
  | this array to grant expanded functionality to your applications.
  |
  */
  
  'providers' =&gt; [
  
      /*
       * Laravel Framework Service Providers...
       */
      Illuminate\Auth\AuthServiceProvider::class,
      Illuminate\Broadcasting\BroadcastServiceProvider::class,
      Illuminate\Bus\BusServiceProvider::class,
      Illuminate\Cache\CacheServiceProvider::class,
      Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
      Illuminate\Cookie\CookieServiceProvider::class,
      Illuminate\Database\DatabaseServiceProvider::class,
      Illuminate\Encryption\EncryptionServiceProvider::class,
      Illuminate\Filesystem\FilesystemServiceProvider::class,
      Illuminate\Foundation\Providers\FoundationServiceProvider::class,
      Illuminate\Hashing\HashServiceProvider::class,
      Illuminate\Mail\MailServiceProvider::class,
      Illuminate\Notifications\NotificationServiceProvider::class,
      Illuminate\Pagination\PaginationServiceProvider::class,
      Illuminate\Pipeline\PipelineServiceProvider::class,
      Illuminate\Queue\QueueServiceProvider::class,
      Illuminate\Redis\RedisServiceProvider::class,
      Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
      Illuminate\Session\SessionServiceProvider::class,
      Illuminate\Translation\TranslationServiceProvider::class,
      Illuminate\Validation\ValidationServiceProvider::class,
      Illuminate\View\ViewServiceProvider::class,
  
      /*
       * Package Service Providers...
       */
  
      /*
       * Application Service Providers...
       */
      App\Providers\AppServiceProvider::class,
      App\Providers\AuthServiceProvider::class,
      // App\Providers\BroadcastServiceProvider::class,
      App\Providers\EventServiceProvider::class,
      App\Providers\RouteServiceProvider::class,
      Collective\Html\HtmlServiceProvider::class,
      Anouar\Paypalpayment\PaypalpaymentServiceProvider::class,
  
  ],
  
  /*
  |--------------------------------------------------------------------------
  | Class Aliases
  |--------------------------------------------------------------------------
  |
  | This array of class aliases will be registered when this application
  | is started. However, feel free to register as many as you wish as
  | the aliases are "lazy" loaded so they don't hinder performance.
  |
  */
  
  'aliases' =&gt; [
  
      'App'          =&gt; Illuminate\Support\Facades\App::class,
      'Artisan'      =&gt; Illuminate\Support\Facades\Artisan::class,
      'Auth'         =&gt; Illuminate\Support\Facades\Auth::class,
      'Blade'        =&gt; Illuminate\Support\Facades\Blade::class,
      'Broadcast'    =&gt; Illuminate\Support\Facades\Broadcast::class,
      'Bus'          =&gt; Illuminate\Support\Facades\Bus::class,
      'Cache'        =&gt; Illuminate\Support\Facades\Cache::class,
      'Config'       =&gt; Illuminate\Support\Facades\Config::class,
      'Cookie'       =&gt; Illuminate\Support\Facades\Cookie::class,
      'Crypt'        =&gt; Illuminate\Support\Facades\Crypt::class,
      'DB'           =&gt; Illuminate\Support\Facades\DB::class,
      'Eloquent'     =&gt; Illuminate\Database\Eloquent\Model::class,
      'Event'        =&gt; Illuminate\Support\Facades\Event::class,
      'File'         =&gt; Illuminate\Support\Facades\File::class,
      'Gate'         =&gt; Illuminate\Support\Facades\Gate::class,
      'Hash'         =&gt; Illuminate\Support\Facades\Hash::class,
      'Lang'         =&gt; Illuminate\Support\Facades\Lang::class,
      'Log'          =&gt; Illuminate\Support\Facades\Log::class,
      'Mail'         =&gt; Illuminate\Support\Facades\Mail::class,
      'Notification' =&gt; Illuminate\Support\Facades\Notification::class,
      'Password'     =&gt; Illuminate\Support\Facades\Password::class,
      'Queue'        =&gt; Illuminate\Support\Facades\Queue::class,
      'Redirect'     =&gt; Illuminate\Support\Facades\Redirect::class,
      'Redis'        =&gt; Illuminate\Support\Facades\Redis::class,
      'Request'      =&gt; Illuminate\Support\Facades\Request::class,
      'Response'     =&gt; Illuminate\Support\Facades\Response::class,
      'Route'        =&gt; Illuminate\Support\Facades\Route::class,
      'Schema'       =&gt; Illuminate\Support\Facades\Schema::class,
      'Session'      =&gt; Illuminate\Support\Facades\Session::class,
      'Storage'      =&gt; Illuminate\Support\Facades\Storage::class,
      'URL'          =&gt; Illuminate\Support\Facades\URL::class,
      'Validator'    =&gt; Illuminate\Support\Facades\Validator::class,
      'View'         =&gt; Illuminate\Support\Facades\View::class,
      'Form' =&gt; Collective\Html\FormFacade::class,
      'Html' =&gt; Collective\Html\HtmlFacade::class,
  </code></pre>
  
  <p>'Paypalpayment'   => Anouar\Paypalpayment\Facades\PaypalPayment::class,</p>
  
  <pre><code>],
  </code></pre>
  
  <p>];</p>
  
  <p><strong>File Class Paypalpayment in Vendor</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  namespace Anouar\Paypalpayment;
  
  use Illuminate\Support\Facades\URL;
  use PayPal\Api\Address;
  use PayPal\Api\Amount;
  use PayPal\Api\Details;
  use PayPal\Api\Authorization;
  use PayPal\Api\Capture;
  use PayPal\Api\CreditCard;
  use PayPal\Api\CreditCardToken;
  use PayPal\Api\FundingInstrument;
  use PayPal\Api\Item;
  use PayPal\Api\ItemList;
  use PayPal\Api\Links;
  use PayPal\Api\Payee;
  use PayPal\Api\Payer;
  use PayPal\Api\PayerInfo;
  use PayPal\Api\Payment;
  use PayPal\Api\PaymentExecution;
  use PayPal\Api\PaymentHistory;
  use PayPal\Api\RedirectUrls;
  use PayPal\Api\Refund;
  use PayPal\Api\RelatedResources;
  use PayPal\Api\Sale;
  use PayPal\Api\ShippingAddress;
  use PayPal\Api\Transaction;
  use PayPal\Api\Transactions;
  use PayPal\Rest\ApiContext;
  use PayPal\Auth\OAuthTokenCredential;
  
  class PaypalPayment
  {
      protected $config;
  
      public function __construct(array $config)
      {
          $this-&gt;config = $config;
      }
  
      /**
       * @return \PayPal\Api\Address
       */
      public function address()
      {
          return new Address;
      }
  
      /**
       * @return \PayPal\Api\Amount
       */
      public function amount()
      {
          return new Amount;
      }
  
      /**
       * @return \PayPal\Api\Details
       */
      public function details()
      {
          return new Details;
      }
  
      /**
       * @return \PayPal\Api\Authorization
       */
      public function authorization()
      {
          return new Authorization;
      }
  
      /**
       * @return \PayPal\Api\Capture
       */
      public function capture()
      {
          return new Capture;
      }
  
      /**
       * @return \PayPal\Api\CreditCard
       */
      public function creditCard()
      {
          return new CreditCard;
      }
  
      /**
       * @return \PayPal\Api\CreditCardToken
       */
      public function creditCardToken()
      {
          return new CreditCardToken;
      }
  
      /**
       * @return \PayPal\Api\FundingInstrument
       */
      public function fundingInstrument()
      {
          return new FundingInstrument;
      }
  
      /**
       * @return \PayPal\Api\Item
       */
      public function item()
      {
          return new Item;
      }
  
      /**
       * @return \PayPal\Api\ItemList
       */
      public function itemList()
      {
          return new ItemList;
      }
  
      /**
       * @return \PayPal\Api\Links
       */
      public function links()
      {
          return new Links;
      }
  
      /**
       * @return \PayPal\Api\Payee
       */
      public function payee()
      {
          return new Payee;
      }
  
      /**
       * @return \PayPal\Api\Payer
       */
      public function payer()
      {
          return new Payer;
      }
  
      /**
       * @return \PayPal\Api\PayerInfo
       */
      public function payerInfo()
      {
          return new PayerInfo;
      }
  
      /**
       * @return \PayPal\Api\Payment
       */
      public function payment()
      {
          return new Payment;
      }
  
      /**
       * @return \PayPal\Api\PaymentExecution
       */
      public function paymentExecution()
      {
          return new PaymentExecution;
      }
  
      /**
       * @return \PayPal\Api\PaymentHistory
       */
      public function paymentHistory()
      {
          return new PaymentHistory;
      }
  
      /**
       * @return \PayPal\Api\RedirectUrls
       */
      public function redirectUrls()
      {
          return new RedirectUrls;
      }
  
      /**
       * @return \PayPal\Api\Refund
       */
      public function refund()
      {
          return new Refund;
      }
  
      /**
       * @return \PayPal\Api\RelatedResources
       */
      public function relatedResources()
      {
          return new RelatedResources;
      }
  
      /**
       * @return \PayPal\Api\Sale
       */
      public function sale()
      {
          return new Sale;
      }
  
      /**
       * @return \PayPal\Api\ShippingAddress
       */
      public function shippingAddress()
      {
          return new ShippingAddress;
      }
  
      /**
       * @return \PayPal\Api\Transactions
       */
      public function transactions()
      {
          return new Transactions;
      }
  
      /**
       * @return \PayPal\Api\Transaction
       */
      public function transaction()
      {
          return new Transaction;
      }
  
  
      /**
       * @param null $clientId
       * @param null $clientSecret
       * @param null $requestId
       * @return \PayPal\Rest\ApiContext
       */
      public function apiContext($clientId = null, $clientSecret = null, $requestId = null)
      {
          if (!is_null($clientId)) {
              $this-&gt;config['account']['client_id'] = $clientId;
          }
  
          if (!is_null($clientSecret)) {
              $this-&gt;config['account']['client_secret'] = $clientSecret;
          }
  
          $apiContext = new ApiContext($this-&gt;oAuthTokenCredential(), $requestId);
  
          $apiContext-&gt;setConfig([
              'mode' =&gt; $this-&gt;config['mode'],
              'http.ConnectionTimeOut' =&gt; $this-&gt;config['http']['connection_time_out'],
              'log.LogEnabled' =&gt; $this-&gt;config['log']['log_enabled'],
              'log.FileName' =&gt; $this-&gt;config['log']['file_name'],
              'log.LogLevel' =&gt; $this-&gt;config['log']['log_level']
          ]);
  
          return $apiContext;
      }
  
      /**
       * @param null $clientId
       * @param null $clientSecret
       * @return PayPal/Auth/OAuthTokenCredential
       */
      public function oAuthTokenCredential()
      {
          return new OAuthTokenCredential($this-&gt;config['account']['client_id'], $this-&gt;config['account']['client_secret']);
      }
  
      /**
       * Get the base URL
       * @return mixed
       */
      public function getBaseUrl()
      {
          return URL::to('/');
      }
  
  
      public static function getById($paymentId, $apiContext = null)
      {
          if (isset($apiContext)) {
              return Payment::get($paymentId, $apiContext);
          }
          return Payment::get($paymentId);
      }
  
      /**
       * grape all payment details
       * @param $param
       * @param null $apiContext
       * @return \PayPal\Api\Payment
       */
      public static function getAll($param, $apiContext = null)
      {
          if (isset($apiContext)) {
              return Payment::all($param, $apiContext);
          }
          return Payment::all($param);
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>Config/App</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  
  
      'providers' =&gt; [
  
          /*
           * Laravel Framework Service Providers...
           */
          Illuminate\Auth\AuthServiceProvider::class,
          Illuminate\Broadcasting\BroadcastServiceProvider::class,
          Illuminate\Bus\BusServiceProvider::class,
          Illuminate\Cache\CacheServiceProvider::class,
          Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
          Illuminate\Cookie\CookieServiceProvider::class,
          Illuminate\Database\DatabaseServiceProvider::class,
          Illuminate\Encryption\EncryptionServiceProvider::class,
          Illuminate\Filesystem\FilesystemServiceProvider::class,
          Illuminate\Foundation\Providers\FoundationServiceProvider::class,
          Illuminate\Hashing\HashServiceProvider::class,
          Illuminate\Mail\MailServiceProvider::class,
          Illuminate\Notifications\NotificationServiceProvider::class,
          Illuminate\Pagination\PaginationServiceProvider::class,
          Illuminate\Pipeline\PipelineServiceProvider::class,
          Illuminate\Queue\QueueServiceProvider::class,
          Illuminate\Redis\RedisServiceProvider::class,
          Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
          Illuminate\Session\SessionServiceProvider::class,
          Illuminate\Translation\TranslationServiceProvider::class,
          Illuminate\Validation\ValidationServiceProvider::class,
          Illuminate\View\ViewServiceProvider::class,
  
          /*
           * Package Service Providers...
           */
  
          /*
           * Application Service Providers...
           */
          App\Providers\AppServiceProvider::class,
          App\Providers\AuthServiceProvider::class,
          // App\Providers\BroadcastServiceProvider::class,
          App\Providers\EventServiceProvider::class,
          App\Providers\RouteServiceProvider::class,
          Collective\Html\HtmlServiceProvider::class,
          Anouar\Paypalpayment\PaypalpaymentServiceProvider::class,
  
      ],
  
      /*
      |--------------------------------------------------------------------------
      | Class Aliases
      |--------------------------------------------------------------------------
      |
      | This array of class aliases will be registered when this application
      | is started. However, feel free to register as many as you wish as
      | the aliases are "lazy" loaded so they don't hinder performance.
      |
      */
  
      'aliases' =&gt; [
  
          'App'          =&gt; Illuminate\Support\Facades\App::class,
          'Artisan'      =&gt; Illuminate\Support\Facades\Artisan::class,
          'Auth'         =&gt; Illuminate\Support\Facades\Auth::class,
          'Blade'        =&gt; Illuminate\Support\Facades\Blade::class,
          'Broadcast'    =&gt; Illuminate\Support\Facades\Broadcast::class,
          'Bus'          =&gt; Illuminate\Support\Facades\Bus::class,
          'Cache'        =&gt; Illuminate\Support\Facades\Cache::class,
          'Config'       =&gt; Illuminate\Support\Facades\Config::class,
          'Cookie'       =&gt; Illuminate\Support\Facades\Cookie::class,
          'Crypt'        =&gt; Illuminate\Support\Facades\Crypt::class,
          'DB'           =&gt; Illuminate\Support\Facades\DB::class,
          'Eloquent'     =&gt; Illuminate\Database\Eloquent\Model::class,
          'Event'        =&gt; Illuminate\Support\Facades\Event::class,
          'File'         =&gt; Illuminate\Support\Facades\File::class,
          'Gate'         =&gt; Illuminate\Support\Facades\Gate::class,
          'Hash'         =&gt; Illuminate\Support\Facades\Hash::class,
          'Lang'         =&gt; Illuminate\Support\Facades\Lang::class,
          'Log'          =&gt; Illuminate\Support\Facades\Log::class,
          'Mail'         =&gt; Illuminate\Support\Facades\Mail::class,
          'Notification' =&gt; Illuminate\Support\Facades\Notification::class,
          'Password'     =&gt; Illuminate\Support\Facades\Password::class,
          'Queue'        =&gt; Illuminate\Support\Facades\Queue::class,
          'Redirect'     =&gt; Illuminate\Support\Facades\Redirect::class,
          'Redis'        =&gt; Illuminate\Support\Facades\Redis::class,
          'Request'      =&gt; Illuminate\Support\Facades\Request::class,
          'Response'     =&gt; Illuminate\Support\Facades\Response::class,
          'Route'        =&gt; Illuminate\Support\Facades\Route::class,
          'Schema'       =&gt; Illuminate\Support\Facades\Schema::class,
          'Session'      =&gt; Illuminate\Support\Facades\Session::class,
          'Storage'      =&gt; Illuminate\Support\Facades\Storage::class,
          'URL'          =&gt; Illuminate\Support\Facades\URL::class,
          'Validator'    =&gt; Illuminate\Support\Facades\Validator::class,
          'View'         =&gt; Illuminate\Support\Facades\View::class,
          'Form' =&gt; Collective\Html\FormFacade::class,
          'Html' =&gt; Collective\Html\HtmlFacade::class,
  'Paypalpayment'   =&gt; Anouar\Paypalpayment\Facades\PaypalPayment::class,
  
      ],
  
  ];</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>Controller edited</strong></p>
  
  <pre><code>class PaypalPaymentController extends Controller
  </code></pre>
  
  <p>{
      /*
      * Process payment using credit card
      */
      public function paywithCreditCard()
      {</p>
  
  <pre><code>    // ### Address
      // Base Address object used as shipping or billing
      // address in a payment. [Optional]
      $shippingAddress = PaypalPayment::shippingAddress();
      $shippingAddress-&gt;setLine1("3909 Witmer Road")
          -&gt;setLine2("Niagara Falls")
          -&gt;setCity("Niagara Falls")
          -&gt;setState("NY")
          -&gt;setPostalCode("14305")
          -&gt;setCountryCode("US")
          -&gt;setPhone("716-298-1822")
          -&gt;setRecipientName("Jhone");
  
      // ### CreditCard
      $card = PaypalPayment::creditCard();
      $card-&gt;setType("visa")
          -&gt;setNumber("4758411877817150")
          -&gt;setExpireMonth("05")
          -&gt;setExpireYear("2019")
          -&gt;setCvv2("456")
          -&gt;setFirstName("Joe")
          -&gt;setLastName("Shopper");
  
      // ### FundingInstrument
      // A resource representing a Payer's funding instrument.
      // Use a Payer ID (A unique identifier of the payer generated
      // and provided by the facilitator. This is required when
      // creating or using a tokenized funding instrument)
      // and the `CreditCardDetails`
      $fi = PaypalPayment::fundingInstrument();
      $fi-&gt;setCreditCard($card);
  
      // ### Payer
      // A resource representing a Payer that funds a payment
      // Use the List of `FundingInstrument` and the Payment Method
      // as 'credit_card'
      $payer = PaypalPayment::payer();
      $payer-&gt;setPaymentMethod("credit_card")
          -&gt;setFundingInstruments([$fi]);
  
      $item1 = PaypalPayment::item();
      $item1-&gt;setName('Ground Coffee 40 oz')
              -&gt;setDescription('Ground Coffee 40 oz')
              -&gt;setCurrency('USD')
              -&gt;setQuantity(1)
              -&gt;setTax(0.3)
              -&gt;setPrice(7.50);
  
      $item2 = PaypalPayment::item();
      $item2-&gt;setName('Granola bars')
              -&gt;setDescription('Granola Bars with Peanuts')
              -&gt;setCurrency('USD')
              -&gt;setQuantity(5)
              -&gt;setTax(0.2)
              -&gt;setPrice(2);
  
  
      $itemList = PaypalPayment::itemList();
      $itemList-&gt;setItems([$item1,$item2])
          -&gt;setShippingAddress($shippingAddress);
  
  
      $details = PaypalPayment::details();
      $details-&gt;setShipping("1.2")
              -&gt;setTax("1.3")
              //total of items prices
              -&gt;setSubtotal("17.5");
  
      //Payment Amount
      $amount = PaypalPayment::amount();
      $amount-&gt;setCurrency("USD")
              // the total is $17.8 = (16 + 0.6) * 1 ( of quantity) + 1.2 ( of Shipping).
              -&gt;setTotal("20")
              -&gt;setDetails($details);
  
      // ### Transaction
      // A transaction defines the contract of a
      // payment - what is the payment for and who
      // is fulfilling it. Transaction is created with
      // a `Payee` and `Amount` types
  
      $transaction = PaypalPayment::transaction();
      $transaction-&gt;setAmount($amount)
          -&gt;setItemList($itemList)
          -&gt;setDescription("Payment description")
          -&gt;setInvoiceNumber(uniqid());
  
      // ### Payment
      // A Payment Resource; create one using
      // the above types and intent as 'sale'
  
      $payment = PaypalPayment::payment();
  
      $payment-&gt;setIntent("sale")
          -&gt;setPayer($payer)
          -&gt;setTransactions([$transaction]);
  
      try {
          // ### Create Payment
          // Create a payment by posting to the APIService
          // using a valid ApiContext
          // The return object contains the status;
          $payment-&gt;create(PaypalPayment::apiContext());
      } catch (\PPConnectionException $ex) {
          return response()-&gt;json(["error" =&gt; $ex-&gt;getMessage()], 400);
      }
  
      return response()-&gt;json([$payment-&gt;toArray()], 200);
  }
  </code></pre>
  
  <p>}</p>