Class "PayPal" not found - Laravel 5
I am trying to integrate Paypal in my web application using this package:
http://packalyst.com/packages/package/netshell/paypal
I installed it according to the instructions.
Controller:
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use PayPal;
use Redirect;
use Illuminate\Http\Request;
class PayPalController extends Controller {
private $_apiContext;
public function __construct() {
$this->_apiContext = PayPal::ApiContext(
config('services.paypal.client_id'),
config('services.paypal.secret'));
$this->_apiContext->setConfig(array(
'mode' => 'sandbox',
'service.EndPoint' => 'https://api.sandbox.paypal.com',
'http.ConnectionTimeOut' => 30,
'log.LogEnabled' => true,
'log.FileName' => storage_path('logs/paypal.log'),
'log.LogLevel' => 'FINE'
));
}
public function getCheckout() {
$payer = PayPal::Payer();
$payer->setPaymentMethod('paypal');
$amount = PayPal:: Amount();
$amount->setCurrency('EUR');
$amount->setTotal(42); // This is the simple way,
// you can alternatively describe everything in the order separately;
// Reference the PayPal PHP REST SDK for details.
$transaction = PayPal::Transaction();
$transaction->setAmount($amount);
$transaction->setDescription('What are you selling?');
$redirectUrls = PayPal:: RedirectUrls();
$redirectUrls->setReturnUrl(action('PayPalController@getDone'));
$redirectUrls->setCancelUrl(action('PayPalController@getCancel'));
$payment = PayPal::Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls);
$payment->setTransactions(array($transaction));
$response = $payment->create($this->_apiContext);
$redirectUrl = $response->links[1]->href;
return Redirect::to( $redirectUrl );
}
public function getDone(Request $request) {
$id = $request->get('paymentId');
$token = $request->get('token');
$payer_id = $request->get('PayerID');
$payment = PayPal::getById($id, $this->_apiContext);
$paymentExecution = PayPal::PaymentExecution();
$paymentExecution->setPayerId($payer_id);
$executePayment = $payment->execute($paymentExecution, $this->_apiContext);
// Clear the shopping cart, write to database, send notifications, etc.
// Thank the user for the purchase
return view('checkout.done');
}
public function getCancel() {
// Curse and humiliate the user for cancelling this most sacred payment (yours)
return view('checkout.cancel');
}
}
Then I created a route:
Route::get('/paypal/checkout', [
'as' => 'get-paypal-checkout', 'uses' => 'PayPalController@getCheckout'
]);
But, when I go this route, I get:
FatalErrorException on line PayPalController.php 14: Class "PayPal" not found on line PayPalController.php 14
From what I can see I have implemented my namespace correctly and use
. New to it all.
Any help would be greatly appreciated. Thank!
EDIT:
I changed the top of PayPalController.php to:
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Netshell\PayPal;
use Redirect;
use Illuminate\Http\Request;
But it still doesn't work. Class 'Netshell\PayPal' not found
source to share
See the file PayPal.php
here: https://github.com/net-shell/laravel-paypal/blob/master/src/Netshell/Paypal/Paypal.php (you can also find this in your project after adding it with composer here: vendor/Netshell/Paypal
rather Total)
The first line shows that the namespace is: namespace Netshell\Paypal;
Update yours PayPalController.php
with help use Netshell/Paypal
instead use Paypal
and it should work.
source to share