title: Paypal integration controller not working in Laravel
body: <p>I create an account at paypal to test in my app.</p>
  
  <pre><code> composer require paypal/rest-api-sdk-php
  </code></pre>
  
  <p>Added the client ID and secret to the .env</p>
  
  <p>This is what I currently have in my view</p>
  
  <pre><code>@if ($message = Session::get('success'))
      &lt;div class="w3-panel w3-green w3-display-container"&gt;
          &lt;span onclick="this.parentElement.style.display='none'"
                  class="w3-button w3-green w3-large w3-display-topright"&gt;&amp;times;&lt;/span&gt;
          &lt;p&gt;{!! $message !!}&lt;/p&gt;
      &lt;/div&gt;
      &lt;?php Session::forget('success');?&gt;
      @endif
  @if ($message = Session::get('error'))
      &lt;div class="w3-panel w3-red w3-display-container"&gt;
          &lt;span onclick="this.parentElement.style.display='none'"
                  class="w3-button w3-red w3-large w3-display-topright"&gt;&amp;times;&lt;/span&gt;
          &lt;p&gt;{!! $message !!}&lt;/p&gt;
      &lt;/div&gt;
      &lt;?php Session::forget('error');?&gt;
      @endif
  &lt;form class="w3-container w3-display-middle w3-card-4 " method="POST" id="payment-form"  action="{!! URL::to('paypal') !!}"&gt;
      {{ csrf_field() }}
      &lt;h2 class="w3-text-blue"&gt;Payment Form&lt;/h2&gt;
      &lt;p&gt;      
      &lt;label class="w3-text-blue"&gt;&lt;b&gt;Enter Amount&lt;/b&gt;&lt;/label&gt;
      &lt;input class="w3-input w3-border" name="amount" type="text"&gt;&lt;/p&gt;      
      &lt;button class="w3-btn w3-blue"&gt;Pay with PayPal&lt;/button&gt;&lt;/p&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>My PaymentController looks like this:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use Illuminate\Support\Facades\Session;
  use Illuminate\Http\Request;
  use PayPal\Api\Amount;
  use PayPal\Api\Item;
  use PayPal\Api\ItemList;
  use PayPal\Api\Payer;
  use PayPal\Api\Transaction;
  use PayPal\Api\Payment;
  use PayPal\Api\Details;
  use PayPal\Api\ChargeModel;
  use PayPal\Api\Currency;
  use PayPal\Api\MerchantPreferences;
  use PayPal\Api\PaymentDefinition;
  use PayPal\Api\Plan;
  use PayPal\Api\Patch;
  use PayPal\Api\PatchRequest;
  use PayPal\Common\PayPalModel;
  use PayPal\Rest\ApiContext;
  use PayPal\Auth\OAuthTokenCredential;
  use PayPal\Api\RedirectUrls;
  use PayPal\Api\PaymentExecution;
  
  use URL;
  use Redirect;
  use Illuminate\Support\Facades\Input;
  
  class PaymentController extends Controller
  {
  
      private $apiContext;
      private $mode;
      private $client_id;
      private $secret;
  
      public function __construct()
          {
      /** PayPal api context **/
              $paypal_conf = \Config::get('paypal');
              $this-&gt;_api_context = new ApiContext(new OAuthTokenCredential(
                  $paypal_conf['client_id'],
                  $paypal_conf['secret'])
              );
              $this-&gt;_api_context-&gt;setConfig($paypal_conf['settings']);
      }
  
      public function payWithpaypal(Request $request){
          $payer = new Payer();
          $payer-&gt;setPaymentMethod('paypal');
          $item_1 = new Item();
          $item_1-&gt;setName('Item 1') /** item name **/
                  -&gt;setCurrency('USD')
                  -&gt;setQuantity(1)
                  -&gt;setPrice($request-&gt;get('amount')); /** unit price **/
          $item_list = new ItemList();
          $item_list-&gt;setItems(array($item_1));
          $amount = new Amount();
          $amount-&gt;setCurrency('USD')
                  -&gt;setTotal($request-&gt;get('amount'));
          $transaction = new Transaction();
          $transaction-&gt;setAmount($amount)
                  -&gt;setItemList($item_list)
                  -&gt;setDescription('Your transaction description');
          $redirect_urls = new RedirectUrls();
          $redirect_urls-&gt;setReturnUrl(URL::route('status')) /** Specify return URL **/
                  -&gt;setCancelUrl(URL::route('status'));
          $payment = new Payment();
          $payment-&gt;setIntent('Sale')
                  -&gt;setPayer($payer)
                  -&gt;setRedirectUrls($redirect_urls)
                  -&gt;setTransactions(array($transaction));
              /** dd($payment-&gt;create($this-&gt;_api_context));exit; **/
  
          try {
              $payment-&gt;create($this-&gt;_api_context);
          } catch (\PayPal\Exception\PPConnectionException $ex) {
              if (\Config::get('app.debug')) {
              \Session::put('error', 'Connection timeout');
                              return Redirect::route('paywithpaypal');
              } else {
              \Session::put('error', 'Some error occur, sorry for inconvenient');
                              return Redirect::route('paywithpaypal');
              }
          }
          foreach ($payment-&gt;getLinks() as $link) {
          if ($link-&gt;getRel() == 'approval_url') {
          $redirect_url = $link-&gt;getHref();
                          break;
          }
          }
          /** add payment ID to session **/
                  Session::put('paypal_payment_id', $payment-&gt;getId());
          if (isset($redirect_url)) {
          /** redirect to paypal **/
                      return Redirect::away($redirect_url);
          }
          \Session::put('error', 'Unknown error occurred');
                  return Redirect::route('paywithpaypal');
      }
  
      public function getPaymentStatus(){
          /** Get the payment ID before session clear **/
          $payment_id = Session::get('paypal_payment_id');
  /** clear the session payment ID **/
          Session::forget('paypal_payment_id');
          if (empty(Input::get('PayerID')) || empty(Input::get('token'))) {
              \Session::put('error', 'Payment failed');
              return Redirect::route('/');
          }
          $payment = Payment::get($payment_id, $this-&gt;_api_context);
          $execution = new PaymentExecution();
          $execution-&gt;setPayerId(Input::get('PayerID'));
          /**Execute the payment **/
          $result = $payment-&gt;execute($execution, $this-&gt;_api_context);
          if ($result-&gt;getState() == 'approved') {
  
              /*************************************************
                  PAYMENT SUCCESSFULL - DO THE REST HERE
              /************************************************/
  
              \Session::put('success', 'Payment success');
              return Redirect::route('/');
          }
          \Session::put('error', 'Payment failed');
                  return Redirect::route('/');
      }
  }
  </code></pre>
  
  <p>So now when I enter an amount and try to pay, I get the following error:</p>
  
  <pre><code> Argument 1 passed to PayPal\Rest\ApiContext::setConfig() must be of the type array, null given, called in C:\xampp\htdocs\owlproperty\app\Http\Controllers\PaymentController.php on line 47
  </code></pre>
  
  <p>I created the paypal file under the config folder and that looks like this:</p>
  
  <pre><code>&lt;?php 
  return [ 
      'client_id' =&gt; env('PAYPAL_CLIENT_ID',''),
      'secret' =&gt; env('PAYPAL_SECRET',''),
      'settings' =&gt; array(
          'mode' =&gt; env('PAYPAL_MODE','sandbox'),
          'http.ConnectionTimeOut' =&gt; 30,
          'log.LogEnabled' =&gt; true,
          'log.FileName' =&gt; storage_path() . '/logs/paypal.log',
          'log.LogLevel' =&gt; 'ERROR'
      ),
  ];
  </code></pre>
  
  <p>Anything I could have possibly done wrong?</p>