/**
  * @return $this
  */
 public function index()
 {
     if (Auth::check()) {
         $logs = PayPalLog::orderBy('created_at', 'DESC')->where('state', "!=", "unfinished!")->get();
         $this_month = Carbon::now();
         $this_month->day = 1;
         // first of the month
         // THIS DOES NOT WORK vvv
         $this_month_logs = PayPalLog::where('created_at', '>=', $this_month->toDateString());
         $month_total = 0;
         foreach ($this_month_logs as $log) {
             $month_total += $log->total;
         }
         return View('admin.logs')->with('title', 'Purchase logs')->with('logs', $logs)->with('month_total', $month_total)->with('month_logs', $this_month_logs);
     } else {
         return Redirect::route('oils.index')->with('message', "Sorry you don't have rights to create a Category, please login");
     }
 }
 /**
  *
  */
 public function ExecutePayment()
 {
     if (isset($_GET['success']) && $_GET['success'] == 'true') {
         // Get the payment Object by passing paymentId
         // payment id was previously stored in session in
         // CreatePaymentUsingPayPal.php
         $log = PayPalLog::find(Session::get('log_id'));
         $paymentId = $log->payment_id;
         //$payment = Paypalpayment::get($paymentId, $this->_apiContext);
         $payment = Payment::get($paymentId, $this->_apiContext);
         // PaymentExecution object includes information necessary
         // to execute a PayPal account payment.
         // The payer_id is added to the request query parameters
         // when the user is redirected from paypal back to your site
         $execution = Paypalpayment::PaymentExecution();
         $execution->setPayerId($_GET['PayerID']);
         //Execute the payment
         try {
             $order = $payment->execute($execution, $this->_apiContext)->toArray();
         } catch (\PPConnectionException $ex) {
             return "Exception: " . $ex->getMessage() . PHP_EOL;
             var_dump($ex->getData());
             exit(1);
         }
         $payer = $order['payer']['payer_info'];
         $log->state = $order['state'];
         $log->viewed = false;
         $log->paypal_id = $order['id'];
         $log->payer_email = $payer['email'];
         $log->payer_id = $payer['payer_id'];
         $log->payer_first_name = $payer['first_name'];
         $log->payer_last_name = $payer['last_name'];
         $log->shipping_address = json_encode($payer['shipping_address']);
         //note: you'll have to do foreach if you want multiple -v
         $log->item_list = json_encode($order['transactions'][0]);
         $log->total = $order['transactions'][0]['amount']['total'];
         $log->save();
         $cart = Cart::content();
         Cart::destroy();
         Flash::success('Payment Sucsess!');
         return view('cart.paypalReturn')->with('title', 'Payment Sucsess!')->with('address', $payer['shipping_address'])->with('cart', $cart)->with('log', $log);
     } else {
         echo "User cancelled payment.";
     }
     // Flash::success('Payment Sucsess!');
     // return redirect()->action('BooksController@show', [Session::get('bookId')]);
 }