Reputation: 9714
Can anyone tell me why I'm getting the following error:
exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'PayPal\Rest\ApiContext' not found'
Here is my Controller code:
<?php
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\ExecutePayment;
use PayPal\Api\PaymentExecution;
use PayPal\Api\Transaction;
class PaypalPaymentController extends BaseController {
private $_api_context;
public function __construct() {
// setup PayPal api context
$paypal_conf = Config::get('paypal');
$this->_api_context = new ApiContext(new OAuthTokenCredential($paypal_conf['client_id'], $paypal_conf['secret']));
$this->_api_context->setConfig($paypal_conf['settings']);
}
I'm not sure what the Service Provider needs to be, either... could someone fill in that blank at least?
Upvotes: 0
Views: 871
Reputation: 2014
I just installed the package from composer on a L5 installation and it worked, so here's what I think will help you:
If you're not using composer, remove everything related to paypal and use it, it helps.. a lot.
Remove the paypal package from composer.json
, composer update
, composer dumpautoload
, php artisan cache:clear
.
Add the package again, I did it with "paypal/rest-api-sdk-php": "1.3.*"
. composer update
.
Test it using php artisan tinker
, like this: new PayPal\Rest\ApiContext()
, should return some blue lines describing the object.
I SERIOUSLY believe this is a composer problem, I had the same problem with another payment package, but nothing was namespaced, they used classmap
loading, paypal uses psr-0. This was the question: Not namespaced, classmap loaded package required from composer makes php throw Class not found
Upvotes: 2
Reputation: 1489
If you are using composer to download the PayPal-PHP-SDK, you would need to add the include
statement to add all the classes, as shown below:
// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader
require '<location to vendor directory>/vendor/autoload.php';
If you used direct download, you need to add include, with this path:
// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader
require '<location to PayPal-PHP-SDK directory>/PayPal-PHP-SDK/autoload.php';
Upvotes: 0